360 // 361 // Implementation note: in order to keep Metadata live, an auxiliary ciObject 362 // is used, which points to it's holder. 363 ciMetadata* ciObjectFactory::create_new_metadata(Metadata* o) { 364 EXCEPTION_CONTEXT; 365 366 // Hold metadata from unloading by keeping it's holder alive. 367 if (_initialized && o->is_klass()) { 368 Klass* holder = ((Klass*)o); 369 if (holder->is_instance_klass() && InstanceKlass::cast(holder)->is_anonymous()) { 370 // Though ciInstanceKlass records class loader oop, it's not enough to keep 371 // VM anonymous classes alive (loader == NULL). Klass holder should be used instead. 372 // It is enough to record a ciObject, since cached elements are never removed 373 // during ciObjectFactory lifetime. ciObjectFactory itself is created for 374 // every compilation and lives for the whole duration of the compilation. 375 ciObject* h = get(holder->klass_holder()); 376 } 377 } 378 379 if (o->is_klass()) { 380 KlassHandle h_k(THREAD, (Klass*)o); 381 Klass* k = (Klass*)o; 382 if (k->is_instance_klass()) { 383 return new (arena()) ciInstanceKlass(h_k); 384 } else if (k->is_objArray_klass()) { 385 return new (arena()) ciObjArrayKlass(h_k); 386 } else if (k->is_typeArray_klass()) { 387 return new (arena()) ciTypeArrayKlass(h_k); 388 } 389 } else if (o->is_method()) { 390 methodHandle h_m(THREAD, (Method*)o); 391 ciEnv *env = CURRENT_THREAD_ENV; 392 ciInstanceKlass* holder = env->get_instance_klass(h_m()->method_holder()); 393 return new (arena()) ciMethod(h_m, holder); 394 } else if (o->is_methodData()) { 395 // Hold methodHandle alive - might not be necessary ??? 396 methodHandle h_m(THREAD, ((MethodData*)o)->method()); 397 return new (arena()) ciMethodData((MethodData*)o); 398 } 399 400 // The Metadata* is of some type not supported by the compiler interface. 401 ShouldNotReachHere(); 402 return NULL; 403 } 404 405 // ------------------------------------------------------------------ 406 // ciObjectFactory::ensure_metadata_alive 407 // | 360 // 361 // Implementation note: in order to keep Metadata live, an auxiliary ciObject 362 // is used, which points to it's holder. 363 ciMetadata* ciObjectFactory::create_new_metadata(Metadata* o) { 364 EXCEPTION_CONTEXT; 365 366 // Hold metadata from unloading by keeping it's holder alive. 367 if (_initialized && o->is_klass()) { 368 Klass* holder = ((Klass*)o); 369 if (holder->is_instance_klass() && InstanceKlass::cast(holder)->is_anonymous()) { 370 // Though ciInstanceKlass records class loader oop, it's not enough to keep 371 // VM anonymous classes alive (loader == NULL). Klass holder should be used instead. 372 // It is enough to record a ciObject, since cached elements are never removed 373 // during ciObjectFactory lifetime. ciObjectFactory itself is created for 374 // every compilation and lives for the whole duration of the compilation. 375 ciObject* h = get(holder->klass_holder()); 376 } 377 } 378 379 if (o->is_klass()) { 380 Klass* k = (Klass*)o; 381 if (k->is_instance_klass()) { 382 return new (arena()) ciInstanceKlass(k); 383 } else if (k->is_objArray_klass()) { 384 return new (arena()) ciObjArrayKlass(k); 385 } else if (k->is_typeArray_klass()) { 386 return new (arena()) ciTypeArrayKlass(k); 387 } 388 } else if (o->is_method()) { 389 methodHandle h_m(THREAD, (Method*)o); 390 ciEnv *env = CURRENT_THREAD_ENV; 391 ciInstanceKlass* holder = env->get_instance_klass(h_m()->method_holder()); 392 return new (arena()) ciMethod(h_m, holder); 393 } else if (o->is_methodData()) { 394 // Hold methodHandle alive - might not be necessary ??? 395 methodHandle h_m(THREAD, ((MethodData*)o)->method()); 396 return new (arena()) ciMethodData((MethodData*)o); 397 } 398 399 // The Metadata* is of some type not supported by the compiler interface. 400 ShouldNotReachHere(); 401 return NULL; 402 } 403 404 // ------------------------------------------------------------------ 405 // ciObjectFactory::ensure_metadata_alive 406 // |