summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Wilson <jessewilson@google.com>2011-09-29 13:12:33 -0400
committerJesse Wilson <jessewilson@google.com>2011-09-29 13:42:49 -0400
commit6bf1915f20a11748d8d4b78ad020172bb2e6c946 (patch)
tree6cc01188a48bdb2ac247b4338001dcf57d7a85fb
parent5371b18d8ff3cd31895255374f575650df4839f0 (diff)
downloadart-6bf1915f20a11748d8d4b78ad020172bb2e6c946.zip
art-6bf1915f20a11748d8d4b78ad020172bb2e6c946.tar.gz
art-6bf1915f20a11748d8d4b78ad020172bb2e6c946.tar.bz2
Revert "Reverts to track dalvik and libcore"
This reverts commit 53d6ff445706c390c541d10ef11f1b2f19ab14e8. Change-Id: I7cfff5b532b0dd6ffef010732cd248f58236421b
-rw-r--r--src/class_linker_test.cc1
-rw-r--r--src/dex_file.cc39
-rw-r--r--src/dex_file.h12
-rw-r--r--src/java_lang_Class.cc25
-rw-r--r--src/object.h7
5 files changed, 66 insertions, 18 deletions
diff --git a/src/class_linker_test.cc b/src/class_linker_test.cc
index ba67402..c23087d 100644
--- a/src/class_linker_test.cc
+++ b/src/class_linker_test.cc
@@ -641,7 +641,6 @@ struct MethodClassOffsets : public CheckOffsets<MethodClass> {
class_descriptor = "Ljava/lang/reflect/Method;";
// alphabetical references
- offsets.push_back(CheckOffset(OFFSETOF_MEMBER(MethodClass, NO_ANNOTATIONS_), "NO_ANNOTATIONS"));
offsets.push_back(CheckOffset(OFFSETOF_MEMBER(MethodClass, ORDER_BY_SIGNATURE_), "ORDER_BY_SIGNATURE"));
};
};
diff --git a/src/dex_file.cc b/src/dex_file.cc
index 519cdc2..c532134 100644
--- a/src/dex_file.cc
+++ b/src/dex_file.cc
@@ -384,7 +384,44 @@ const DexFile* DexFile::Open(const byte* dex_bytes, size_t length,
}
}
-DexFile::~DexFile() {}
+DexFile::~DexFile() {
+ if (dex_object_ != NULL) {
+ UNIMPLEMENTED(WARNING) << "leaked a global reference to an com.android.dex.Dex instance";
+ }
+}
+
+jobject DexFile::GetDexObject(JNIEnv* env) const {
+ MutexLock mu(dex_object_lock_);
+ if (dex_object_ != NULL) {
+ return dex_object_;
+ }
+
+ void* address = const_cast<void*>(reinterpret_cast<const void*>(base_));
+ jobject byte_buffer = env->NewDirectByteBuffer(address, length_);
+ if (byte_buffer == NULL) {
+ return NULL;
+ }
+
+ jclass c = env->FindClass("com/android/dex/Dex");
+ if (c == NULL) {
+ return NULL;
+ }
+
+ jmethodID mid = env->GetStaticMethodID(c, "create", "(Ljava/nio/ByteBuffer;)Lcom/android/dex/Dex;");
+ if (mid == NULL) {
+ return NULL;
+ }
+
+ jvalue args[1];
+ args[0].l = byte_buffer;
+ jobject local = env->CallStaticObjectMethodA(c, mid, args);
+ if (local == NULL) {
+ return NULL;
+ }
+
+ dex_object_ = env->NewGlobalRef(local);
+ return dex_object_;
+}
bool DexFile::Init() {
InitMembers();
diff --git a/src/dex_file.h b/src/dex_file.h
index 359825a..4ad701f 100644
--- a/src/dex_file.h
+++ b/src/dex_file.h
@@ -9,8 +9,10 @@
#include "UniquePtr.h"
#include "globals.h"
+#include "jni.h"
#include "leb128.h"
#include "logging.h"
+#include "mutex.h"
#include "stringpiece.h"
#include "strutil.h"
#include "utils.h"
@@ -348,6 +350,10 @@ class DexFile {
return location_;
}
+ // Returns a com.android.dex.Dex object corresponding to the mapped-in dex file.
+ // Used by managed code to implement annotations.
+ jobject GetDexObject(JNIEnv* env) const;
+
const Header& GetHeader() const {
CHECK(header_ != NULL);
return *header_;
@@ -874,6 +880,8 @@ class DexFile {
length_(length),
location_(location),
closer_(closer),
+ dex_object_lock_("a dex_object_lock_"),
+ dex_object_(NULL),
header_(0),
string_ids_(0),
type_ids_(0),
@@ -920,6 +928,10 @@ class DexFile {
// Helper object to free the underlying allocation.
UniquePtr<Closer> closer_;
+ // A cached com.android.dex.Dex instance, possibly NULL. Use GetDexObject.
+ mutable Mutex dex_object_lock_;
+ mutable jobject dex_object_;
+
// Points to the header section.
const Header* header_;
diff --git a/src/java_lang_Class.cc b/src/java_lang_Class.cc
index 68b83f2..de5315a 100644
--- a/src/java_lang_Class.cc
+++ b/src/java_lang_Class.cc
@@ -168,6 +168,17 @@ jboolean Class_desiredAssertionStatus(JNIEnv* env, jobject javaThis) {
return JNI_FALSE;
}
+jobject Class_getDex(JNIEnv* env, jobject javaClass) {
+ Class* c = Decode<Class*>(env, javaClass);
+
+ DexCache* dex_cache = c->GetDexCache();
+ if (dex_cache == NULL) {
+ return NULL;
+ }
+
+ return Runtime::Current()->GetClassLinker()->FindDexFile(dex_cache).GetDexObject(env);
+}
+
jobject Class_getClassLoader(JNIEnv* env, jclass, jobject javaClass) {
Class* c = Decode<Class*>(env, javaClass);
Object* result = reinterpret_cast<Object*>(const_cast<ClassLoader*>(c->GetClassLoader()));
@@ -248,16 +259,6 @@ jclass Class_getDeclaringClass(JNIEnv* env, jobject javaThis) {
return NULL;
}
-jobject Class_getEnclosingConstructor(JNIEnv* env, jobject javaThis) {
- UNIMPLEMENTED(WARNING) << "needs annotations";
- return NULL;
-}
-
-jobject Class_getEnclosingMethod(JNIEnv* env, jobject javaThis) {
- UNIMPLEMENTED(WARNING) << "needs annotations";
- return NULL;
-}
-
/*
* private native String getNameNative()
*
@@ -441,9 +442,7 @@ static JNINativeMethod gMethods[] = {
NATIVE_METHOD(Class, getDeclaredFields, "(Ljava/lang/Class;Z)[Ljava/lang/reflect/Field;"),
NATIVE_METHOD(Class, getDeclaredMethods, "(Ljava/lang/Class;Z)[Ljava/lang/reflect/Method;"),
NATIVE_METHOD(Class, getDeclaringClass, "()Ljava/lang/Class;"),
- //NATIVE_METHOD(Class, getEnclosingClass, "()Ljava/lang/Class;"),
- NATIVE_METHOD(Class, getEnclosingConstructor, "()Ljava/lang/reflect/Constructor;"),
- NATIVE_METHOD(Class, getEnclosingMethod, "()Ljava/lang/reflect/Method;"),
+ NATIVE_METHOD(Class, getDex, "()Lcom/android/dex/Dex;"),
//NATIVE_METHOD(Class, getInnerClassName, "()Ljava/lang/String;"),
//NATIVE_METHOD(Class, getModifiers, "(Ljava/lang/Class;Z)I"),
NATIVE_METHOD(Class, getNameNative, "()Ljava/lang/String;"),
diff --git a/src/object.h b/src/object.h
index 9b1d3c7..1eee2b8 100644
--- a/src/object.h
+++ b/src/object.h
@@ -569,7 +569,7 @@ class MANAGED Field : public AccessibleObject {
DISALLOW_IMPLICIT_CONSTRUCTORS(Field);
};
-// C++ mirror of java.lang.reflect.Method
+// C++ mirror of java.lang.reflect.Method and java.lang.reflect.Constructor
class MANAGED Method : public AccessibleObject {
public:
// An function that invokes a method with an array of its arguments.
@@ -2032,7 +2032,8 @@ class MANAGED Class : public StaticStorageBase {
// access flags; low 16 bits are defined by VM spec
uint32_t access_flags_;
- // Total class size; used when allocating storage on gc heap.
+ // Total size of the Class instance; used when allocating storage on gc heap.
+ // See also object_size_.
size_t class_size_;
// tid used to check for recursive <clinit> invocation
@@ -2046,6 +2047,7 @@ class MANAGED Class : public StaticStorageBase {
// Total object size; used when allocating storage on gc heap.
// (For interfaces and abstract classes this will be zero.)
+ // See also class_size_.
size_t object_size_;
// primitive type index, or kPrimNot (0); set for generated prim classes
@@ -2317,7 +2319,6 @@ class MANAGED FieldClass : public Class {
class MANAGED MethodClass : public Class {
private:
- ObjectArray<Object>* NO_ANNOTATIONS_;
Object* ORDER_BY_SIGNATURE_;
friend struct MethodClassOffsets; // for verifying offset information
DISALLOW_IMPLICIT_CONSTRUCTORS(MethodClass);