comparison src/share/vm/graal/graalEnv.cpp @ 3653:6aef50c6d967

Handlize to fix GC issue.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Thu, 17 Nov 2011 00:01:56 +0100
parents 0e8a2a629afb
children 4123781869da
comparison
equal deleted inserted replaced
3652:aac12c75f805 3653:6aef50c6d967
295 // ------------------------------------------------------------------ 295 // ------------------------------------------------------------------
296 // ciEnv::lookup_method 296 // ciEnv::lookup_method
297 // 297 //
298 // Perform an appropriate method lookup based on accessor, holder, 298 // Perform an appropriate method lookup based on accessor, holder,
299 // name, signature, and bytecode. 299 // name, signature, and bytecode.
300 methodOop GraalEnv::lookup_method(instanceKlass* accessor, 300 methodHandle GraalEnv::lookup_method(instanceKlassHandle h_accessor,
301 instanceKlass* holder, 301 instanceKlassHandle h_holder,
302 Symbol* name, 302 Symbol* name,
303 Symbol* sig, 303 Symbol* sig,
304 Bytecodes::Code bc) { 304 Bytecodes::Code bc) {
305 EXCEPTION_CONTEXT; 305 EXCEPTION_CONTEXT;
306 KlassHandle h_accessor(THREAD, accessor);
307 KlassHandle h_holder(THREAD, holder);
308 LinkResolver::check_klass_accessability(h_accessor, h_holder, KILL_COMPILE_ON_FATAL_(NULL)); 306 LinkResolver::check_klass_accessability(h_accessor, h_holder, KILL_COMPILE_ON_FATAL_(NULL));
309 methodHandle dest_method; 307 methodHandle dest_method;
310 switch (bc) { 308 switch (bc) {
311 case Bytecodes::_invokestatic: 309 case Bytecodes::_invokestatic:
312 dest_method = 310 dest_method =
327 h_accessor, true); 325 h_accessor, true);
328 break; 326 break;
329 default: ShouldNotReachHere(); 327 default: ShouldNotReachHere();
330 } 328 }
331 329
332 return dest_method(); 330 return dest_method;
333 } 331 }
334 332
335 333
336 // ------------------------------------------------------------------ 334 // ------------------------------------------------------------------
337 // ciEnv::get_method_by_index_impl 335 // ciEnv::get_method_by_index_impl
338 methodHandle GraalEnv::get_method_by_index_impl(constantPoolHandle cpool, 336 methodHandle GraalEnv::get_method_by_index_impl(constantPoolHandle cpool,
339 int index, Bytecodes::Code bc, 337 int index, Bytecodes::Code bc,
340 instanceKlass* accessor) { 338 instanceKlassHandle accessor) {
341 int holder_index = cpool->klass_ref_index_at(index); 339 int holder_index = cpool->klass_ref_index_at(index);
342 bool holder_is_accessible; 340 bool holder_is_accessible;
343 KlassHandle holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, KlassHandle(Thread::current(), accessor)); 341 KlassHandle holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, accessor);
344 342
345 // Get the method's name and signature. 343 // Get the method's name and signature.
346 Symbol* name_sym = cpool->name_ref_at(index); 344 Symbol* name_sym = cpool->name_ref_at(index);
347 Symbol* sig_sym = cpool->signature_ref_at(index); 345 Symbol* sig_sym = cpool->signature_ref_at(index);
348 346
349 if (holder_is_accessible) { // Our declared holder is loaded. 347 if (holder_is_accessible) { // Our declared holder is loaded.
350 instanceKlass* lookup = get_instance_klass_for_declared_method_holder(holder); 348 instanceKlassHandle lookup = get_instance_klass_for_declared_method_holder(holder);
351 methodOop m = lookup_method(accessor, lookup, name_sym, sig_sym, bc); 349 methodHandle m = lookup_method(accessor, lookup, name_sym, sig_sym, bc);
352 if (m != NULL && 350 if (!m.is_null() &&
353 (bc == Bytecodes::_invokestatic 351 (bc == Bytecodes::_invokestatic
354 ? instanceKlass::cast(m->method_holder())->is_not_initialized() 352 ? instanceKlass::cast(m->method_holder())->is_not_initialized()
355 : !instanceKlass::cast(m->method_holder())->is_loaded())) { 353 : !instanceKlass::cast(m->method_holder())->is_loaded())) {
356 m = NULL; 354 m = NULL;
357 } 355 }
358 if (m != NULL) { 356 if (!m.is_null()) {
359 // We found the method. 357 // We found the method.
360 return m; 358 return m;
361 } 359 }
362 } 360 }
363 361
368 return NULL; 366 return NULL;
369 } 367 }
370 368
371 // ------------------------------------------------------------------ 369 // ------------------------------------------------------------------
372 // ciEnv::get_instance_klass_for_declared_method_holder 370 // ciEnv::get_instance_klass_for_declared_method_holder
373 instanceKlass* GraalEnv::get_instance_klass_for_declared_method_holder(KlassHandle method_holder) { 371 instanceKlassHandle GraalEnv::get_instance_klass_for_declared_method_holder(KlassHandle method_holder) {
374 // For the case of <array>.clone(), the method holder can be a ciArrayKlass 372 // For the case of <array>.clone(), the method holder can be a ciArrayKlass
375 // instead of a ciInstanceKlass. For that case simply pretend that the 373 // instead of a ciInstanceKlass. For that case simply pretend that the
376 // declared holder is Object.clone since that's where the call will bottom out. 374 // declared holder is Object.clone since that's where the call will bottom out.
377 // A more correct fix would trickle out through many interfaces in CI, 375 // A more correct fix would trickle out through many interfaces in CI,
378 // requiring ciInstanceKlass* to become ciKlass* and many more places would 376 // requiring ciInstanceKlass* to become ciKlass* and many more places would
379 // require checks to make sure the expected type was found. Given that this 377 // require checks to make sure the expected type was found. Given that this
380 // only occurs for clone() the more extensive fix seems like overkill so 378 // only occurs for clone() the more extensive fix seems like overkill so
381 // instead we simply smear the array type into Object. 379 // instead we simply smear the array type into Object.
382 if (method_holder->oop_is_instance()) { 380 if (method_holder->oop_is_instance()) {
383 return instanceKlass::cast(method_holder()); 381 return instanceKlassHandle(method_holder());
384 } else if (method_holder->oop_is_array()) { 382 } else if (method_holder->oop_is_array()) {
385 return instanceKlass::cast(SystemDictionary::Object_klass()); 383 return instanceKlassHandle(SystemDictionary::Object_klass());
386 } else { 384 } else {
387 ShouldNotReachHere(); 385 ShouldNotReachHere();
388 } 386 }
389 return NULL; 387 return NULL;
390 } 388 }
392 390
393 // ------------------------------------------------------------------ 391 // ------------------------------------------------------------------
394 // ciEnv::get_method_by_index 392 // ciEnv::get_method_by_index
395 methodHandle GraalEnv::get_method_by_index(constantPoolHandle cpool, 393 methodHandle GraalEnv::get_method_by_index(constantPoolHandle cpool,
396 int index, Bytecodes::Code bc, 394 int index, Bytecodes::Code bc,
397 instanceKlass* accessor) { 395 instanceKlassHandle accessor) {
398 ResourceMark rm; 396 ResourceMark rm;
399 assert(bc != Bytecodes::_invokedynamic, "invokedynamic not yet supported"); 397 assert(bc != Bytecodes::_invokedynamic, "invokedynamic not yet supported");
400 return get_method_by_index_impl(cpool, index, bc, accessor); 398 return get_method_by_index_impl(cpool, index, bc, accessor);
401 } 399 }
402 400