Commit 5ad721d5 authored by Kunshan Wang's avatar Kunshan Wang

Merge branch 'master' into issue52-threadlocal

parents 3f08206b edf705a1
...@@ -15,50 +15,17 @@ import uvm.refimpl.MicroVM$; ...@@ -15,50 +15,17 @@ import uvm.refimpl.MicroVM$;
/** Static functions for the convenient of C programs that start Mu via JNI. */ /** Static functions for the convenient of C programs that start Mu via JNI. */
public class CInitiater { public class CInitiater {
private static boolean isLogConfigured = false;
private static void configureLog() {
if (isLogConfigured) {
return;
}
isLogConfigured = true;
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
lc.reset();
ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<ILoggingEvent>();
ca.setContext(lc);
ca.setName("console");
ca.setTarget("System.err");
PatternLayoutEncoder pl = new PatternLayoutEncoder();
pl.setContext(lc);
pl.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n");
pl.start();
ca.setEncoder(pl);
ca.start();
Logger rootLogger = lc.getLogger(Logger.ROOT_LOGGER_NAME);
rootLogger.addAppender(ca);
}
/** Called by the native program, this function creates a Mu instance. */ /** Called by the native program, this function creates a Mu instance. */
static long mu_refimpl2_new() { static long mu_refimpl2_new() {
configureLog(); return ScalaCInitiater$.MODULE$.mu_refimpl2_new();
MicroVM mvm = MicroVM$.MODULE$.apply();
long fak = NativeClientSupport$.MODULE$.exposeMicroVM(mvm);
return fak;
} }
/** /**
* Called by the native program, this function creates a Mu instance with * Called by the native program, this function creates a Mu instance with
* extra arguments. * extra arguments.
*/ */
static long mu_refimpl2_new_ex(String gcConfString) { static long mu_refimpl2_new_ex(String vmConf) {
configureLog(); return ScalaCInitiater$.MODULE$.mu_refimpl2_new_ex(vmConf);
MicroVM mvm = MicroVM$.MODULE$.apply(gcConfString);
long fak = NativeClientSupport$.MODULE$.exposeMicroVM(mvm);
return fak;
} }
/** /**
...@@ -66,7 +33,6 @@ public class CInitiater { ...@@ -66,7 +33,6 @@ public class CInitiater {
* instance. * instance.
*/ */
static void mu_refimpl2_close(long mvmFak) { static void mu_refimpl2_close(long mvmFak) {
NativeClientSupport$.MODULE$.unexposeMicroVM(mvmFak); ScalaCInitiater$.MODULE$.mu_refimpl_close(mvmFak);
// does not really deallocate it.
} }
} }
...@@ -26,7 +26,7 @@ object VMConf { ...@@ -26,7 +26,7 @@ object VMConf {
case "losSize" => losSize = value.toLong case "losSize" => losSize = value.toLong
case "globalSize" => globalSize = value.toLong case "globalSize" => globalSize = value.toLong
case "stackSize" => stackSize = value.toLong case "stackSize" => stackSize = value.toLong
case "vmLog" => setLog("uvm.refimpl", value) case "vmLog" => setLog("uvm", value)
case "gcLog" => setLog("uvm.refimpl.mem", value) case "gcLog" => setLog("uvm.refimpl.mem", value)
case _ => throw new UvmRefImplException("Unrecognized option %s".format(key)) case _ => throw new UvmRefImplException("Unrecognized option %s".format(key))
} }
......
...@@ -18,8 +18,8 @@ class MemorySupport(val muMemorySize: Word) { ...@@ -18,8 +18,8 @@ class MemorySupport(val muMemorySize: Word) {
val SIZE_LIMIT: Word = Int.MaxValue.toLong val SIZE_LIMIT: Word = Int.MaxValue.toLong
if (muMemorySize > SIZE_LIMIT) { if (muMemorySize > SIZE_LIMIT) {
throw new UvmRuntimeException("Memory too large (%d bytes requested)." + throw new UvmRuntimeException(("Memory too large (%d bytes requested)." +
" Due to the limitation of JNR-FFI, the maximum available memory size is %d bytes.".format(muMemorySize, SIZE_LIMIT)) " Due to the limitation of JNR-FFI, the maximum available memory size is %d bytes.").format(muMemorySize, SIZE_LIMIT))
} }
val muMemory = Memory.allocateDirect(jnrRuntime, muMemorySize.toInt, true) val muMemory = Memory.allocateDirect(jnrRuntime, muMemorySize.toInt, true)
......
package uvm.refimpl.nat
import org.slf4j.LoggerFactory
import ch.qos.logback.classic.LoggerContext
import ch.qos.logback.classic.encoder.PatternLayoutEncoder
import ch.qos.logback.classic.spi.ILoggingEvent
import ch.qos.logback.core.ConsoleAppender
import uvm.refimpl.MicroVM
import com.typesafe.scalalogging.Logger
object ScalaCInitiater {
val logger = Logger(LoggerFactory.getLogger("priv.uvm.refimpl.native.ScalaCInitiater"))
private var isLogConfigured = false;
private def configureLog(): Unit = {
if (isLogConfigured) {
return
}
isLogConfigured = true
val lc = LoggerFactory.getILoggerFactory().asInstanceOf[LoggerContext]
lc.reset()
val ca = new ConsoleAppender[ILoggingEvent]()
ca.setContext(lc)
ca.setName("console")
ca.setTarget("System.err")
val pl = new PatternLayoutEncoder()
pl.setContext(lc)
pl.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n")
pl.start()
ca.setEncoder(pl)
ca.start()
val rootLogger = lc.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME)
rootLogger.addAppender(ca)
}
def mu_refimpl2_new(): Long = try {
configureLog()
val mvm = MicroVM()
val fak = NativeClientSupport.exposeMicroVM(mvm)
return fak
} catch {
case t: Throwable => {
logger.error("Exception thrown when creating MicroVM", t)
0L
}
}
def mu_refimpl2_new_ex(vmConf: String): Long = try {
val mvm = MicroVM(vmConf)
val fak = NativeClientSupport.exposeMicroVM(mvm)
return fak
} catch {
case t: Throwable => {
logger.error("Exception thrown when creating MicroVM", t)
0L
}
}
def mu_refimpl_close(mvmFak: Long): Unit = try {
NativeClientSupport.unexposeMicroVM(mvmFak)
} catch {
case t: Throwable => {
logger.error("Exception thrown when closing MicroVM", t)
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment