Commit c225bf8a authored by Kunshan Wang's avatar Kunshan Wang

Loading array supports NULL.

parent 8876d93c
...@@ -46,15 +46,18 @@ classpath.h: classpath.txt ...@@ -46,15 +46,18 @@ classpath.h: classpath.txt
xxd -i classpath.txt > classpath.h xxd -i classpath.txt > classpath.h
.PHONY: tests .PHONY: tests
tests: test_client tests: test_client test_client2
test_client: test_client.c libmurefimpl2start.so test_client: test_client.c libmurefimpl2start.so
$(CC) `./refimpl2-config --istart --cflags --libs` -o $@ $< $(CC) `./refimpl2-config --istart --cflags --libs` -o $@ $<
test_client2: test_client2.c libmurefimpl2start.so
$(CC) `./refimpl2-config --istart --cflags --libs` -o $@ $<
.PHONY: clean veryclean .PHONY: clean veryclean
clean: clean:
rm *.so test_client rm *.so test_client test_client2
veryclean: veryclean:
rm *.so test_client classpath.txt classpath.h rm *.so test_client test_client2 classpath.txt classpath.h
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h> // write
#include <refimpl2-start.h>
#include <muapi.h>
const char *hw_string = "Hello world!\n";
const char *hw2_string = "Goodbye world!\n";
const char *gc_conf =
"sosSize=524288\n"
"losSize=524288\n"
"globalSize=1048576\n"
"stackSize=32768\n"
"vmLog=DEBUG\n"
;
int main() {
MuVM *mvm = mu_refimpl2_new_ex(gc_conf);
//MuCtx *ctx = mvm->new_context(mvm);
//mvm->execute(mvm);
mu_refimpl2_close(mvm);
return 0;
}
...@@ -512,21 +512,29 @@ object NativeMuHelpers { ...@@ -512,21 +512,29 @@ object NativeMuHelpers {
} }
def readFromValueFakArray[T <: MuValue](faks: MuValueFakArrayPtr, len: Long): Seq[T] = { def readFromValueFakArray[T <: MuValue](faks: MuValueFakArrayPtr, len: Long): Seq[T] = {
for (i <- 0L until len) yield { if (faks == 0L) {
val addr = faks + i * WORD_SIZE_BYTES Seq()
val valFak = theMemory.getAddress(addr) } else {
val v = getMuValueNotNull(valFak) for (i <- 0L until len) yield {
v.asInstanceOf[T] val addr = faks + i * WORD_SIZE_BYTES
val valFak = theMemory.getAddress(addr)
val v = getMuValueNotNull(valFak)
v.asInstanceOf[T]
}
} }
} }
def readFromFlagArray(flags: MuValueFakArrayPtr, len: Long): Seq[Flag] = { def readFromFlagArray(flags: MuValueFakArrayPtr, len: Long): Seq[Flag] = {
val flagVals = for (i <- 0L until len) yield { if (flags == 0L) {
val addr = flags + i * 32 Seq()
val flagVal = theMemory.getInt(addr) } else {
flagVal val flagVals = for (i <- 0L until len) yield {
val addr = flags + i * 32
val flagVal = theMemory.getInt(addr)
flagVal
}
flagVals.map(intToFlag)
} }
flagVals.map(intToFlag)
} }
implicit class MuCtxExtras(val ctx: MuCtx) extends AnyVal { implicit class MuCtxExtras(val ctx: MuCtx) extends AnyVal {
...@@ -695,11 +703,16 @@ object NativeMuHelpers { ...@@ -695,11 +703,16 @@ object NativeMuHelpers {
} }
object ClientAccessibleClassExposer { object ClientAccessibleClassExposer {
import NativeClientSupport._
logger.debug("Creating mirror...")
// Reflection utils. // Reflection utils.
val mirror = ru.runtimeMirror(getClass.getClassLoader) val mirror = ru.runtimeMirror(getClass.getClassLoader)
val MAX_NAME_SIZE = 65536 val MAX_NAME_SIZE = 65536
logger.debug("Types for common types...")
// Type objects for common types. // Type objects for common types.
val TUnit = ru.typeTag[Unit].tpe val TUnit = ru.typeTag[Unit].tpe
...@@ -807,6 +820,8 @@ object ClientAccessibleClassExposer { ...@@ -807,6 +820,8 @@ object ClientAccessibleClassExposer {
case t if t <:< TMuValue => JType.POINTER case t if t <:< TMuValue => JType.POINTER
case t if t <:< TOptMuValue => JType.POINTER case t if t <:< TOptMuValue => JType.POINTER
} }
logger.debug("Allocating Mu error number memory...")
val MU_NATIVE_ERRNO = 6481626 // muErrno is set to this number if an exception is thrown val MU_NATIVE_ERRNO = 6481626 // muErrno is set to this number if an exception is thrown
val muErrorPtr = jnrMemoryManager.allocateDirect(16) val muErrorPtr = jnrMemoryManager.allocateDirect(16)
...@@ -841,6 +856,8 @@ object ClientAccessibleClassExposer { ...@@ -841,6 +856,8 @@ object ClientAccessibleClassExposer {
*/ */
class ClientAccessibleClassExposer[T: ru.TypeTag: ClassTag](obj: T) { class ClientAccessibleClassExposer[T: ru.TypeTag: ClassTag](obj: T) {
import ClientAccessibleClassExposer._ import ClientAccessibleClassExposer._
logger.debug("Creating closure handles...")
/** /**
* A list of JFFI closure handles, one for each declared method in obj, in the declared order. * A list of JFFI closure handles, one for each declared method in obj, in the declared order.
...@@ -1014,7 +1031,9 @@ object NativeClientSupport { ...@@ -1014,7 +1031,9 @@ object NativeClientSupport {
val stringPool = HashMap[String, Pointer]() val stringPool = HashMap[String, Pointer]()
// These "exposer" can repeatedly generate function tables. // These "exposer" can repeatedly generate function tables.
logger.debug("Creating Mu VM Exposer...")
val muVMExposer = new ClientAccessibleClassExposer(NativeMuVM) val muVMExposer = new ClientAccessibleClassExposer(NativeMuVM)
logger.debug("Creating Mu Ctx Exposer...")
val muCtxExposer = new ClientAccessibleClassExposer(NativeMuCtx) val muCtxExposer = new ClientAccessibleClassExposer(NativeMuCtx)
// Expose and unexpose objects // Expose and unexpose objects
......
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