Exemple #1
0
DoubleArray* Java_aura_rt_VM_newDoubleArray(Env* env, Class* c, jlong address, jint size) {
    DoubleArray* array = rvmNewDoubleArray(env, size);
    if (array) {
        memcpy(array->values, LONG_TO_PTR(address), size * sizeof(jdouble));
    }
    return array;
}
Exemple #2
0
FloatArray* Java_org_robovm_rt_VM_newFloatArray(Env* env, Class* c, jlong address, jint size) {
    FloatArray* array = rvmNewFloatArray(env, size);
    if (array) {
        memcpy(array->values, LONG_TO_PTR(address), size * sizeof(jfloat));
    }
    return array;
}
Exemple #3
0
ObjectArray* Java_java_lang_Thread_internalGetStackTrace(Env* env, Class* cls, JavaThread* threadObj) {
    Thread* thread = (Thread*) LONG_TO_PTR(threadObj->threadPtr);
    CallStack* callStack = NULL;
    if (thread) {
        callStack = rvmCaptureCallStackForThread(env, thread);
    }
    return rvmCallStackToStackTraceElements(env, callStack, 0);
}
Exemple #4
0
void Java_java_lang_Thread_internalSetPriority(Env* env, Class* cls, JavaThread* threadObj, jint priority) {
    rvmLockThreadsList();
    Thread* thread = (Thread*) LONG_TO_PTR(threadObj->threadPtr);
    if (thread) {
        rvmChangeThreadPriority(env, thread, priority);
    }
    rvmUnlockThreadsList();
}
Exemple #5
0
void Java_java_lang_Thread_internalInterrupt(Env* env, Class* cls, JavaThread* threadObj) {
    rvmLockThreadsList();
    Thread* thread = (Thread*) LONG_TO_PTR(threadObj->threadPtr);
    if (thread) {
        rvmThreadInterrupt(env, thread);
    }
    rvmUnlockThreadsList();
}
Exemple #6
0
void Java_java_lang_Thread_internalSetName(Env* env, Class* cls, JavaThread* threadObj, Object* threadName) {
    rvmLockThreadsList();
    Thread* thread = (Thread*) LONG_TO_PTR(threadObj->threadPtr);
    if (thread) {
        rvmThreadNameChanged(env, thread);
    }
    rvmUnlockThreadsList();
}
ObjectArray* Java_java_lang_reflect_Method_getExceptionTypes(Env* env, Class* clazz, jlong methodPtr) {
    Method* method = (Method*) LONG_TO_PTR(methodPtr);
    Class* java_lang_reflect_Proxy = rvmFindClassUsingLoader(env, "java/lang/reflect/Proxy", NULL);
    if (method->clazz->superclass == java_lang_reflect_Proxy) {
        return rvmAttributeGetExceptions(env, ((ProxyMethod*) method)->proxiedMethod);
    }
    return rvmAttributeGetExceptions(env, method);
}
Exemple #8
0
jint Java_java_lang_Thread_internalGetState(Env* env, Class* cls, JavaThread* threadObj) {
    rvmLockThreadsList();
    Thread* thread = (Thread*) LONG_TO_PTR(threadObj->threadPtr);
    jint status = THREAD_ZOMBIE; // If thread==NULL we assume the thread has been finished
    if (thread) {
        status = thread->status;
    }
    rvmUnlockThreadsList();
    return status;
}
Exemple #9
0
jboolean Java_java_lang_Thread_internalIsInterrupted(Env* env, Class* cls, JavaThread* threadObj) {
    rvmLockThreadsList();
    Thread* thread = (Thread*) LONG_TO_PTR(threadObj->threadPtr);
    jboolean interrupted = FALSE;
    if (thread) {
        interrupted = thread->interrupted;
    }
    rvmUnlockThreadsList();
    return interrupted;
}
Exemple #10
0
Field* getFieldFromFieldObject(Env* env, Object* fieldObject) {
    if (!java_lang_reflect_Field) {
        java_lang_reflect_Field = rvmFindClassUsingLoader(env, "java/lang/reflect/Field", NULL);
        if (!java_lang_reflect_Field) return NULL;
    }
    if (!java_lang_reflect_Field_field) {
        java_lang_reflect_Field_field = rvmGetInstanceField(env, java_lang_reflect_Field, "field", "J");
        if (!java_lang_reflect_Field_field) return NULL;
    }
    return (Field*) LONG_TO_PTR(rvmGetLongInstanceFieldValue(env, fieldObject, java_lang_reflect_Field_field));
}
Exemple #11
0
Method* getMethodFromMethodObject(Env* env, Object* methodObject) {
    if (!java_lang_reflect_Method) {
        java_lang_reflect_Method = rvmFindClassUsingLoader(env, "java/lang/reflect/Method", NULL);
        if (!java_lang_reflect_Method) return NULL;
    }
    if (!java_lang_reflect_Method_method) {
        java_lang_reflect_Method_method = rvmGetInstanceField(env, java_lang_reflect_Method, "method", "J");
        if (!java_lang_reflect_Method_method) return NULL;
    }
    return (Method*) LONG_TO_PTR(rvmGetLongInstanceFieldValue(env, methodObject, java_lang_reflect_Method_method));
}
Exemple #12
0
BooleanArray* Java_aura_rt_VM_newBooleanArray(Env* env, Class* c, jlong address, jint size) {
    BooleanArray* array = rvmNewBooleanArray(env, size);
    if (array) {
        jbyte* data = (jbyte*) LONG_TO_PTR(address);
        jint i = 0;
        for (i = 0; i < size; i++) {
            array->values[i] = *data ? TRUE : FALSE;
            data++;
        }
    }
    return array;
}
ObjectArray* Java_java_lang_Throwable_nativeGetStackTrace(Env* env, Object* thiz, jlong stackState) {
    CallStack* callStack = (CallStack*) LONG_TO_PTR(stackState);
    if (!callStack) {
        return rvmCallStackToStackTraceElements(env, NULL, 0);
    }

    jint index = 0;
    jint first = 0;
    Method* m = rvmGetNextCallStackMethod(env, callStack, &index);
    if (m && m->clazz == java_lang_Throwable && !strcmp(m->name, "nativeFillInStackTrace")) {
        // Skip Throwable.nativeFillInStackTrace()
        rvmGetNextCallStackMethod(env, callStack, &index); // Skip Throwable.fillInStackTrace()
        m = rvmGetNextCallStackMethod(env, callStack, &index);
        first = index;
        if (m) {
            Class* clazz = m->clazz;
            if (clazz == java_lang_Throwable && METHOD_IS_CONSTRUCTOR(m)) {
                // fillInStackTrace() was called from the constructor of Throwable
                // Skip all constructors until the constructor of thiz->clazz
                Class* superclass = java_lang_Object;
                while (m && METHOD_IS_CONSTRUCTOR(m) && clazz != thiz->clazz && clazz->superclass == superclass) {
                    m = rvmGetNextCallStackMethod(env, callStack, &index);
                    if (m && m->clazz != clazz) {
                        superclass = clazz;
                        clazz = m->clazz;
                    }
                    first = index - 1;
                }
                // We're now at the constructor of thiz->clazz which called super(). 
                // Skip all constructors belonging to thiz->clazz to get to the method which created the throwable
                while (m && METHOD_IS_CONSTRUCTOR(m) && clazz == thiz->clazz) {
                    m = rvmGetNextCallStackMethod(env, callStack, &index);
                    if (m) clazz = m->clazz;
                    first = index - 1;
                }
            }
        }
    }

    return rvmCallStackToStackTraceElements(env, callStack, first);
}
Exemple #14
0
void rvmThrow(Env* env, Object* e) {
    // TODO: Check that e != NULL?
    if (env->throwable) {
        rvmAbort("rvmThrow() called with env->throwable already set");
    }
    if (IS_TRACE_ENABLED) {
        jlong stackState = rvmGetLongInstanceFieldValue(env, e, stackStateField);
        CallStack* callStack = (CallStack*) LONG_TO_PTR(stackState);
        if (!callStack || callStack->length == 0) {
            TRACEF("Throwing a %s with empty call stack", e->clazz->name);
        } else {
            TRACEF("Throwing a %s. Call stack:", e->clazz->name);
            Method* m;
            jint index = 0;
            while ((m = rvmGetNextCallStackMethod(env, callStack, &index)) != NULL) {
                TRACEF("    %s.%s%s", m->clazz->name, m->name, m->desc);
            }
        }
    }
    env->throwable = e;
}
Object* Java_java_lang_reflect_Constructor_internalNewInstance(Env* env, JClass* clazz, jlong methodPtr, ObjectArray* parameterTypes, ObjectArray* args) {
    Method* method = (Method*) LONG_TO_PTR(methodPtr);

    /*
     * The Java code has already checked that the constructor is accessible
     * to the the caller, that the class can be instatiated and that the number 
     * of arguments are correct. The args array is never null.
     */

    jvalue* jvalueArgs = validateAndUnwrapArgs(env, parameterTypes, args);
    if (!jvalueArgs) return NULL;

    Object* o = rvmNewObjectA(env, method->clazz, method, jvalueArgs);
    if (!o) {
        Object* exception = rvmExceptionOccurred(env);
        if (exception->clazz != java_lang_ExceptionInInitializerError) {
            throwInvocationTargetException(env, rvmExceptionOccurred(env));
        }
        return NULL;
    }
    return o;
}
ObjectArray* Java_java_lang_reflect_Method_getParameterTypes(Env* env, Class* clazz, jlong methodPtr) {
    Method* method = (Method*) LONG_TO_PTR(methodPtr);

    jint argsCount = rvmGetParameterCount(method);

    Class* array_java_lang_Class = rvmFindClassUsingLoader(env, "[Ljava/lang/Class;", NULL);
    if (!array_java_lang_Class) return NULL;
    ObjectArray* paramTypes = rvmNewObjectArray(env, argsCount, NULL, array_java_lang_Class, NULL);
    if (!paramTypes) return NULL;

    const char* desc = method->desc;
    const char* s;
    jint i = 0;
    while ((s = rvmGetNextParameterType(&desc))) {
        char* paramTypeName = rvmAllocateMemoryAtomic(env, desc - s + 1);
        if (!paramTypeName) return NULL;
        strncpy(paramTypeName, s, desc - s);
        Class* paramType = rvmFindClassByDescriptor(env, paramTypeName, method->clazz->classLoader);
        if (!paramType) return NULL;
        paramTypes->values[i++] = (Object*) paramType;
    }

    return paramTypes;
}
Exemple #17
0
jboolean Java_aura_rt_VM_getBoolean(Env* env, Class* c, jlong address) {
    return *((jboolean*) LONG_TO_PTR(address));
}
Exemple #18
0
void Java_aura_rt_VM_setPointer(Env* env, Class* c, jlong address, jlong value) {
    *((void**) LONG_TO_PTR(address)) = LONG_TO_PTR(value);
}
Exemple #19
0
Object* Java_aura_rt_VM_newStringUTF(Env* env, Class* c, jlong address) {
    return rvmNewStringUTF(env, (char*) LONG_TO_PTR(address), -1);
}
Exemple #20
0
void Java_aura_rt_VM_setBoolean(Env* env, Class* c, jlong address, jboolean value) {
    *((jboolean*) LONG_TO_PTR(address)) = value;
}
Exemple #21
0
jlong Java_aura_rt_VM_getPointer(Env* env, Class* c, jlong address) {
    return PTR_TO_LONG(*((void**) LONG_TO_PTR(address)));
}
Exemple #22
0
void Java_aura_rt_VM_setShort(Env* env, Class* c, jlong address, jshort value) {
    *((jshort*) LONG_TO_PTR(address)) = value;
}
Exemple #23
0
void Java_aura_rt_VM_setByte(Env* env, Class* c, jlong address, jbyte value) {
    *((jbyte*) LONG_TO_PTR(address)) = value;
}
Exemple #24
0
void Java_aura_rt_VM_setInt(Env* env, Class* c, jlong address, jint value) {
    *((jint*) LONG_TO_PTR(address)) = value;
}
Exemple #25
0
void Java_aura_rt_VM_setChar(Env* env, Class* c, jlong address, jchar value) {
    *((jchar*) LONG_TO_PTR(address)) = value;
}
Exemple #26
0
void Java_aura_rt_VM_setLong(Env* env, Class* c, jlong address, jlong value) {
    *((jlong*) LONG_TO_PTR(address)) = value;
}
Exemple #27
0
void Java_aura_rt_VM_setFloat(Env* env, Class* c, jlong address, jfloat value) {
    *((jfloat*) LONG_TO_PTR(address)) = value;
}
Exemple #28
0
void Java_aura_rt_VM_setDouble(Env* env, Class* c, jlong address, jdouble value) {
    *((jdouble*) LONG_TO_PTR(address)) = value;
}
Exemple #29
0
void Java_aura_rt_VM_setObject(Env* env, Class* c, jlong address, Object* value) {
    *((Object**) LONG_TO_PTR(address)) = value;
}
Exemple #30
0
jbyte Java_aura_rt_VM_getByte(Env* env, Class* c, jlong address) {
    return *((jbyte*) LONG_TO_PTR(address));
}