Fast JNI support.
Use a modifier to signal a native method is a fast JNI method. If the
modifier is set then don't perform runnable transitions.
Change-Id: I7835b4d837bfdd1cb8e2d54b919c0d5e6cf90499
diff --git a/runtime/native/dalvik_system_VMRuntime.cc b/runtime/native/dalvik_system_VMRuntime.cc
index dad6eff..9ad2585 100644
--- a/runtime/native/dalvik_system_VMRuntime.cc
+++ b/runtime/native/dalvik_system_VMRuntime.cc
@@ -28,6 +28,7 @@
#include "mirror/object.h"
#include "mirror/object-inl.h"
#include "object_utils.h"
+#include "scoped_fast_native_object_access.h"
#include "scoped_thread_state_change.h"
#include "thread.h"
#include "thread_list.h"
@@ -50,7 +51,7 @@
}
static jobject VMRuntime_newNonMovableArray(JNIEnv* env, jobject, jclass javaElementClass, jint length) {
- ScopedObjectAccess soa(env);
+ ScopedFastNativeObjectAccess soa(env);
#ifdef MOVING_GARBAGE_COLLECTOR
// TODO: right now, we don't have a copying collector, so there's no need
// to do anything special here, but we ought to pass the non-movability
@@ -81,7 +82,7 @@
if (javaArray == NULL) { // Most likely allocation failed
return 0;
}
- ScopedObjectAccess soa(env);
+ ScopedFastNativeObjectAccess soa(env);
mirror::Array* array = soa.Decode<mirror::Array*>(javaArray);
if (!array->IsArrayInstance()) {
ThrowIllegalArgumentException(NULL, "not an array");
@@ -147,21 +148,21 @@
}
static void VMRuntime_registerNativeAllocation(JNIEnv* env, jobject, jint bytes) {
- ScopedObjectAccess soa(env);
- if (bytes < 0) {
+ if (UNLIKELY(bytes < 0)) {
+ ScopedObjectAccess soa(env);
ThrowRuntimeException("allocation size negative %d", bytes);
return;
}
- Runtime::Current()->GetHeap()->RegisterNativeAllocation(bytes);
+ Runtime::Current()->GetHeap()->RegisterNativeAllocation(env, bytes);
}
static void VMRuntime_registerNativeFree(JNIEnv* env, jobject, jint bytes) {
- ScopedObjectAccess soa(env);
- if (bytes < 0) {
+ if (UNLIKELY(bytes < 0)) {
+ ScopedObjectAccess soa(env);
ThrowRuntimeException("allocation size negative %d", bytes);
return;
}
- Runtime::Current()->GetHeap()->RegisterNativeFree(bytes);
+ Runtime::Current()->GetHeap()->RegisterNativeFree(env, bytes);
}
static void VMRuntime_trimHeap(JNIEnv*, jobject) {
@@ -189,12 +190,12 @@
}
static void VMRuntime_concurrentGC(JNIEnv* env, jobject) {
- Thread* self = static_cast<JNIEnvExt*>(env)->self;
+ Thread* self = ThreadForEnv(env);
Runtime::Current()->GetHeap()->ConcurrentGC(self);
}
static JNINativeMethod gMethods[] = {
- NATIVE_METHOD(VMRuntime, addressOf, "(Ljava/lang/Object;)J"),
+ NATIVE_METHOD(VMRuntime, addressOf, "!(Ljava/lang/Object;)J"),
NATIVE_METHOD(VMRuntime, bootClassPath, "()Ljava/lang/String;"),
NATIVE_METHOD(VMRuntime, classPath, "()Ljava/lang/String;"),
NATIVE_METHOD(VMRuntime, clearGrowthLimit, "()V"),
@@ -203,7 +204,7 @@
NATIVE_METHOD(VMRuntime, getTargetHeapUtilization, "()F"),
NATIVE_METHOD(VMRuntime, isDebuggerActive, "()Z"),
NATIVE_METHOD(VMRuntime, nativeSetTargetHeapUtilization, "(F)V"),
- NATIVE_METHOD(VMRuntime, newNonMovableArray, "(Ljava/lang/Class;I)Ljava/lang/Object;"),
+ NATIVE_METHOD(VMRuntime, newNonMovableArray, "!(Ljava/lang/Class;I)Ljava/lang/Object;"),
NATIVE_METHOD(VMRuntime, properties, "()[Ljava/lang/String;"),
NATIVE_METHOD(VMRuntime, setTargetSdkVersion, "(I)V"),
NATIVE_METHOD(VMRuntime, registerNativeAllocation, "(I)V"),