#include "mm/memory.h"
-#include "native/jni.h"
+#include "native/jni.hpp"
#include "native/llni.h"
-#include "native/native.h"
+#include "native/native.hpp"
-#include "native/include/java_lang_AssertionStatusDirectives.h"
-#include "native/include/java_lang_String.h" /* required by j.l.CL */
-#include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */
-#include "native/include/java_lang_ClassLoader.h" /* required by j.l.C */
-#include "native/include/java_lang_StackTraceElement.h"
-#include "native/include/java_lang_Throwable.h"
-#include "native/include/java_security_ProtectionDomain.h"
-
-#if defined(ENABLE_ANNOTATIONS)
-#include "native/include/sun_reflect_ConstantPool.h"
-#endif
-
-#include "native/vm/reflect.h"
+#include "native/vm/reflection.hpp"
#include "native/vm/openjdk/hpi.h"
+#include "native/vm/openjdk/management.hpp"
-#include "threads/lock-common.h"
+#include "threads/lock.hpp"
#include "threads/thread.hpp"
#include "toolbox/logging.h"
-#include "toolbox/list.h"
+#include "toolbox/list.hpp"
-#include "vm/array.h"
+#include "vm/array.hpp"
#if defined(ENABLE_ASSERTION)
-#include "vm/assertion.h"
+#include "vm/assertion.hpp"
#endif
-#include "vm/builtin.h"
+#include "vm/jit/builtin.hpp"
+#include "vm/classcache.h"
#include "vm/exceptions.hpp"
#include "vm/global.h"
+#include "vm/globals.hpp"
#include "vm/initialize.h"
+#include "vm/javaobjects.hpp"
+#include "vm/options.h"
+#include "vm/os.hpp"
#include "vm/package.hpp"
#include "vm/primitive.hpp"
-#include "vm/properties.h"
+#include "vm/properties.hpp"
#include "vm/resolve.h"
#include "vm/signallocal.h"
#include "vm/string.hpp"
#include "vm/jit/stacktrace.hpp"
-#include "vmcore/classcache.h"
-#include "vmcore/globals.hpp"
-#include "vmcore/options.h"
-#include "vmcore/os.hpp"
-
/* debugging macros ***********************************************************/
-D option, as requested. */
jio_snprintf(buf, sizeof(buf), PRINTF_FORMAT_INT64_T, opt_MaxDirectMemorySize);
- properties_add("sun.nio.MaxDirectMemorySize", buf);
+ VM::get_current()->get_properties().put("sun.nio.MaxDirectMemorySize", buf);
- /* Add all properties. */
-
- properties_system_add_all(h);
+ // Fill the java.util.Properties object.
+ VM::get_current()->get_properties().fill(h);
return properties;
}
void JVM_FillInStackTrace(JNIEnv *env, jobject receiver)
{
- java_lang_Throwable *o;
- java_handle_bytearray_t *ba;
-
TRACEJVMCALLS(("JVM_FillInStackTrace(env=%p, receiver=%p)", env, receiver));
- o = (java_lang_Throwable *) receiver;
-
- ba = stacktrace_get_current();
+ java_handle_bytearray_t* ba = stacktrace_get_current();
if (ba == NULL)
return;
- LLNI_field_set_ref(o, backtrace, (java_lang_Object *) ba);
+ java_lang_Throwable jlt(receiver, ba);
}
jint JVM_GetStackTraceDepth(JNIEnv *env, jobject throwable)
{
- java_lang_Throwable *to;
- java_lang_Object *o;
- java_handle_bytearray_t *ba;
- stacktrace_t *st;
- int32_t depth;
-
TRACEJVMCALLS(("JVM_GetStackTraceDepth(env=%p, throwable=%p)", env, throwable));
- if (throwable == NULL) {
+ java_lang_Throwable jlt(throwable);
+
+ if (jlt.is_null()) {
exceptions_throw_nullpointerexception();
return 0;
}
- to = (java_lang_Throwable *) throwable;
-
- LLNI_field_get_ref(to, backtrace, o);
-
- ba = (java_handle_bytearray_t *) o;
+ java_handle_bytearray_t* ba = jlt.get_backtrace();
if (ba == NULL)
return 0;
- /* We need a critical section here as the stacktrace structure is
- mapped onto a Java byte-array. */
+ // We need a critical section here as the stacktrace structure is
+ // mapped onto a Java byte-array.
LLNI_CRITICAL_START;
- st = (stacktrace_t *) LLNI_array_data(ba);
+ stacktrace_t* st = (stacktrace_t *) LLNI_array_data(ba);
- depth = st->length;
+ int32_t depth = st->length;
LLNI_CRITICAL_END;
jobject JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index)
{
- java_lang_Throwable *to;
- java_lang_Object *o;
- java_handle_bytearray_t *ba;
- stacktrace_t *st;
- stacktrace_entry_t *ste;
- codeinfo *code;
- methodinfo *m;
- classinfo *c;
- java_lang_StackTraceElement *steo;
- java_handle_t* declaringclass;
- java_lang_String *filename;
- int32_t linenumber;
-
TRACEJVMCALLS(("JVM_GetStackTraceElement(env=%p, throwable=%p, index=%d)", env, throwable, index));
- to = (java_lang_Throwable *) throwable;
-
- LLNI_field_get_ref(to, backtrace, o);
-
- ba = (java_handle_bytearray_t *) o;
+ java_lang_Throwable jlt(throwable);
+ java_handle_bytearray_t* ba = jlt.get_backtrace();
- /* FIXME critical section */
+ // We need a critical section here as the stacktrace structure is
+ // mapped onto a Java byte-array.
+ LLNI_CRITICAL_START;
- st = (stacktrace_t *) LLNI_array_data(ba);
+ stacktrace_t* st = (stacktrace_t *) LLNI_array_data(ba);
if ((index < 0) || (index >= st->length)) {
/* XXX This should be an IndexOutOfBoundsException (check this
again). */
-
exceptions_throw_arrayindexoutofboundsexception();
return NULL;
}
- /* Get the stacktrace entry. */
-
- ste = &(st->entries[index]);
-
- /* Get the codeinfo, methodinfo and classinfo. */
-
- code = ste->code;
- m = code->m;
- c = m->clazz;
+ // Get the stacktrace entry.
+ stacktrace_entry_t* ste = &(st->entries[index]);
- /* allocate a new StackTraceElement */
+ // Get the codeinfo, methodinfo and classinfo.
+ codeinfo* code = ste->code;
+ methodinfo* m = code->m;
+ classinfo* c = m->clazz;
- steo = (java_lang_StackTraceElement *)
- builtin_new(class_java_lang_StackTraceElement);
-
- if (steo == NULL)
- return NULL;
-
- /* get filename */
+ // Get filename.
+ java_handle_t* filename;
if (!(m->flags & ACC_NATIVE)) {
if (c->sourcefile != NULL)
- filename = (java_lang_String *) javastring_new(c->sourcefile);
+ filename = javastring_new(c->sourcefile);
else
filename = NULL;
}
else
filename = NULL;
- /* get line number */
+ // Get line number.
+ int32_t linenumber;
if (m->flags & ACC_NATIVE) {
linenumber = -2;
}
else {
- /* FIXME The linenumbertable_linenumber_for_pc could change
- the methodinfo pointer when hitting an inlined method. */
-
- linenumber = linenumbertable_linenumber_for_pc(&m, code, ste->pc);
+ // FIXME linenumbertable->find could change the methodinfo
+ // pointer when hitting an inlined method.
+ linenumber = code->linenumbertable->find(&m, ste->pc);
linenumber = (linenumber == 0) ? -1 : linenumber;
}
- /* get declaring class name */
-
- declaringclass = class_get_classname(c);
+ LLNI_CRITICAL_END;
- /* fill the java.lang.StackTraceElement element */
+ // Get declaring class name.
+ java_handle_t* declaringclass = class_get_classname(c);
- /* FIXME critical section */
+ // Allocate a new StackTraceElement object.
+ java_lang_StackTraceElement jlste(declaringclass, javastring_new(m->name), filename, linenumber);
- steo->declaringClass = (java_lang_String*) declaringclass;
- steo->methodName = (java_lang_String*) javastring_new(m->name);
- steo->fileName = filename;
- steo->lineNumber = linenumber;
+ if (jlste.is_null())
+ return NULL;
- return (jobject) steo;
+ return (jobject) jlste.get_handle();
}
{
TRACEJVMCALLS(("JVM_IHashCode(env=%p, jobject=%p)", env, handle));
- return (jint) ((ptrint) handle);
+ java_lang_Object o(handle);
+
+ return o.get_hashcode();
}
jbyteArray JVM_GetClassAnnotations(JNIEnv *env, jclass cls)
{
- classinfo *c = NULL; /* classinfo for 'cls' */
- java_handle_bytearray_t *annotations = NULL; /* unparsed annotations */
-
- TRACEJVMCALLS(("JVM_GetClassAnnotations: cls=%p", cls));
+ TRACEJVMCALLS(("JVM_GetClassAnnotations(env=%p, cls=%p)", env, cls));
if (cls == NULL) {
exceptions_throw_nullpointerexception();
return NULL;
}
- c = LLNI_classinfo_unwrap(cls);
+ classinfo* c = LLNI_classinfo_unwrap(cls);
/* get annotations: */
- annotations = class_get_annotations(c);
+ java_handle_bytearray_t* annotations = class_get_annotations(c);
- return (jbyteArray)annotations;
+ return (jbyteArray) annotations;
}
jbyteArray JVM_GetFieldAnnotations(JNIEnv *env, jobject field)
{
- java_lang_reflect_Field *rf = NULL; /* java.lang.reflect.Field for 'field' */
- java_handle_bytearray_t *ba = NULL; /* unparsed annotations */
+ TRACEJVMCALLS(("JVM_GetFieldAnnotations(env=%p, field=%p)", env, field));
- TRACEJVMCALLS(("JVM_GetFieldAnnotations: field=%p", field));
+ java_lang_reflect_Field jlrf(field);
- if (field == NULL) {
+ if (jlrf.is_null()) {
exceptions_throw_nullpointerexception();
return NULL;
}
- rf = (java_lang_reflect_Field*)field;
-
- LLNI_field_get_ref(rf, annotations, ba);
-
- return (jbyteArray)ba;
+ return (jbyteArray) jlrf.get_annotations();
}
jbyteArray JVM_GetMethodAnnotations(JNIEnv *env, jobject method)
{
- java_lang_reflect_Method *rm = NULL; /* java.lang.reflect.Method for 'method' */
- java_handle_bytearray_t *ba = NULL; /* unparsed annotations */
+ TRACEJVMCALLS(("JVM_GetMethodAnnotations(env=%p, method=%p)", env, method));
- TRACEJVMCALLS(("JVM_GetMethodAnnotations: method=%p", method));
+ java_lang_reflect_Method jlrm(method);
- if (method == NULL) {
+ if (jlrm.is_null()) {
exceptions_throw_nullpointerexception();
return NULL;
}
- rm = (java_lang_reflect_Method*)method;
-
- LLNI_field_get_ref(rm, annotations, ba);
-
- return (jbyteArray)ba;
+ return (jbyteArray) jlrm.get_annotations();
}
jbyteArray JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject method)
{
- java_lang_reflect_Method *rm = NULL; /* java.lang.reflect.Method for 'method' */
- java_handle_bytearray_t *ba = NULL; /* unparsed annotation default value */
+ TRACEJVMCALLS(("JVM_GetMethodDefaultAnnotationValue(env=%p, method=%p)", env, method));
- TRACEJVMCALLS(("JVM_GetMethodDefaultAnnotationValue: method=%p", method));
+ java_lang_reflect_Method jlrm(method);
- if (method == NULL) {
+ if (jlrm.is_null()) {
exceptions_throw_nullpointerexception();
return NULL;
}
- rm = (java_lang_reflect_Method*)method;
-
- LLNI_field_get_ref(rm, annotationDefault, ba);
-
- return (jbyteArray)ba;
+ return (jbyteArray) jlrm.get_annotationDefault();
}
jbyteArray JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject method)
{
- java_lang_reflect_Method *rm = NULL; /* java.lang.reflect.Method for 'method' */
- java_handle_bytearray_t *ba = NULL; /* unparsed parameter annotations */
+ TRACEJVMCALLS(("JVM_GetMethodParameterAnnotations(env=%p, method=%p)", env, method));
- TRACEJVMCALLS(("JVM_GetMethodParameterAnnotations: method=%p", method));
+ java_lang_reflect_Method jlrm(method);
- if (method == NULL) {
+ if (jlrm.is_null()) {
exceptions_throw_nullpointerexception();
return NULL;
}
- rm = (java_lang_reflect_Method*)method;
-
- LLNI_field_get_ref(rm, parameterAnnotations, ba);
-
- return (jbyteArray)ba;
+ return (jbyteArray) jlrm.get_parameterAnnotations();
}
jobjectArray JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly)
{
- classinfo *c;
- java_handle_objectarray_t *oa;
-
TRACEJVMCALLS(("JVM_GetClassDeclaredMethods(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly));
- c = LLNI_classinfo_unwrap(ofClass);
+ classinfo* c = LLNI_classinfo_unwrap(ofClass);
- oa = class_get_declaredmethods(c, publicOnly);
+ java_handle_objectarray_t* oa = class_get_declaredmethods(c, publicOnly);
return (jobjectArray) oa;
}
jobject JVM_GetClassConstantPool(JNIEnv *env, jclass cls)
{
#if defined(ENABLE_ANNOTATIONS)
- sun_reflect_ConstantPool *constantPool = NULL;
- /* constant pool object for the class refered by 'cls' */
- java_lang_Object *constantPoolOop = (java_lang_Object*)cls;
- /* constantPoolOop field of the constant pool object */
-
TRACEJVMCALLS(("JVM_GetClassConstantPool(env=%p, cls=%p)", env, cls));
- constantPool =
- (sun_reflect_ConstantPool*)native_new_and_init(
- class_sun_reflect_ConstantPool);
+ java_handle_t* h = native_new_and_init(class_sun_reflect_ConstantPool);
+ sun_reflect_ConstantPool cp(h, cls);
- if (constantPool == NULL) {
- /* out of memory */
+ if (cp.is_null()) {
return NULL;
}
- LLNI_field_set_ref(constantPool, constantPoolOop, constantPoolOop);
-
- return (jobject)constantPool;
+ return (jobject) cp.get_handle();
#else
log_println("JVM_GetClassConstantPool(env=%p, cls=%p): not implemented in this configuration!", env, cls);
return NULL;
return NULL;
}
+ // Create a new java.lang.reflect.Method Java object.
/* XXX: is that right? or do I have to use resolve_method_*? */
- return (jobject)reflect_method_new(ref->p.method);
+ java_lang_reflect_Method jlrm(ref->p.method);
+
+ return (jobject) jlrm.get_handle();
}
return NULL;
}
- return (jobject)reflect_method_new(ref->p.method);
+ // Create a new java.lang.reflect.Method Java object.
+ java_lang_reflect_Method jlrm(ref->p.method);
+
+ return (jobject) jlrm.get_handle();
}
return NULL;
}
- return (jobject)reflect_field_new(ref->p.field);
+ // Create a new java.lang.reflect.Field Java object.
+ java_lang_reflect_Field jlrf(ref->p.field);
+
+ return (jobject) jlrf.get_handle();
}
return NULL;
}
- return (jobject)reflect_field_new(ref->p.field);
+ // Create a new java.lang.reflect.Field Java object.
+ java_lang_reflect_Field jlrf(ref->p.field);
+
+ return (jobject) jlrf.get_handle();
}
jboolean JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls)
{
#if defined(ENABLE_ASSERTION)
- assertion_name_t *item;
classinfo *c;
jboolean status;
utf *name;
}
if (list_assertion_names != NULL) {
- item = (assertion_name_t *)list_first(list_assertion_names);
- while (item != NULL) {
+ for (List<assertion_name_t*>::iterator it = list_assertion_names->begin();
+ it != list_assertion_names->end(); it++) {
+ assertion_name_t* item = *it;
+
name = utf_new_char(item->name);
if (name == c->packagename) {
status = (jboolean)item->enabled;
else if (name == c->name) {
status = (jboolean)item->enabled;
}
-
- item = (assertion_name_t *)list_next(list_assertion_names, item);
}
}
jobject JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused)
{
- classinfo *c;
- java_lang_AssertionStatusDirectives *o;
java_handle_objectarray_t *classes;
java_handle_objectarray_t *packages;
java_booleanarray_t *classEnabled;
java_booleanarray_t *packageEnabled;
#if defined(ENABLE_ASSERTION)
- assertion_name_t *item;
java_handle_t *js;
s4 i, j;
#endif
TRACEJVMCALLS(("JVM_AssertionStatusDirectives(env=%p, unused=%p)", env, unused));
- c = load_class_bootstrap(utf_new_char("java/lang/AssertionStatusDirectives"));
-
- if (c == NULL)
- return NULL;
-
- o = (java_lang_AssertionStatusDirectives *) builtin_new(c);
-
- if (o == NULL)
- return NULL;
-
#if defined(ENABLE_ASSERTION)
classes = builtin_anewarray(assertion_class_count, class_java_lang_Object);
#else
i = 0;
j = 0;
- item = (assertion_name_t *)list_first(list_assertion_names);
- while (item != NULL) {
+ for (List<assertion_name_t*>::iterator it = list_assertion_names->begin(); it != list_assertion_names->end(); it++) {
+ assertion_name_t* item = *it;
+
js = javastring_new_from_ascii(item->name);
if (js == NULL) {
return NULL;
packageEnabled->data[j] = (jboolean) item->enabled;
j += 1;
}
-
- item = (assertion_name_t *)list_next(list_assertion_names, item);
}
}
#endif
/* set instance fields */
- o->classes = classes;
- o->packages = packages;
- o->classEnabled = classEnabled;
- o->packageEnabled = packageEnabled;
+ java_lang_AssertionStatusDirectives jlasd(classes, classEnabled, packages, packageEnabled);
- return (jobject) o;
+ return (jobject) jlasd.get_handle();
}
JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void)
{
- java_object_t *o;
-
TRACEJVMCALLS(("JVM_RawMonitorCreate()"));
- o = NEW(java_object_t);
-
- lock_init_object_lock(o);
+ Mutex* m = new Mutex();
- return o;
+ return m;
}
/* JVM_RawMonitorDestroy */
-JNIEXPORT void JNICALL JVM_RawMonitorDestroy(void *mon)
+JNIEXPORT void JNICALL JVM_RawMonitorDestroy(void* mon)
{
TRACEJVMCALLS(("JVM_RawMonitorDestroy(mon=%p)", mon));
- FREE(mon, java_object_t);
+ delete ((Mutex*) mon);
}
/* JVM_RawMonitorEnter */
-JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon)
+JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void* mon)
{
TRACEJVMCALLS(("JVM_RawMonitorEnter(mon=%p)", mon));
- (void) lock_monitor_enter((java_object_t *) mon);
+ ((Mutex*) mon)->lock();
return 0;
}
/* JVM_RawMonitorExit */
-JNIEXPORT void JNICALL JVM_RawMonitorExit(void *mon)
+JNIEXPORT void JNICALL JVM_RawMonitorExit(void* mon)
{
TRACEJVMCALLS(("JVM_RawMonitorExit(mon=%p)", mon));
- (void) lock_monitor_exit((java_object_t *) mon);
+ ((Mutex*) mon)->unlock();
}
jobject JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0)
{
- java_lang_reflect_Method *rm;
- classinfo *c;
- int32_t slot;
- int32_t override;
- methodinfo *m;
- java_handle_t *ro;
-
TRACEJVMCALLS(("JVM_InvokeMethod(env=%p, method=%p, obj=%p, args0=%p)", env, method, obj, args0));
- rm = (java_lang_reflect_Method *) method;
-
- LLNI_field_get_cls(rm, clazz, c);
- LLNI_field_get_val(rm, slot, slot);
- LLNI_field_get_val(rm, override, override);
-
- m = &(c->methods[slot]);
-
- ro = reflect_method_invoke(m, (java_handle_t *) obj, (java_handle_objectarray_t *) args0, override);
+ java_lang_reflect_Method jlrm(method);
+
+ java_handle_t* result = jlrm.invoke((java_handle_t*) obj, (java_handle_objectarray_t*) args0);
- return (jobject) ro;
+ return (jobject) result;
}
jobject JVM_NewInstanceFromConstructor(JNIEnv *env, jobject con, jobjectArray args0)
{
- java_lang_reflect_Constructor *rc;
- classinfo *c;
- int32_t slot;
- int32_t override;
- methodinfo *m;
- java_handle_t *o;
-
TRACEJVMCALLS(("JVM_NewInstanceFromConstructor(env=%p, c=%p, args0=%p)", env, con, args0));
- rc = (java_lang_reflect_Constructor *) con;
-
- LLNI_field_get_cls(rc, clazz, c);
- LLNI_field_get_val(rc, slot, slot);
- LLNI_field_get_val(rc, override, override);
-
- m = &(c->methods[slot]);
-
- o = reflect_constructor_newinstance(m, (java_handle_objectarray_t *) args0, override);
+ java_lang_reflect_Constructor jlrc(con);
+ java_handle_t* o = jlrc.new_instance((java_handle_objectarray_t*) args0);
return (jobject) o;
}
{
TRACEJVMCALLS(("JVM_GetManagement(version=%d)", version));
- /* TODO We current don't support the management interface. */
-
- return NULL;
+ return Management::get_jmm_interface(version);
}
if (strcmp(name, "TERM") == 0)
return SIGTERM;
+#elif defined(__SOLARIS__)
+ int signum;
+
+ if (os::str2sig(name, &signum) == -1)
+ return -1;
+
+ return signum;
#else
-# error not implemented for this OS
+# error Not implemented for this OS.
#endif
return -1;
* c-basic-offset: 4
* tab-width: 4
* End:
+ * vim:noexpandtab:sw=4:ts=4:
*/