From ed68f8a8b1e401815978927c9d695d809fd47ed2 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Mon, 19 Feb 2018 02:19:50 +0200 Subject: jvm: Implement more and document header Starting to look pretty good. --- src/fakejvm/jvm.h | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/fakejvm/jvm.h') diff --git a/src/fakejvm/jvm.h b/src/fakejvm/jvm.h index 3ab7025..937ddfd 100644 --- a/src/fakejvm/jvm.h +++ b/src/fakejvm/jvm.h @@ -6,12 +6,12 @@ struct jvm_string { const char *data; size_t size; - bool heap; + bool heap; // if on heap, then `data` should be freed }; struct jvm_array { void *data; - size_t element_sz, size; // size == in elements, size * element_sz for bytes + size_t element_sz, size; // `size` == in elements, `size * element_sz` for bytes }; struct jvm_class { @@ -24,18 +24,22 @@ struct jvm_method { }; struct jvm_object { + jclass this_klass; + union { struct jvm_array array; struct jvm_method method; struct jvm_class klass; struct jvm_string string; }; + enum jvm_object_type { JVM_OBJECT_NONE, JVM_OBJECT_ARRAY, JVM_OBJECT_METHOD, JVM_OBJECT_CLASS, JVM_OBJECT_STRING, + JVM_OBJECT_LAST, } type; }; @@ -45,9 +49,18 @@ struct jvm_native_method { }; struct jvm { + // [0] object is created on `jvm_init` and it's a class object for defining the class of a class + // every class object's `this_class` member points back to [0], causing recursion. + // Every other object or class definition is created lazily as needed, only [0] is special. + // `jobject`'s we return through JNI are actually (index+1) to this array, not pointers. struct jvm_object objects[256]; + + // Native methods registered by the application. + // Nothing special, but there's no need to access this array either really. + // You can use `jvm_get_native_method` instead. struct jvm_native_method methods[255]; + // These hold the function pointers for our JNI implementation. struct JNINativeInterface native; struct JNIInvokeInterface invoke; @@ -58,5 +71,11 @@ struct jvm { JavaVM vm; // points to invoke }; +void* +jvm_get_native_method(struct jvm *jvm, const char *klass, const char *method); + +void +jvm_release(struct jvm *jvm); + void jvm_init(struct jvm *jvm); -- cgit v1.2.3-70-g09d2