To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

Commit edf705a1 authored by Kunshan Wang's avatar Kunshan Wang
Browse files

Log exception in VM creation from C API

parent f77642c3
......@@ -15,50 +15,17 @@ import uvm.refimpl.MicroVM$;
/** Static functions for the convenient of C programs that start Mu via JNI. */
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. */
static long mu_refimpl2_new() {
configureLog();
MicroVM mvm = MicroVM$.MODULE$.apply();
long fak = NativeClientSupport$.MODULE$.exposeMicroVM(mvm);
return fak;
return ScalaCInitiater$.MODULE$.mu_refimpl2_new();
}
/**
* Called by the native program, this function creates a Mu instance with
* extra arguments.
*/
static long mu_refimpl2_new_ex(String gcConfString) {
configureLog();
MicroVM mvm = MicroVM$.MODULE$.apply(gcConfString);
long fak = NativeClientSupport$.MODULE$.exposeMicroVM(mvm);
return fak;
static long mu_refimpl2_new_ex(String vmConf) {
return ScalaCInitiater$.MODULE$.mu_refimpl2_new_ex(vmConf);
}
/**
......@@ -66,7 +33,6 @@ public class CInitiater {
* instance.
*/
static void mu_refimpl2_close(long mvmFak) {
NativeClientSupport$.MODULE$.unexposeMicroVM(mvmFak);
// does not really deallocate it.
ScalaCInitiater$.MODULE$.mu_refimpl_close(mvmFak);
}
}
......@@ -26,7 +26,7 @@ object VMConf {
case "losSize" => losSize = value.toLong
case "globalSize" => globalSize = 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 _ => throw new UvmRefImplException("Unrecognized option %s".format(key))
}
......
......@@ -18,8 +18,8 @@ class MemorySupport(val muMemorySize: Word) {
val SIZE_LIMIT: Word = Int.MaxValue.toLong
if (muMemorySize > SIZE_LIMIT) {
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))
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))
}
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