diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/jni_internal.cc | 30 | ||||
| -rw-r--r-- | src/object.h | 6 |
2 files changed, 32 insertions, 4 deletions
diff --git a/src/jni_internal.cc b/src/jni_internal.cc index 87decd7116..9a2492e7e5 100644 --- a/src/jni_internal.cc +++ b/src/jni_internal.cc @@ -390,8 +390,28 @@ jboolean IsInstanceOf(JNIEnv* env, jobject obj, jclass clazz) { jmethodID GetMethodID(JNIEnv* env, jclass clazz, const char* name, const char* sig) { ScopedJniThreadState ts(env); - UNIMPLEMENTED(FATAL); - return NULL; + // TODO: retrieve handle value for class + Class* klass = reinterpret_cast<Class*>(clazz); + if (!klass->IsInitialized()) { + // TODO: initialize the class + } + Method* method = klass->FindVirtualMethod(name, sig); + if (method == NULL) { + // No virtual method matching the signature. Search declared + // private methods and constructors. + method = klass->FindDeclaredDirectMethod(name, sig); + } + if (method == NULL || method->IsStatic()) { + LG << "NoSuchMethodError"; // TODO: throw NoSuchMethodError + return NULL; + } + // TODO: create a JNI weak global reference for method + bool success = EnsureInvokeStub(method); + if (!success) { + // TODO: throw OutOfMemoryException + return NULL; + } + return reinterpret_cast<jmethodID>(method); } jobject CallObjectMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) { @@ -909,10 +929,12 @@ jmethodID GetStaticMethodID(JNIEnv* env, ScopedJniThreadState ts(env); // TODO: DecodeReference Class* klass = reinterpret_cast<Class*>(clazz); - // TODO: check that klass is initialized + if (!klass->IsInitialized()) { + // TODO: initialize the class + } Method* method = klass->FindDirectMethod(name, sig); if (method == NULL || !method->IsStatic()) { - // TODO: throw NoSuchMethodError + LG << "NoSuchMethodError"; // TODO: throw NoSuchMethodError return NULL; } // TODO: create a JNI weak global reference for method diff --git a/src/object.h b/src/object.h index 4f32cf9cf8..abcf51f64b 100644 --- a/src/object.h +++ b/src/object.h @@ -868,10 +868,16 @@ class Class : public Object { return GetStatus() >= kStatusResolved; } + // Returns true if the class has been loaded. bool IsLoaded() const { return GetStatus() >= kStatusLoaded; } + // Returns true if the class is initialized. + bool IsInitialized() const { + return GetStatus() == kStatusInitialized; + } + // Returns true if this class is in the same packages as that class. bool IsInSamePackage(const Class* that) const; |