harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r474477 - in /incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti: jvmti_heap.cpp jvmti_heap.h jvmti_roots.cpp jvmti_trace.cpp
Date Mon, 13 Nov 2006 20:07:24 GMT
Author: gshimansky
Date: Mon Nov 13 12:07:23 2006
New Revision: 474477

URL: http://svn.apache.org/viewvc?view=rev&rev=474477
Log:
Applied HARMONY-2177 [drlvm][jvmti] Proper handling of NULL callbacks

Tests passed on winxp and ubuntu


Modified:
    incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_heap.cpp
    incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_heap.h
    incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_roots.cpp
    incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_trace.cpp

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_heap.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_heap.cpp?view=diff&rev=474477&r1=474476&r2=474477
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_heap.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_heap.cpp Mon Nov 13 12:07:23
2006
@@ -76,7 +76,7 @@
 
     if (!ti_env->posessed_capabilities.can_tag_objects)
         return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
-    if (NULL == tag_ptr)
+    if (!tag_ptr)
         return JVMTI_ERROR_NULL_POINTER;
     if (!is_jobject_valid(object))
         return JVMTI_ERROR_INVALID_OBJECT;
@@ -254,6 +254,8 @@
 
     if (!ti_env->posessed_capabilities.can_tag_objects)
         return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
+    if (!object_ref_callback)
+        return JVMTI_ERROR_NULL_POINTER;
     if (!is_jobject_valid(object))
         return JVMTI_ERROR_INVALID_OBJECT;
 
@@ -291,11 +293,12 @@
 static void ti_iterate_reachable(TIEnv* ti_env, 
         hythread_iterator_t iterator)
 {
-    // enumerate roots and the trace the heap
+    // enumerate roots
     ti_enumerate_roots(ti_env, iterator);
 
     // check if we don't need to trace heap
-    if (ti_env->iteration_state->abort) return;
+    if (ti_env->iteration_state->abort
+            || ti_env->iteration_state->object_ref_callback == NULL) return;
 
     ti_trace_heap(ti_env);
 }
@@ -440,6 +443,13 @@
             && object_filter != JVMTI_HEAP_OBJECT_EITHER)
         return JVMTI_ERROR_ILLEGAL_ARGUMENT;
 
+    // According to JVMTI specification, if callback is NULL,
+    // we must not process untagged objects.
+    // Since the iteration is visible to user only through callback,
+    // doing nothing will satisfy specification.
+    if (!heap_object_callback)
+        return JVMTI_ERROR_NONE;
+
     // heap iteration requires stop-the-world
     hythread_global_lock();
 
@@ -512,10 +522,19 @@
 
     if (!ti_env->posessed_capabilities.can_tag_objects)
         return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
+    if (!is_jclass_valid(klass))
+        return JVMTI_ERROR_INVALID_CLASS;
     if (object_filter != JVMTI_HEAP_OBJECT_TAGGED
             && object_filter != JVMTI_HEAP_OBJECT_UNTAGGED
             && object_filter != JVMTI_HEAP_OBJECT_EITHER)
         return JVMTI_ERROR_ILLEGAL_ARGUMENT;
+
+    // According to JVMTI specification, if callback is NULL,
+    // we must not process untagged objects.
+    // Since the iteration is visible to user only through callback,
+    // doing nothing will satisfy specification.
+    if (!heap_object_callback)
+        return JVMTI_ERROR_NONE;
 
     // heap iteration requires stop-the-world
     TRACE2("ti.iterate", "acquire tm lock");

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_heap.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_heap.h?view=diff&rev=474477&r1=474476&r2=474477
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_heap.h (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_heap.h Mon Nov 13 12:07:23
2006
@@ -131,4 +131,21 @@
     return r;
 }
 
