Thu, 13 Jun 2013 15:39:47 -0400
8010124: JVM_GetClassContext: use GrowableArray instead of KlassLink
Summary: replace linked data structure with array (performance)
Reviewed-by: kvn
Contributed-by: christian.thalinger@oracle.com, david.r.chase@oracle.com
src/share/vm/prims/jvm.cpp | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/vm/prims/jvm.cpp Tue Jun 11 16:40:31 2013 -0700 1.2 +++ b/src/share/vm/prims/jvm.cpp Thu Jun 13 15:39:47 2013 -0400 1.3 @@ -3230,24 +3230,10 @@ 1.4 JVM_END 1.5 1.6 1.7 -// Utility object for collecting method holders walking down the stack 1.8 -class KlassLink: public ResourceObj { 1.9 - public: 1.10 - KlassHandle klass; 1.11 - KlassLink* next; 1.12 - 1.13 - KlassLink(KlassHandle k) { klass = k; next = NULL; } 1.14 -}; 1.15 - 1.16 - 1.17 JVM_ENTRY(jobjectArray, JVM_GetClassContext(JNIEnv *env)) 1.18 JVMWrapper("JVM_GetClassContext"); 1.19 ResourceMark rm(THREAD); 1.20 JvmtiVMObjectAllocEventCollector oam; 1.21 - // Collect linked list of (handles to) method holders 1.22 - KlassLink* first = NULL; 1.23 - KlassLink* last = NULL; 1.24 - int depth = 0; 1.25 vframeStream vfst(thread); 1.26 1.27 if (SystemDictionary::reflect_CallerSensitive_klass() != NULL) { 1.28 @@ -3261,32 +3247,23 @@ 1.29 } 1.30 1.31 // Collect method holders 1.32 + GrowableArray<KlassHandle>* klass_array = new GrowableArray<KlassHandle>(); 1.33 for (; !vfst.at_end(); vfst.security_next()) { 1.34 Method* m = vfst.method(); 1.35 // Native frames are not returned 1.36 if (!m->is_ignored_by_security_stack_walk() && !m->is_native()) { 1.37 Klass* holder = m->method_holder(); 1.38 assert(holder->is_klass(), "just checking"); 1.39 - depth++; 1.40 - KlassLink* l = new KlassLink(KlassHandle(thread, holder)); 1.41 - if (first == NULL) { 1.42 - first = last = l; 1.43 - } else { 1.44 - last->next = l; 1.45 - last = l; 1.46 - } 1.47 + klass_array->append(holder); 1.48 } 1.49 } 1.50 1.51 // Create result array of type [Ljava/lang/Class; 1.52 - objArrayOop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), depth, CHECK_NULL); 1.53 + objArrayOop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), klass_array->length(), CHECK_NULL); 1.54 // Fill in mirrors corresponding to method holders 1.55 - int index = 0; 1.56 - while (first != NULL) { 1.57 - result->obj_at_put(index++, first->klass()->java_mirror()); 1.58 - first = first->next; 1.59 + for (int i = 0; i < klass_array->length(); i++) { 1.60 + result->obj_at_put(i, klass_array->at(i)->java_mirror()); 1.61 } 1.62 - assert(index == depth, "just checking"); 1.63 1.64 return (jobjectArray) JNIHandles::make_local(env, result); 1.65 JVM_END