* src/vm/javaobjects.hpp (java_lang_Object): Added get_hashcode getter.
authorMichael Starzinger <michi@complang.tuwien.ac.at>
Wed, 20 Aug 2008 14:05:58 +0000 (16:05 +0200)
committerMichael Starzinger <michi@complang.tuwien.ac.at>
Wed, 20 Aug 2008 14:05:58 +0000 (16:05 +0200)
* src/native/vm/cldc1.1/java_lang_Object.cpp: Use above getter function.
* src/native/vm/gnuclasspath/java_lang_VMSystem.cpp: Likewise.
* src/native/vm/openjdk/jvm.cpp: Likewise.

src/native/vm/cldc1.1/java_lang_Object.cpp
src/native/vm/gnuclasspath/java_lang_VMSystem.cpp
src/native/vm/openjdk/jvm.cpp
src/vm/javaobjects.hpp

index f302cea182cb041e7a4c3d8b7565974652040cc9..14711dcd784bfb8f3e7c359b19389730b661eb7a 100644 (file)
@@ -39,6 +39,7 @@
 #include "threads/lock-common.h"
 
 #include "vm/exceptions.hpp"
+#include "vm/javaobjects.hpp"
 
 
 // Native functions are exported as C functions.
@@ -71,11 +72,9 @@ JNIEXPORT jclass JNICALL Java_java_lang_Object_getClass(JNIEnv *env, jobject obj
  */
 JNIEXPORT jint JNICALL Java_java_lang_Object_hashCode(JNIEnv *env, jobject _this)
 {
-#if defined(ENABLE_GC_CACAO)
-       assert(0);
-#else
-       return (int32_t) ((uintptr_t) _this);
-#endif
+       java_lang_Object o(_this);
+
+       return o.get_hashcode();
 }
 
 
index 6f7cd1b0fc3797d95c6257521c8d4b8513b41d2b..3a7b67ff2e7ff041444d13065e3e99485b07b74a 100644 (file)
@@ -39,6 +39,7 @@
 #endif
 
 #include "vm/builtin.h"
+#include "vm/javaobjects.hpp"
 
 
 // Native functions are exported as C functions.
@@ -61,18 +62,10 @@ JNIEXPORT void JNICALL Java_java_lang_VMSystem_arraycopy(JNIEnv *env, jclass cla
  * Method:    identityHashCode
  * Signature: (Ljava/lang/Object;)I
  */
-JNIEXPORT jint JNICALL Java_java_lang_VMSystem_identityHashCode(JNIEnv *env, jclass clazz, jobject o)
+JNIEXPORT jint JNICALL Java_java_lang_VMSystem_identityHashCode(JNIEnv *env, jclass clazz, jobject obj)
 {
-       int32_t hashcode;
-
-       // XXX This critical section should be inside the heap function.
-       LLNI_CRITICAL_START;
-
-       hashcode = heap_hashcode(LLNI_UNWRAP((java_handle_t *) o));
-
-       LLNI_CRITICAL_END;
-
-       return hashcode;
+       java_lang_Object o(obj);
+       return o.get_hashcode();
 }
 
 } // extern "C"
index 2ba79b7c986d842351ef4ff52b4464f46fb28a22..1141307c12ade018754eec8cb7b3f76de235d15e 100644 (file)
@@ -531,7 +531,9 @@ jint JVM_IHashCode(JNIEnv* env, jobject handle)
 {
        TRACEJVMCALLS(("JVM_IHashCode(env=%p, jobject=%p)", env, handle));
 
-       return (jint) ((ptrint) handle);
+       java_lang_Object o(handle);
+
+       return o.get_hashcode();
 }
 
 
index 09bf71e26c0ef1c7096a95819894bdd9e0d9e7cb..cc7d164a7d474b317fdb4da67b8137e83b0bb76b 100644 (file)
@@ -170,9 +170,10 @@ public:
        virtual ~java_lang_Object() {}
 
        // Getters.
-       virtual inline java_handle_t* get_handle() const { return _handle; }
-       inline vftbl_t*               get_vftbl () const;
-       inline classinfo*             get_Class () const;
+       virtual inline java_handle_t* get_handle  () const { return _handle; }
+       inline vftbl_t*               get_vftbl   () const;
+       inline classinfo*             get_Class   () const;
+       inline int32_t                get_hashcode() const;
 
        inline bool is_null    () const;
        inline bool is_non_null() const;
@@ -197,6 +198,27 @@ inline classinfo* java_lang_Object::get_Class() const
        return get_vftbl()->clazz;
 }
 
+inline int32_t java_lang_Object::get_hashcode() const
+{
+#if defined(ENABLE_GC_CACAO)
+       return heap_get_hashcode(_handle);
+#else
+       java_object_t* o;
+       int32_t hashcode;
+
+       GC::critical_enter();
+
+       // XXX This should be h->get_object();
+       o = LLNI_UNWRAP(_handle);
+
+       hashcode = (int32_t)(intptr_t) o;
+
+       GC::critical_leave();
+       
+       return hashcode;
+#endif
+}
+
 
 inline bool java_lang_Object::is_null() const
 {