Mercurial > hg > graal-jvmci-8
comparison src/share/vm/prims/jvm.cpp @ 11001:c52abc8a0b08
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
author | drchase |
---|---|
date | Thu, 13 Jun 2013 15:39:47 -0400 |
parents | 6bd680e9ea35 |
children | ac91879aa56f |
comparison
equal
deleted
inserted
replaced
11000:bc8956037049 | 11001:c52abc8a0b08 |
---|---|
3228 } | 3228 } |
3229 return NULL; | 3229 return NULL; |
3230 JVM_END | 3230 JVM_END |
3231 | 3231 |
3232 | 3232 |
3233 // Utility object for collecting method holders walking down the stack | |
3234 class KlassLink: public ResourceObj { | |
3235 public: | |
3236 KlassHandle klass; | |
3237 KlassLink* next; | |
3238 | |
3239 KlassLink(KlassHandle k) { klass = k; next = NULL; } | |
3240 }; | |
3241 | |
3242 | |
3243 JVM_ENTRY(jobjectArray, JVM_GetClassContext(JNIEnv *env)) | 3233 JVM_ENTRY(jobjectArray, JVM_GetClassContext(JNIEnv *env)) |
3244 JVMWrapper("JVM_GetClassContext"); | 3234 JVMWrapper("JVM_GetClassContext"); |
3245 ResourceMark rm(THREAD); | 3235 ResourceMark rm(THREAD); |
3246 JvmtiVMObjectAllocEventCollector oam; | 3236 JvmtiVMObjectAllocEventCollector oam; |
3247 // Collect linked list of (handles to) method holders | |
3248 KlassLink* first = NULL; | |
3249 KlassLink* last = NULL; | |
3250 int depth = 0; | |
3251 vframeStream vfst(thread); | 3237 vframeStream vfst(thread); |
3252 | 3238 |
3253 if (SystemDictionary::reflect_CallerSensitive_klass() != NULL) { | 3239 if (SystemDictionary::reflect_CallerSensitive_klass() != NULL) { |
3254 // This must only be called from SecurityManager.getClassContext | 3240 // This must only be called from SecurityManager.getClassContext |
3255 Method* m = vfst.method(); | 3241 Method* m = vfst.method(); |
3259 THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVM_GetClassContext must only be called from SecurityManager.getClassContext"); | 3245 THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVM_GetClassContext must only be called from SecurityManager.getClassContext"); |
3260 } | 3246 } |
3261 } | 3247 } |
3262 | 3248 |
3263 // Collect method holders | 3249 // Collect method holders |
3250 GrowableArray<KlassHandle>* klass_array = new GrowableArray<KlassHandle>(); | |
3264 for (; !vfst.at_end(); vfst.security_next()) { | 3251 for (; !vfst.at_end(); vfst.security_next()) { |
3265 Method* m = vfst.method(); | 3252 Method* m = vfst.method(); |
3266 // Native frames are not returned | 3253 // Native frames are not returned |
3267 if (!m->is_ignored_by_security_stack_walk() && !m->is_native()) { | 3254 if (!m->is_ignored_by_security_stack_walk() && !m->is_native()) { |
3268 Klass* holder = m->method_holder(); | 3255 Klass* holder = m->method_holder(); |
3269 assert(holder->is_klass(), "just checking"); | 3256 assert(holder->is_klass(), "just checking"); |
3270 depth++; | 3257 klass_array->append(holder); |
3271 KlassLink* l = new KlassLink(KlassHandle(thread, holder)); | |
3272 if (first == NULL) { | |
3273 first = last = l; | |
3274 } else { | |
3275 last->next = l; | |
3276 last = l; | |
3277 } | |
3278 } | 3258 } |
3279 } | 3259 } |
3280 | 3260 |
3281 // Create result array of type [Ljava/lang/Class; | 3261 // Create result array of type [Ljava/lang/Class; |
3282 objArrayOop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), depth, CHECK_NULL); | 3262 objArrayOop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), klass_array->length(), CHECK_NULL); |
3283 // Fill in mirrors corresponding to method holders | 3263 // Fill in mirrors corresponding to method holders |
3284 int index = 0; | 3264 for (int i = 0; i < klass_array->length(); i++) { |
3285 while (first != NULL) { | 3265 result->obj_at_put(i, klass_array->at(i)->java_mirror()); |
3286 result->obj_at_put(index++, first->klass()->java_mirror()); | 3266 } |
3287 first = first->next; | |
3288 } | |
3289 assert(index == depth, "just checking"); | |
3290 | 3267 |
3291 return (jobjectArray) JNIHandles::make_local(env, result); | 3268 return (jobjectArray) JNIHandles::make_local(env, result); |
3292 JVM_END | 3269 JVM_END |
3293 | 3270 |
3294 | 3271 |