+/**
+ * returns true if the jclass looks like a valid java.lang.Class instance.
+ */
+inline bool is_jclass_valid(jclass jobj)
+{
+    if (jobj == NULL) return false;
+    hythread_suspend_disable();
+    bool r = false;
+    if (is_object_valid(jobj->object)) {
+        Class* cls = ((ManagedObject*)jobj->object)->vt()->clss;
+        r = class_is_instanceof(cls,
+            VM_Global_State::loader_env->JavaLangClass_Class);
+    }
+    hythread_suspend_enable();
+    return r;
+}
+
 #endif // _JVMTI_HEAP_H_

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_roots.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_roots.cpp?view=diff&rev=474477&r1=474476&r2=474477
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_roots.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_roots.cpp Mon Nov 13
12:07:23 2006
@@ -81,21 +81,20 @@
         return;
     }
 
-    tag_pair **tp = ti_get_object_tptr(obj);
-    jlong tag = (*tp != NULL ? (*tp)->tag : 0);
-    jlong class_tag = ti_get_object_class_tag(ti_env, obj);
-    jlong size = ti_get_object_size(ti_env, obj);
-
-    void* user_data = state->user_data;
-
-    jvmtiIterationControl r;
-
-    jlong thread_tag = state->thread_tag;
-
-    r = state->stack_ref_callback(root_kind, class_tag, size, &tag,
-            thread_tag, depth, method, slot, user_data);
-
-    ti_env->tags->update(obj, tag, tp);
+    jvmtiIterationControl r = JVMTI_ITERATION_CONTINUE;
+    if (state->stack_ref_callback) {
+        tag_pair **tp = ti_get_object_tptr(obj);
+        jlong tag = (*tp != NULL ? (*tp)->tag : 0);
+        jlong class_tag = ti_get_object_class_tag(ti_env, obj);
+        jlong size = ti_get_object_size(ti_env, obj);
+
+        void* user_data = state->user_data;
+        jlong thread_tag = state->thread_tag;
+
+        r = state->stack_ref_callback(root_kind, class_tag, size, &tag,
+                thread_tag, depth, method, slot, user_data);
+        ti_env->tags->update(obj, tag, tp);
+    }
 
     if (JVMTI_ITERATION_ABORT == r) {
         state->abort = true;
@@ -131,19 +130,18 @@
         return;
     }
 
-    tag_pair** tp = ti_get_object_tptr(obj);
-    jlong tag = ((*tp) != NULL ? (*tp)->tag : 0);
-
-    jlong class_tag = ti_get_object_class_tag(ti_env, obj);
-    jlong size = ti_get_object_size(ti_env, obj);
-
-    void* user_data = state->user_data;
+    jvmtiIterationControl r = JVMTI_ITERATION_CONTINUE;
+    if (state->heap_root_callback) {
+        tag_pair** tp = ti_get_object_tptr(obj);
+        jlong tag = ((*tp) != NULL ? (*tp)->tag : 0);
+        jlong class_tag = ti_get_object_class_tag(ti_env, obj);
+        jlong size = ti_get_object_size(ti_env, obj);
 
-    jvmtiIterationControl r;
+        void* user_data = state->user_data;
 
-    r = state->heap_root_callback(root_kind, class_tag, size, &tag, user_data);
-
-    ti_env->tags->update(obj, tag, tp);
+        r = state->heap_root_callback(root_kind, class_tag, size, &tag, user_data);
+        ti_env->tags->update(obj, tag, tp);
+    }
 
     if (JVMTI_ITERATION_ABORT == r) {
         state->abort = true;

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_trace.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_trace.cpp?view=diff&rev=474477&r1=474476&r2=474477
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_trace.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_trace.cpp Mon Nov 13
12:07:23 2006
@@ -54,8 +54,8 @@
 
     void *user_data = state->user_data;
 
-    jvmtiIterationControl r;
-    r = state->object_ref_callback(reference_kind,
+    assert(state->object_ref_callback);
+    jvmtiIterationControl r = state->object_ref_callback(reference_kind,
             class_tag, size, &tag, referrer_tag,
             referrer_index, user_data);
 



Mime
View raw message