8190891: Clean up G1 barrier code in compiler interface (ci)

Consolidate gc barrier code in ci

Reviewed-by: eosterlund, kbarrett
This commit is contained in:
Coleen Phillimore 2017-11-13 17:29:00 -05:00
parent 002aff0a75
commit 6e6c2aa59f
6 changed files with 39 additions and 60 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -187,10 +187,6 @@ private:
} }
} }
void ensure_metadata_alive(ciMetadata* m) {
_factory->ensure_metadata_alive(m);
}
ciInstance* get_instance(oop o) { ciInstance* get_instance(oop o) {
if (o == NULL) return NULL; if (o == NULL) return NULL;
return get_object(o)->as_instance(); return get_object(o)->as_instance();

View file

@ -34,12 +34,36 @@
#include "oops/oop.inline.hpp" #include "oops/oop.inline.hpp"
#include "oops/fieldStreams.hpp" #include "oops/fieldStreams.hpp"
#include "runtime/fieldDescriptor.hpp" #include "runtime/fieldDescriptor.hpp"
#if INCLUDE_ALL_GCS
# include "gc/g1/g1SATBCardTableModRefBS.hpp"
#endif
// ciInstanceKlass // ciInstanceKlass
// //
// This class represents a Klass* in the HotSpot virtual machine // This class represents a Klass* in the HotSpot virtual machine
// whose Klass part in an InstanceKlass. // whose Klass part in an InstanceKlass.
// ------------------------------------------------------------------
// ensure_metadata_alive
//
// Ensure that the metadata wrapped by the ciMetadata is kept alive by GC.
// This is primarily useful for metadata which is considered as weak roots
// by the GC but need to be strong roots if reachable from a current compilation.
// InstanceKlass are created for both weak and strong metadata. Ensuring this metadata
// alive covers the cases where there are weak roots without performance cost.
//
static void ensure_metadata_alive(oop metadata_holder) {
#if INCLUDE_ALL_GCS
if (!UseG1GC) {
return;
}
if (metadata_holder != NULL) {
G1SATBCardTableModRefBS::enqueue(metadata_holder);
}
#endif
}
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// ciInstanceKlass::ciInstanceKlass // ciInstanceKlass::ciInstanceKlass
// //
@ -64,6 +88,18 @@ ciInstanceKlass::ciInstanceKlass(Klass* k) :
_has_injected_fields = -1; _has_injected_fields = -1;
_implementor = NULL; // we will fill these lazily _implementor = NULL; // we will fill these lazily
oop holder = ik->klass_holder();
ensure_metadata_alive(holder);
if (ik->is_anonymous()) {
// Though ciInstanceKlass records class loader oop, it's not enough to keep
// VM anonymous classes alive (loader == NULL). Klass holder should be used instead.
// It is enough to record a ciObject, since cached elements are never removed
// during ciObjectFactory lifetime. ciObjectFactory itself is created for
// every compilation and lives for the whole duration of the compilation.
assert(holder != NULL, "holder of anonymous class is the mirror which is never null");
(void)CURRENT_ENV->get_object(holder);
}
Thread *thread = Thread::current(); Thread *thread = Thread::current();
if (ciObjectFactory::is_initialized()) { if (ciObjectFactory::is_initialized()) {
_loader = JNIHandles::make_local(thread, ik->class_loader()); _loader = JNIHandles::make_local(thread, ik->class_loader());

View file

@ -188,7 +188,6 @@ void ciReceiverTypeData::translate_receiver_data_from(const ProfileData* data) {
Klass* k = data->as_ReceiverTypeData()->receiver(row); Klass* k = data->as_ReceiverTypeData()->receiver(row);
if (k != NULL) { if (k != NULL) {
ciKlass* klass = CURRENT_ENV->get_klass(k); ciKlass* klass = CURRENT_ENV->get_klass(k);
CURRENT_ENV->ensure_metadata_alive(klass);
set_receiver(row, klass); set_receiver(row, klass);
} }
} }
@ -210,7 +209,6 @@ void ciReturnTypeEntry::translate_type_data_from(const ReturnTypeEntry* ret) {
void ciSpeculativeTrapData::translate_from(const ProfileData* data) { void ciSpeculativeTrapData::translate_from(const ProfileData* data) {
Method* m = data->as_SpeculativeTrapData()->method(); Method* m = data->as_SpeculativeTrapData()->method();
ciMethod* ci_m = CURRENT_ENV->get_method(m); ciMethod* ci_m = CURRENT_ENV->get_method(m);
CURRENT_ENV->ensure_metadata_alive(ci_m);
set_method(ci_m); set_method(ci_m);
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -70,7 +70,6 @@ protected:
Klass* v = TypeEntries::valid_klass(k); Klass* v = TypeEntries::valid_klass(k);
if (v != NULL) { if (v != NULL) {
ciKlass* klass = CURRENT_ENV->get_klass(v); ciKlass* klass = CURRENT_ENV->get_klass(v);
CURRENT_ENV->ensure_metadata_alive(klass);
return with_status(klass, k); return with_status(klass, k);
} }
return with_status(NULL, k); return with_status(NULL, k);

View file

@ -47,9 +47,6 @@
#include "oops/oop.inline.hpp" #include "oops/oop.inline.hpp"
#include "runtime/fieldType.hpp" #include "runtime/fieldType.hpp"
#include "utilities/macros.hpp" #include "utilities/macros.hpp"
#if INCLUDE_ALL_GCS
# include "gc/g1/g1SATBCardTableModRefBS.hpp"
#endif
// ciObjectFactory // ciObjectFactory
// //
@ -363,19 +360,6 @@ ciObject* ciObjectFactory::create_new_object(oop o) {
ciMetadata* ciObjectFactory::create_new_metadata(Metadata* o) { ciMetadata* ciObjectFactory::create_new_metadata(Metadata* o) {
EXCEPTION_CONTEXT; EXCEPTION_CONTEXT;
// Hold metadata from unloading by keeping it's holder alive.
if (_initialized && o->is_klass()) {
Klass* holder = ((Klass*)o);
if (holder->is_instance_klass() && InstanceKlass::cast(holder)->is_anonymous()) {
// Though ciInstanceKlass records class loader oop, it's not enough to keep
// VM anonymous classes alive (loader == NULL). Klass holder should be used instead.
// It is enough to record a ciObject, since cached elements are never removed
// during ciObjectFactory lifetime. ciObjectFactory itself is created for
// every compilation and lives for the whole duration of the compilation.
ciObject* h = get(holder->klass_holder());
}
}
if (o->is_klass()) { if (o->is_klass()) {
Klass* k = (Klass*)o; Klass* k = (Klass*)o;
if (k->is_instance_klass()) { if (k->is_instance_klass()) {
@ -401,38 +385,6 @@ ciMetadata* ciObjectFactory::create_new_metadata(Metadata* o) {
return NULL; return NULL;
} }
// ------------------------------------------------------------------
// ciObjectFactory::ensure_metadata_alive
//
// Ensure that the metadata wrapped by the ciMetadata is kept alive by GC.
// This is primarily useful for metadata which is considered as weak roots
// by the GC but need to be strong roots if reachable from a current compilation.
//
void ciObjectFactory::ensure_metadata_alive(ciMetadata* m) {
ASSERT_IN_VM; // We're handling raw oops here.
#if INCLUDE_ALL_GCS
if (!UseG1GC) {
return;
}
Klass* metadata_owner_klass;
if (m->is_klass()) {
metadata_owner_klass = m->as_klass()->get_Klass();
} else if (m->is_method()) {
metadata_owner_klass = m->as_method()->get_Method()->constants()->pool_holder();
} else {
fatal("Not implemented for other types of metadata");
return;
}
oop metadata_holder = metadata_owner_klass->klass_holder();
if (metadata_holder != NULL) {
G1SATBCardTableModRefBS::enqueue(metadata_holder);
}
#endif
}
//------------------------------------------------------------------ //------------------------------------------------------------------
// ciObjectFactory::get_unloaded_method // ciObjectFactory::get_unloaded_method
// //

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -73,8 +73,6 @@ private:
ciObject* create_new_object(oop o); ciObject* create_new_object(oop o);
ciMetadata* create_new_metadata(Metadata* o); ciMetadata* create_new_metadata(Metadata* o);
void ensure_metadata_alive(ciMetadata* m);
static bool is_equal(NonPermObject* p, oop key) { static bool is_equal(NonPermObject* p, oop key) {
return p->object()->get_oop() == key; return p->object()->get_oop() == key;
} }