/* * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
// 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.
oop holder = ik->klass_holder(); if (ik->class_loader_data()->has_class_mirror_holder()) { // Though ciInstanceKlass records class loader oop, it's not enough to keep // non-strong hidden 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 hidden class is the mirror which is never null");
(void)CURRENT_ENV->get_object(holder);
}
// ------------------------------------------------------------------ // ciInstanceKlass::field_cache // // Get the field cache associated with this klass.
ciConstantPoolCache* ciInstanceKlass::field_cache() { if (is_shared()) { return NULL;
} if (_field_cache == NULL) {
assert(!is_java_lang_Object(), "Object has no fields");
Arena* arena = CURRENT_ENV->arena();
_field_cache = new (arena) ciConstantPoolCache(arena, 5);
} return _field_cache;
}
if (offset < instanceOopDesc::base_offset_in_bytes()) { // All header offsets belong properly to java/lang/Object. return CURRENT_ENV->Object_klass();
}
ciInstanceKlass* self = this;
assert(self->is_loaded(), "must be loaded to access field info");
ciField* field = self->get_field_by_offset(offset, false); if (field != NULL) { return field->holder();
} else { for (;;) {
assert(self->is_loaded(), "must be loaded to have size");
ciInstanceKlass* super = self->super(); if (super == NULL ||
super->nof_nonstatic_fields() == 0 ||
super->layout_helper_size_in_bytes() <= offset) { return self;
} else {
self = super; // return super->get_canonical_holder(offset)
}
}
}
}
// ------------------------------------------------------------------ // ciInstanceKlass::is_java_lang_Object // // Is this klass java.lang.Object? bool ciInstanceKlass::is_java_lang_Object() const { return equals(CURRENT_ENV->Object_klass());
}
// ------------------------------------------------------------------ // ciInstanceKlass::uses_default_loader bool ciInstanceKlass::uses_default_loader() const { // Note: We do not need to resolve the handle or enter the VM // in order to test null-ness. return _loader == NULL;
}
/** * Return basic type of boxed value for box klass or T_OBJECT if not.
*/
BasicType ciInstanceKlass::box_klass_type() const { if (uses_default_loader() && is_loaded()) { return vmClasses::box_klass_type(get_Klass());
} else { return T_OBJECT;
}
}
/** * Is this boxing klass?
*/ bool ciInstanceKlass::is_box_klass() const { return is_java_primitive(box_klass_type());
}
/** * Is this boxed value offset?
*/ bool ciInstanceKlass::is_boxed_value_offset(int offset) const {
BasicType bt = box_klass_type(); return is_java_primitive(bt) &&
(offset == java_lang_boxing_object::value_offset(bt));
}
// ------------------------------------------------------------------ // ciInstanceKlass::is_in_package // // Is this klass in the given package? bool ciInstanceKlass::is_in_package(constchar* packagename, int len) { // To avoid class loader mischief, this test always rejects application classes. if (!uses_default_loader()) returnfalse;
GUARDED_VM_ENTRY( return is_in_package_impl(packagename, len);
)
}
bool ciInstanceKlass::is_in_package_impl(constchar* packagename, int len) {
ASSERT_IN_VM;
// If packagename contains trailing '/' exclude it from the // prefix-test since we test for it explicitly. if (packagename[len - 1] == '/')
len--;
if (!name()->starts_with(packagename, len)) returnfalse;
// Test if the class name is something like "java/lang". if ((len + 1) > name()->utf8_length()) returnfalse;
// Test for trailing '/' if (name()->char_at(len) != '/') returnfalse;
// Make sure it's not actually in a subpackage: if (name()->index_of_at(len+1, "/", 1) >= 0) returnfalse;
if (_super) {
st->print(" super=");
_super->print_name();
} if (_java_mirror) {
st->print(" mirror=PRESENT");
}
}
}
// ------------------------------------------------------------------ // ciInstanceKlass::super // // Get the superklass of this klass.
ciInstanceKlass* ciInstanceKlass::super() {
assert(is_loaded(), "must be loaded"); if (_super == NULL && !is_java_lang_Object()) {
GUARDED_VM_ENTRY(
Klass* super_klass = get_instanceKlass()->super();
_super = CURRENT_ENV->get_instance_klass(super_klass);
)
} return _super;
}
// ------------------------------------------------------------------ // ciInstanceKlass::java_mirror // // Get the instance of java.lang.Class corresponding to this klass. // Cache it on this->_java_mirror.
ciInstance* ciInstanceKlass::java_mirror() { if (is_shared()) { return ciKlass::java_mirror();
} if (_java_mirror == NULL) {
_java_mirror = ciKlass::java_mirror();
} return _java_mirror;
}
// ------------------------------------------------------------------ // ciInstanceKlass::unique_concrete_subklass
ciInstanceKlass* ciInstanceKlass::unique_concrete_subklass() { if (!is_loaded()) return NULL; // No change if class is not loaded if (!is_abstract()) return NULL; // Only applies to abstract classes. if (!has_subklass()) return NULL; // Must have at least one subklass.
VM_ENTRY_MARK;
InstanceKlass* ik = get_instanceKlass();
Klass* up = ik->up_cast_abstract();
assert(up->is_instance_klass(), "must be InstanceKlass"); if (ik == up) { return NULL;
} return CURRENT_THREAD_ENV->get_instance_klass(up);
}
// ------------------------------------------------------------------ // ciInstanceKlass::get_field_by_offset
ciField* ciInstanceKlass::get_field_by_offset(int field_offset, bool is_static) { if (!is_static) { for (int i = 0, len = nof_nonstatic_fields(); i < len; i++) {
ciField* field = _nonstatic_fields->at(i); int field_off = field->offset_in_bytes(); if (field_off == field_offset) return field; if (field_off > field_offset) break; // could do binary search or check bins, but probably not worth it
} return NULL;
}
VM_ENTRY_MARK;
InstanceKlass* k = get_instanceKlass();
fieldDescriptor fd; if (!k->find_field_from_offset(field_offset, is_static, &fd)) { return NULL;
}
ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd); return field;
}
staticint sort_field_by_offset(ciField** a, ciField** b) { return (*a)->offset_in_bytes() - (*b)->offset_in_bytes(); // (no worries about 32-bit overflow...)
}
// ------------------------------------------------------------------ // ciInstanceKlass::compute_nonstatic_fields int ciInstanceKlass::compute_nonstatic_fields() {
assert(is_loaded(), "must be loaded");
if (_nonstatic_fields != NULL) return _nonstatic_fields->length();
if (fields == NULL) { // This can happen if this class (java.lang.Class) has invisible fields. if (super_fields != NULL) {
_nonstatic_fields = super_fields; return super_fields->length();
} else { return 0;
}
}
int flen = fields->length();
// Now sort them by offset, ascending. // (In principle, they could mix with superclass fields.)
fields->sort(sort_field_by_offset);
_nonstatic_fields = fields; return flen;
}
GrowableArray<ciField*>*
ciInstanceKlass::compute_nonstatic_fields_impl(GrowableArray<ciField*>*
super_fields) {
ASSERT_IN_VM;
Arena* arena = CURRENT_ENV->arena(); int flen = 0;
GrowableArray<ciField*>* fields = NULL;
InstanceKlass* k = get_instanceKlass(); for (JavaFieldStream fs(k); !fs.done(); fs.next()) { if (fs.access_flags().is_static()) continue;
flen += 1;
}
// allocate the array: if (flen == 0) { return NULL; // return nothing if none are locally declared
} if (super_fields != NULL) {
flen += super_fields->length();
}
fields = new (arena) GrowableArray<ciField*>(arena, flen, 0, NULL); if (super_fields != NULL) {
fields->appendAll(super_fields);
}
for (JavaFieldStream fs(k); !fs.done(); fs.next()) { if (fs.access_flags().is_static()) continue;
fieldDescriptor& fd = fs.field_descriptor();
ciField* field = new (arena) ciField(&fd);
fields->append(field);
}
assert(fields->length() == flen, "sanity"); return fields;
}
bool ciInstanceKlass::compute_injected_fields_helper() {
ASSERT_IN_VM;
InstanceKlass* k = get_instanceKlass();
for (InternalFieldStream fs(k); !fs.done(); fs.next()) { if (fs.access_flags().is_static()) continue; returntrue;
} returnfalse;
}
void ciInstanceKlass::compute_injected_fields() {
assert(is_loaded(), "must be loaded");
int has_injected_fields = 0; if (super() != NULL && super()->has_injected_fields()) {
has_injected_fields = 1;
} else {
GUARDED_VM_ENTRY({
has_injected_fields = compute_injected_fields_helper() ? 1 : 0;
});
} // may be concurrently initialized for shared ciInstanceKlass objects
assert(_has_injected_fields == -1 || _has_injected_fields == has_injected_fields, "broken concurrent initialization");
_has_injected_fields = has_injected_fields;
}
// ------------------------------------------------------------------ // ciInstanceKlass::find_method // // Find a method in this klass.
ciMethod* ciInstanceKlass::find_method(ciSymbol* name, ciSymbol* signature) {
VM_ENTRY_MARK;
InstanceKlass* k = get_instanceKlass();
Symbol* name_sym = name->get_symbol();
Symbol* sig_sym= signature->get_symbol();
Method* m = k->find_method(name_sym, sig_sym); if (m == NULL) return NULL;
return CURRENT_THREAD_ENV->get_method(m);
}
// ------------------------------------------------------------------ // ciInstanceKlass::is_leaf_type bool ciInstanceKlass::is_leaf_type() {
assert(is_loaded(), "must be loaded"); if (is_shared()) { return is_final(); // approximately correct
} else { return !has_subklass() && (nof_implementors() == 0);
}
}
// ------------------------------------------------------------------ // ciInstanceKlass::implementor // // Report an implementor of this interface. // Note that there are various races here, since my copy // of _nof_implementors might be out of date with respect // to results returned by InstanceKlass::implementor. // This is OK, since any dependencies we decide to assert // will be checked later under the Compile_lock.
ciInstanceKlass* ciInstanceKlass::implementor() {
ciInstanceKlass* impl = _implementor; if (impl == NULL) { if (is_shared()) {
impl = this; // assume a well-known interface never has a unique implementor
} else { // Go into the VM to fetch the implementor.
VM_ENTRY_MARK;
MutexLocker ml(Compile_lock);
Klass* k = get_instanceKlass()->implementor(); if (k != NULL) { if (k == get_instanceKlass()) { // More than one implementors. Use 'this' in this case.
impl = this;
} else {
impl = CURRENT_THREAD_ENV->get_instance_klass(k);
}
}
} // Memoize this result.
_implementor = impl;
} return impl;
}
// Utility class for printing of the contents of the static fields for // use by compilation replay. It only prints out the information that // could be consumed by the compiler, so for primitive types it prints // out the actual value. For Strings it's the actual string value. // For array types it it's first level array size since that's the // only value which statically unchangeable. For all other reference // types it simply prints out the dynamic type.
class StaticFinalFieldPrinter : public FieldClosure {
outputStream* _out; constchar* _holder; public:
StaticFinalFieldPrinter(outputStream* out, constchar* holder) :
_out(out),
_holder(holder) {
} void do_field(fieldDescriptor* fd) { if (fd->is_final() && !fd->has_initial_value()) {
ResourceMark rm;
oop mirror = fd->field_holder()->java_mirror();
_out->print("staticfield %s %s %s ", _holder, fd->name()->as_quoted_ascii(), fd->signature()->as_quoted_ascii()); switch (fd->field_type()) { case T_BYTE: _out->print_cr("%d", mirror->byte_field(fd->offset())); break; case T_BOOLEAN: _out->print_cr("%d", mirror->bool_field(fd->offset())); break; case T_SHORT: _out->print_cr("%d", mirror->short_field(fd->offset())); break; case T_CHAR: _out->print_cr("%d", mirror->char_field(fd->offset())); break; case T_INT: _out->print_cr("%d", mirror->int_field(fd->offset())); break; case T_LONG: _out->print_cr(INT64_FORMAT, (int64_t)(mirror->long_field(fd->offset()))); break; case T_FLOAT: { float f = mirror->float_field(fd->offset());
_out->print_cr("%d", *(int*)&f); break;
} case T_DOUBLE: { double d = mirror->double_field(fd->offset());
_out->print_cr(INT64_FORMAT, *(int64_t*)&d); break;
} case T_ARRAY: // fall-through case T_OBJECT: {
oop value = mirror->obj_field_acquire(fd->offset()); if (value == NULL) {
_out->print_cr("null");
} elseif (value->is_instance()) {
assert(fd->field_type() == T_OBJECT, ""); if (value->is_a(vmClasses::String_klass())) { constchar* ascii_value = java_lang_String::as_quoted_ascii(value);
_out->print_cr("\"%s\"", (ascii_value != NULL) ? ascii_value : "");
} else { constchar* klass_name = value->klass()->name()->as_quoted_ascii();
_out->print_cr("%s", klass_name);
}
} elseif (value->is_array()) {
typeArrayOop ta = (typeArrayOop)value;
_out->print("%d", ta->length()); if (value->is_objArray()) {
objArrayOop oa = (objArrayOop)value; constchar* klass_name = value->klass()->name()->as_quoted_ascii();
_out->print(" %s", klass_name);
}
_out->cr();
} else {
ShouldNotReachHere();
} break;
} default:
ShouldNotReachHere();
}
}
}
};
InstanceKlass* ik = get_instanceKlass();
ConstantPool* cp = ik->constants();
// Try to record related loaded classes
Klass* sub = ik->subklass(); while (sub != NULL) { if (sub->is_instance_klass()) {
InstanceKlass *isub = InstanceKlass::cast(sub);
dump_replay_instanceKlass(out, isub);
}
sub = sub->next_sibling();
}
// Dump out the state of the constant pool tags. During replay the // tags will be validated for things which shouldn't change and // classes will be resolved if the tags indicate that they were // resolved at compile time. constchar *name = replay_name();
out->print("ciInstanceKlass %s %d %d %d", name,
is_linked(), is_initialized(), cp->length()); for (int index = 1; index < cp->length(); index++) {
out->print(" %d", cp->tags()->at(index));
}
out->cr(); if (is_initialized()) { // Dump out the static final fields in case the compilation relies // on their value for correct replay.
StaticFinalFieldPrinter sffp(out, name);
ik->do_local_static_fields(&sffp);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.