src/share/vm/ci/ciObjectFactory.cpp

Wed, 31 Jan 2018 19:24:57 -0500

author
dbuck
date
Wed, 31 Jan 2018 19:24:57 -0500
changeset 9289
427b2fb1944f
parent 8316
626f594dffa6
child 8604
04d83ba48607
permissions
-rw-r--r--

8189170: Add option to disable stack overflow checking in primordial thread for use with JNI_CreateJavaJVM
Reviewed-by: dcubed

duke@435 1 /*
zgu@7074 2 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "ci/ciCallSite.hpp"
stefank@2314 27 #include "ci/ciInstance.hpp"
stefank@2314 28 #include "ci/ciInstanceKlass.hpp"
twisti@3969 29 #include "ci/ciMemberName.hpp"
stefank@2314 30 #include "ci/ciMethod.hpp"
stefank@2314 31 #include "ci/ciMethodData.hpp"
stefank@2314 32 #include "ci/ciMethodHandle.hpp"
twisti@4133 33 #include "ci/ciMethodType.hpp"
stefank@2314 34 #include "ci/ciNullObject.hpp"
stefank@2314 35 #include "ci/ciObjArray.hpp"
stefank@2314 36 #include "ci/ciObjArrayKlass.hpp"
coleenp@4037 37 #include "ci/ciObject.hpp"
stefank@2314 38 #include "ci/ciObjectFactory.hpp"
stefank@2314 39 #include "ci/ciSymbol.hpp"
stefank@2314 40 #include "ci/ciTypeArray.hpp"
stefank@2314 41 #include "ci/ciTypeArrayKlass.hpp"
stefank@2314 42 #include "ci/ciUtilities.hpp"
stefank@2314 43 #include "classfile/systemDictionary.hpp"
stefank@2314 44 #include "gc_interface/collectedHeap.inline.hpp"
stefank@2314 45 #include "memory/allocation.inline.hpp"
stefank@2314 46 #include "oops/oop.inline.hpp"
stefank@2314 47 #include "oops/oop.inline2.hpp"
stefank@2314 48 #include "runtime/fieldType.hpp"
stefank@6992 49 #if INCLUDE_ALL_GCS
stefank@6992 50 # include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
stefank@6992 51 #endif
duke@435 52
duke@435 53 // ciObjectFactory
duke@435 54 //
duke@435 55 // This class handles requests for the creation of new instances
duke@435 56 // of ciObject and its subclasses. It contains a caching mechanism
duke@435 57 // which ensures that for each oop, at most one ciObject is created.
duke@435 58 // This invariant allows more efficient implementation of ciObject.
duke@435 59 //
duke@435 60 // Implementation note: the oop->ciObject mapping is represented as
duke@435 61 // a table stored in an array. Even though objects are moved
duke@435 62 // by the garbage collector, the compactor preserves their relative
duke@435 63 // order; address comparison of oops (in perm space) is safe so long
duke@435 64 // as we prohibit GC during our comparisons. We currently use binary
duke@435 65 // search to find the oop in the table, and inserting a new oop
duke@435 66 // into the table may be costly. If this cost ends up being
duke@435 67 // problematic the underlying data structure can be switched to some
duke@435 68 // sort of balanced binary tree.
duke@435 69
coleenp@4037 70 GrowableArray<ciMetadata*>* ciObjectFactory::_shared_ci_metadata = NULL;
duke@435 71 ciSymbol* ciObjectFactory::_shared_ci_symbols[vmSymbols::SID_LIMIT];
duke@435 72 int ciObjectFactory::_shared_ident_limit = 0;
duke@435 73 volatile bool ciObjectFactory::_initialized = false;
duke@435 74
duke@435 75
duke@435 76 // ------------------------------------------------------------------
duke@435 77 // ciObjectFactory::ciObjectFactory
duke@435 78 ciObjectFactory::ciObjectFactory(Arena* arena,
duke@435 79 int expected_size) {
duke@435 80
duke@435 81 for (int i = 0; i < NON_PERM_BUCKETS; i++) {
duke@435 82 _non_perm_bucket[i] = NULL;
duke@435 83 }
duke@435 84 _non_perm_count = 0;
duke@435 85
duke@435 86 _next_ident = _shared_ident_limit;
duke@435 87 _arena = arena;
coleenp@4037 88 _ci_metadata = new (arena) GrowableArray<ciMetadata*>(arena, expected_size, 0, NULL);
duke@435 89
duke@435 90 // If the shared ci objects exist append them to this factory's objects
duke@435 91
coleenp@4037 92 if (_shared_ci_metadata != NULL) {
coleenp@4037 93 _ci_metadata->appendAll(_shared_ci_metadata);
duke@435 94 }
duke@435 95
duke@435 96 _unloaded_methods = new (arena) GrowableArray<ciMethod*>(arena, 4, 0, NULL);
duke@435 97 _unloaded_klasses = new (arena) GrowableArray<ciKlass*>(arena, 8, 0, NULL);
jrose@1957 98 _unloaded_instances = new (arena) GrowableArray<ciInstance*>(arena, 4, 0, NULL);
duke@435 99 _return_addresses =
duke@435 100 new (arena) GrowableArray<ciReturnAddress*>(arena, 8, 0, NULL);
coleenp@2497 101
coleenp@2497 102 _symbols = new (arena) GrowableArray<ciSymbol*>(arena, 100, 0, NULL);
duke@435 103 }
duke@435 104
duke@435 105 // ------------------------------------------------------------------
duke@435 106 // ciObjectFactory::ciObjectFactory
duke@435 107 void ciObjectFactory::initialize() {
duke@435 108 ASSERT_IN_VM;
duke@435 109 JavaThread* thread = JavaThread::current();
duke@435 110 HandleMark handle_mark(thread);
duke@435 111
duke@435 112 // This Arena is long lived and exists in the resource mark of the
duke@435 113 // compiler thread that initializes the initial ciObjectFactory which
duke@435 114 // creates the shared ciObjects that all later ciObjectFactories use.
zgu@7074 115 Arena* arena = new (mtCompiler) Arena(mtCompiler);
duke@435 116 ciEnv initial(arena);
duke@435 117 ciEnv* env = ciEnv::current();
duke@435 118 env->_factory->init_shared_objects();
duke@435 119
duke@435 120 _initialized = true;
duke@435 121
duke@435 122 }
duke@435 123
duke@435 124 void ciObjectFactory::init_shared_objects() {
duke@435 125
duke@435 126 _next_ident = 1; // start numbering CI objects at 1
duke@435 127
duke@435 128 {
coleenp@4037 129 // Create the shared symbols, but not in _shared_ci_metadata.
duke@435 130 int i;
duke@435 131 for (i = vmSymbols::FIRST_SID; i < vmSymbols::SID_LIMIT; i++) {
coleenp@2497 132 Symbol* vmsym = vmSymbols::symbol_at((vmSymbols::SID) i);
coleenp@2497 133 assert(vmSymbols::find_sid(vmsym) == i, "1-1 mapping");
coleenp@2497 134 ciSymbol* sym = new (_arena) ciSymbol(vmsym, (vmSymbols::SID) i);
duke@435 135 init_ident_of(sym);
duke@435 136 _shared_ci_symbols[i] = sym;
duke@435 137 }
duke@435 138 #ifdef ASSERT
duke@435 139 for (i = vmSymbols::FIRST_SID; i < vmSymbols::SID_LIMIT; i++) {
coleenp@2497 140 Symbol* vmsym = vmSymbols::symbol_at((vmSymbols::SID) i);
duke@435 141 ciSymbol* sym = vm_symbol_at((vmSymbols::SID) i);
coleenp@2497 142 assert(sym->get_symbol() == vmsym, "oop must match");
duke@435 143 }
coleenp@2497 144 assert(ciSymbol::void_class_signature()->get_symbol() == vmSymbols::void_class_signature(), "spot check");
duke@435 145 #endif
duke@435 146 }
duke@435 147
coleenp@4037 148 _ci_metadata = new (_arena) GrowableArray<ciMetadata*>(_arena, 64, 0, NULL);
duke@435 149
duke@435 150 for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) {
duke@435 151 BasicType t = (BasicType)i;
roland@4159 152 if (type2name(t) != NULL && t != T_OBJECT && t != T_ARRAY && t != T_NARROWOOP && t != T_NARROWKLASS) {
duke@435 153 ciType::_basic_types[t] = new (_arena) ciType(t);
duke@435 154 init_ident_of(ciType::_basic_types[t]);
duke@435 155 }
duke@435 156 }
duke@435 157
duke@435 158 ciEnv::_null_object_instance = new (_arena) ciNullObject();
duke@435 159 init_ident_of(ciEnv::_null_object_instance);
never@1577 160
never@1577 161 #define WK_KLASS_DEFN(name, ignore_s, opt) \
never@1577 162 if (SystemDictionary::name() != NULL) \
coleenp@4037 163 ciEnv::_##name = get_metadata(SystemDictionary::name())->as_instance_klass();
never@1577 164
never@1577 165 WK_KLASSES_DO(WK_KLASS_DEFN)
never@1577 166 #undef WK_KLASS_DEFN
duke@435 167
coleenp@4037 168 for (int len = -1; len != _ci_metadata->length(); ) {
coleenp@4037 169 len = _ci_metadata->length();
duke@435 170 for (int i2 = 0; i2 < len; i2++) {
coleenp@4037 171 ciMetadata* obj = _ci_metadata->at(i2);
coleenp@4037 172 assert (obj->is_metadata(), "what else would it be?");
duke@435 173 if (obj->is_loaded() && obj->is_instance_klass()) {
duke@435 174 obj->as_instance_klass()->compute_nonstatic_fields();
duke@435 175 }
duke@435 176 }
duke@435 177 }
duke@435 178
coleenp@2497 179 ciEnv::_unloaded_cisymbol = ciObjectFactory::get_symbol(vmSymbols::dummy_symbol());
coleenp@4142 180 // Create dummy InstanceKlass and ObjArrayKlass object and assign them idents
duke@435 181 ciEnv::_unloaded_ciinstance_klass = new (_arena) ciInstanceKlass(ciEnv::_unloaded_cisymbol, NULL, NULL);
duke@435 182 init_ident_of(ciEnv::_unloaded_ciinstance_klass);
duke@435 183 ciEnv::_unloaded_ciobjarrayklass = new (_arena) ciObjArrayKlass(ciEnv::_unloaded_cisymbol, ciEnv::_unloaded_ciinstance_klass, 1);
duke@435 184 init_ident_of(ciEnv::_unloaded_ciobjarrayklass);
duke@435 185 assert(ciEnv::_unloaded_ciobjarrayklass->is_obj_array_klass(), "just checking");
duke@435 186
coleenp@4037 187 get_metadata(Universe::boolArrayKlassObj());
coleenp@4037 188 get_metadata(Universe::charArrayKlassObj());
coleenp@4037 189 get_metadata(Universe::singleArrayKlassObj());
coleenp@4037 190 get_metadata(Universe::doubleArrayKlassObj());
coleenp@4037 191 get_metadata(Universe::byteArrayKlassObj());
coleenp@4037 192 get_metadata(Universe::shortArrayKlassObj());
coleenp@4037 193 get_metadata(Universe::intArrayKlassObj());
coleenp@4037 194 get_metadata(Universe::longArrayKlassObj());
duke@435 195
duke@435 196
duke@435 197
duke@435 198 assert(_non_perm_count == 0, "no shared non-perm objects");
duke@435 199
duke@435 200 // The shared_ident_limit is the first ident number that will
duke@435 201 // be used for non-shared objects. That is, numbers less than
duke@435 202 // this limit are permanently assigned to shared CI objects,
duke@435 203 // while the higher numbers are recycled afresh by each new ciEnv.
duke@435 204
duke@435 205 _shared_ident_limit = _next_ident;
coleenp@4037 206 _shared_ci_metadata = _ci_metadata;
duke@435 207 }
duke@435 208
coleenp@2497 209
coleenp@2497 210 ciSymbol* ciObjectFactory::get_symbol(Symbol* key) {
coleenp@2497 211 vmSymbols::SID sid = vmSymbols::find_sid(key);
coleenp@2497 212 if (sid != vmSymbols::NO_SID) {
coleenp@2497 213 // do not pollute the main cache with it
coleenp@2497 214 return vm_symbol_at(sid);
coleenp@2497 215 }
coleenp@2497 216
coleenp@2497 217 assert(vmSymbols::find_sid(key) == vmSymbols::NO_SID, "");
coleenp@2497 218 ciSymbol* s = new (arena()) ciSymbol(key, vmSymbols::NO_SID);
coleenp@2497 219 _symbols->push(s);
coleenp@2497 220 return s;
coleenp@2497 221 }
coleenp@2497 222
coleenp@2497 223 // Decrement the refcount when done on symbols referenced by this compilation.
coleenp@2497 224 void ciObjectFactory::remove_symbols() {
coleenp@2497 225 for (int i = 0; i < _symbols->length(); i++) {
coleenp@2497 226 ciSymbol* s = _symbols->at(i);
coleenp@2497 227 s->get_symbol()->decrement_refcount();
coleenp@2497 228 }
coleenp@2497 229 // Since _symbols is resource allocated we're not allowed to delete it
coleenp@2497 230 // but it'll go away just the same.
coleenp@2497 231 }
coleenp@2497 232
duke@435 233 // ------------------------------------------------------------------
duke@435 234 // ciObjectFactory::get
duke@435 235 //
duke@435 236 // Get the ciObject corresponding to some oop. If the ciObject has
duke@435 237 // already been created, it is returned. Otherwise, a new ciObject
duke@435 238 // is created.
duke@435 239 ciObject* ciObjectFactory::get(oop key) {
duke@435 240 ASSERT_IN_VM;
duke@435 241
vlivanov@7384 242 assert(Universe::heap()->is_in_reserved(key), "must be");
coleenp@4037 243
twisti@4133 244 NonPermObject* &bucket = find_non_perm(key);
twisti@4133 245 if (bucket != NULL) {
twisti@4133 246 return bucket->object();
twisti@4133 247 }
duke@435 248
twisti@4133 249 // The ciObject does not yet exist. Create it and insert it
twisti@4133 250 // into the cache.
twisti@4133 251 Handle keyHandle(key);
twisti@4133 252 ciObject* new_object = create_new_object(keyHandle());
twisti@4133 253 assert(keyHandle() == new_object->get_oop(), "must be properly recorded");
twisti@4133 254 init_ident_of(new_object);
coleenp@4037 255 assert(Universe::heap()->is_in_reserved(new_object->get_oop()), "must be");
coleenp@4037 256
twisti@4133 257 // Not a perm-space object.
twisti@4133 258 insert_non_perm(bucket, keyHandle(), new_object);
twisti@4133 259 return new_object;
twisti@4133 260 }
coleenp@4037 261
coleenp@4037 262 // ------------------------------------------------------------------
vlivanov@7384 263 // ciObjectFactory::get_metadata
coleenp@4037 264 //
vlivanov@7384 265 // Get the ciMetadata corresponding to some Metadata. If the ciMetadata has
vlivanov@7384 266 // already been created, it is returned. Otherwise, a new ciMetadata
coleenp@4037 267 // is created.
coleenp@4037 268 ciMetadata* ciObjectFactory::get_metadata(Metadata* key) {
coleenp@4037 269 ASSERT_IN_VM;
coleenp@4037 270
coleenp@4037 271 #ifdef ASSERT
coleenp@4037 272 if (CIObjectFactoryVerify) {
coleenp@4037 273 Metadata* last = NULL;
coleenp@4037 274 for (int j = 0; j< _ci_metadata->length(); j++) {
coleenp@4037 275 Metadata* o = _ci_metadata->at(j)->constant_encoding();
coleenp@4037 276 assert(last < o, "out of order");
coleenp@4037 277 last = o;
coleenp@4037 278 }
coleenp@4037 279 }
coleenp@4037 280 #endif // ASSERT
coleenp@4037 281 int len = _ci_metadata->length();
coleenp@4037 282 int index = find(key, _ci_metadata);
coleenp@4037 283 #ifdef ASSERT
coleenp@4037 284 if (CIObjectFactoryVerify) {
coleenp@4037 285 for (int i=0; i<_ci_metadata->length(); i++) {
coleenp@4037 286 if (_ci_metadata->at(i)->constant_encoding() == key) {
coleenp@4037 287 assert(index == i, " bad lookup");
coleenp@4037 288 }
coleenp@4037 289 }
coleenp@4037 290 }
coleenp@4037 291 #endif
coleenp@4037 292 if (!is_found_at(index, key, _ci_metadata)) {
vlivanov@7384 293 // The ciMetadata does not yet exist. Create it and insert it
coleenp@4037 294 // into the cache.
vlivanov@7384 295 ciMetadata* new_object = create_new_metadata(key);
coleenp@4037 296 init_ident_of(new_object);
coleenp@4037 297 assert(new_object->is_metadata(), "must be");
coleenp@4037 298
coleenp@4037 299 if (len != _ci_metadata->length()) {
duke@435 300 // creating the new object has recursively entered new objects
duke@435 301 // into the table. We need to recompute our index.
coleenp@4037 302 index = find(key, _ci_metadata);
duke@435 303 }
coleenp@4037 304 assert(!is_found_at(index, key, _ci_metadata), "no double insert");
coleenp@4037 305 insert(index, new_object, _ci_metadata);
duke@435 306 return new_object;
duke@435 307 }
coleenp@4037 308 return _ci_metadata->at(index)->as_metadata();
duke@435 309 }
duke@435 310
duke@435 311 // ------------------------------------------------------------------
duke@435 312 // ciObjectFactory::create_new_object
duke@435 313 //
duke@435 314 // Create a new ciObject from an oop.
duke@435 315 //
duke@435 316 // Implementation note: this functionality could be virtual behavior
duke@435 317 // of the oop itself. For now, we explicitly marshal the object.
duke@435 318 ciObject* ciObjectFactory::create_new_object(oop o) {
duke@435 319 EXCEPTION_CONTEXT;
duke@435 320
coleenp@4037 321 if (o->is_instance()) {
duke@435 322 instanceHandle h_i(THREAD, (instanceOop)o);
jrose@2639 323 if (java_lang_invoke_CallSite::is_instance(o))
twisti@1573 324 return new (arena()) ciCallSite(h_i);
twisti@3969 325 else if (java_lang_invoke_MemberName::is_instance(o))
twisti@3969 326 return new (arena()) ciMemberName(h_i);
jrose@2639 327 else if (java_lang_invoke_MethodHandle::is_instance(o))
twisti@1573 328 return new (arena()) ciMethodHandle(h_i);
twisti@4133 329 else if (java_lang_invoke_MethodType::is_instance(o))
twisti@4133 330 return new (arena()) ciMethodType(h_i);
twisti@1573 331 else
twisti@1573 332 return new (arena()) ciInstance(h_i);
duke@435 333 } else if (o->is_objArray()) {
duke@435 334 objArrayHandle h_oa(THREAD, (objArrayOop)o);
duke@435 335 return new (arena()) ciObjArray(h_oa);
duke@435 336 } else if (o->is_typeArray()) {
duke@435 337 typeArrayHandle h_ta(THREAD, (typeArrayOop)o);
duke@435 338 return new (arena()) ciTypeArray(h_ta);
coleenp@4037 339 }
coleenp@4037 340
coleenp@4037 341 // The oop is of some type not supported by the compiler interface.
coleenp@4037 342 ShouldNotReachHere();
coleenp@4037 343 return NULL;
coleenp@4037 344 }
coleenp@4037 345
coleenp@4037 346 // ------------------------------------------------------------------
vlivanov@7384 347 // ciObjectFactory::create_new_metadata
coleenp@4037 348 //
vlivanov@7384 349 // Create a new ciMetadata from a Metadata*.
coleenp@4037 350 //
vlivanov@7384 351 // Implementation note: in order to keep Metadata live, an auxiliary ciObject
vlivanov@7384 352 // is used, which points to it's holder.
vlivanov@7384 353 ciMetadata* ciObjectFactory::create_new_metadata(Metadata* o) {
coleenp@4037 354 EXCEPTION_CONTEXT;
coleenp@4037 355
vlivanov@7384 356 // Hold metadata from unloading by keeping it's holder alive.
vlivanov@7384 357 if (_initialized && o->is_klass()) {
vlivanov@7384 358 Klass* holder = ((Klass*)o);
vlivanov@7384 359 if (holder->oop_is_instance() && InstanceKlass::cast(holder)->is_anonymous()) {
vlivanov@7384 360 // Though ciInstanceKlass records class loader oop, it's not enough to keep
vlivanov@7384 361 // VM anonymous classes alive (loader == NULL). Klass holder should be used instead.
vlivanov@7384 362 // It is enough to record a ciObject, since cached elements are never removed
vlivanov@7384 363 // during ciObjectFactory lifetime. ciObjectFactory itself is created for
vlivanov@7384 364 // every compilation and lives for the whole duration of the compilation.
vlivanov@7384 365 ciObject* h = get(holder->klass_holder());
vlivanov@7384 366 }
vlivanov@7384 367 }
vlivanov@7384 368
coleenp@4037 369 if (o->is_klass()) {
coleenp@4037 370 KlassHandle h_k(THREAD, (Klass*)o);
coleenp@4037 371 Klass* k = (Klass*)o;
coleenp@4037 372 if (k->oop_is_instance()) {
coleenp@4037 373 return new (arena()) ciInstanceKlass(h_k);
coleenp@4037 374 } else if (k->oop_is_objArray()) {
coleenp@4037 375 return new (arena()) ciObjArrayKlass(h_k);
coleenp@4037 376 } else if (k->oop_is_typeArray()) {
coleenp@4037 377 return new (arena()) ciTypeArrayKlass(h_k);
coleenp@4037 378 }
coleenp@4037 379 } else if (o->is_method()) {
coleenp@4037 380 methodHandle h_m(THREAD, (Method*)o);
vlivanov@7384 381 ciEnv *env = CURRENT_THREAD_ENV;
vlivanov@7384 382 ciInstanceKlass* holder = env->get_instance_klass(h_m()->method_holder());
vlivanov@7384 383 return new (arena()) ciMethod(h_m, holder);
coleenp@4037 384 } else if (o->is_methodData()) {
coleenp@4037 385 // Hold methodHandle alive - might not be necessary ???
coleenp@4037 386 methodHandle h_m(THREAD, ((MethodData*)o)->method());
coleenp@4037 387 return new (arena()) ciMethodData((MethodData*)o);
duke@435 388 }
duke@435 389
vlivanov@7384 390 // The Metadata* is of some type not supported by the compiler interface.
duke@435 391 ShouldNotReachHere();
duke@435 392 return NULL;
duke@435 393 }
duke@435 394
stefank@6992 395 // ------------------------------------------------------------------
stefank@6992 396 // ciObjectFactory::ensure_metadata_alive
stefank@6992 397 //
stefank@6992 398 // Ensure that the metadata wrapped by the ciMetadata is kept alive by GC.
stefank@6992 399 // This is primarily useful for metadata which is considered as weak roots
stefank@6992 400 // by the GC but need to be strong roots if reachable from a current compilation.
stefank@6992 401 //
stefank@6992 402 void ciObjectFactory::ensure_metadata_alive(ciMetadata* m) {
stefank@6992 403 ASSERT_IN_VM; // We're handling raw oops here.
stefank@6992 404
stefank@6992 405 #if INCLUDE_ALL_GCS
stefank@6992 406 if (!UseG1GC) {
stefank@6992 407 return;
stefank@6992 408 }
stefank@6992 409 Klass* metadata_owner_klass;
stefank@6992 410 if (m->is_klass()) {
stefank@6992 411 metadata_owner_klass = m->as_klass()->get_Klass();
stefank@6992 412 } else if (m->is_method()) {
stefank@6992 413 metadata_owner_klass = m->as_method()->get_Method()->constants()->pool_holder();
stefank@6992 414 } else {
stefank@6992 415 fatal("Not implemented for other types of metadata");
csahu@8316 416 return;
stefank@6992 417 }
stefank@6992 418
stefank@6992 419 oop metadata_holder = metadata_owner_klass->klass_holder();
stefank@6992 420 if (metadata_holder != NULL) {
stefank@6992 421 G1SATBCardTableModRefBS::enqueue(metadata_holder);
stefank@6992 422 }
stefank@6992 423
stefank@6992 424 #endif
stefank@6992 425 }
stefank@6992 426
duke@435 427 //------------------------------------------------------------------
duke@435 428 // ciObjectFactory::get_unloaded_method
duke@435 429 //
duke@435 430 // Get the ciMethod representing an unloaded/unfound method.
duke@435 431 //
duke@435 432 // Implementation note: unloaded methods are currently stored in
duke@435 433 // an unordered array, requiring a linear-time lookup for each
duke@435 434 // unloaded method. This may need to change.
duke@435 435 ciMethod* ciObjectFactory::get_unloaded_method(ciInstanceKlass* holder,
duke@435 436 ciSymbol* name,
twisti@3197 437 ciSymbol* signature,
twisti@3197 438 ciInstanceKlass* accessor) {
twisti@3197 439 ciSignature* that = NULL;
twisti@3197 440 for (int i = 0; i < _unloaded_methods->length(); i++) {
duke@435 441 ciMethod* entry = _unloaded_methods->at(i);
duke@435 442 if (entry->holder()->equals(holder) &&
duke@435 443 entry->name()->equals(name) &&
duke@435 444 entry->signature()->as_symbol()->equals(signature)) {
twisti@3197 445 // Short-circuit slow resolve.
twisti@3197 446 if (entry->signature()->accessing_klass() == accessor) {
twisti@3197 447 // We've found a match.
twisti@3197 448 return entry;
twisti@3197 449 } else {
twisti@3197 450 // Lazily create ciSignature
twisti@3197 451 if (that == NULL) that = new (arena()) ciSignature(accessor, constantPoolHandle(), signature);
twisti@3197 452 if (entry->signature()->equals(that)) {
twisti@3197 453 // We've found a match.
twisti@3197 454 return entry;
twisti@3197 455 }
twisti@3197 456 }
duke@435 457 }
duke@435 458 }
duke@435 459
duke@435 460 // This is a new unloaded method. Create it and stick it in
duke@435 461 // the cache.
twisti@3197 462 ciMethod* new_method = new (arena()) ciMethod(holder, name, signature, accessor);
duke@435 463
duke@435 464 init_ident_of(new_method);
duke@435 465 _unloaded_methods->append(new_method);
duke@435 466
duke@435 467 return new_method;
duke@435 468 }
duke@435 469
duke@435 470 //------------------------------------------------------------------
duke@435 471 // ciObjectFactory::get_unloaded_klass
duke@435 472 //
duke@435 473 // Get a ciKlass representing an unloaded klass.
duke@435 474 //
duke@435 475 // Implementation note: unloaded klasses are currently stored in
duke@435 476 // an unordered array, requiring a linear-time lookup for each
duke@435 477 // unloaded klass. This may need to change.
duke@435 478 ciKlass* ciObjectFactory::get_unloaded_klass(ciKlass* accessing_klass,
duke@435 479 ciSymbol* name,
duke@435 480 bool create_if_not_found) {
duke@435 481 EXCEPTION_CONTEXT;
duke@435 482 oop loader = NULL;
duke@435 483 oop domain = NULL;
duke@435 484 if (accessing_klass != NULL) {
duke@435 485 loader = accessing_klass->loader();
duke@435 486 domain = accessing_klass->protection_domain();
duke@435 487 }
duke@435 488 for (int i=0; i<_unloaded_klasses->length(); i++) {
duke@435 489 ciKlass* entry = _unloaded_klasses->at(i);
duke@435 490 if (entry->name()->equals(name) &&
duke@435 491 entry->loader() == loader &&
duke@435 492 entry->protection_domain() == domain) {
duke@435 493 // We've found a match.
duke@435 494 return entry;
duke@435 495 }
duke@435 496 }
duke@435 497
duke@435 498 if (!create_if_not_found)
duke@435 499 return NULL;
duke@435 500
duke@435 501 // This is a new unloaded klass. Create it and stick it in
duke@435 502 // the cache.
duke@435 503 ciKlass* new_klass = NULL;
duke@435 504
coleenp@4142 505 // Two cases: this is an unloaded ObjArrayKlass or an
coleenp@4037 506 // unloaded InstanceKlass. Deal with both.
duke@435 507 if (name->byte_at(0) == '[') {
duke@435 508 // Decompose the name.'
coleenp@2497 509 FieldArrayInfo fd;
coleenp@2497 510 BasicType element_type = FieldType::get_array_info(name->get_symbol(),
coleenp@2497 511 fd, THREAD);
duke@435 512 if (HAS_PENDING_EXCEPTION) {
duke@435 513 CLEAR_PENDING_EXCEPTION;
duke@435 514 CURRENT_THREAD_ENV->record_out_of_memory_failure();
duke@435 515 return ciEnv::_unloaded_ciobjarrayklass;
duke@435 516 }
coleenp@2497 517 int dimension = fd.dimension();
duke@435 518 assert(element_type != T_ARRAY, "unsuccessful decomposition");
duke@435 519 ciKlass* element_klass = NULL;
duke@435 520 if (element_type == T_OBJECT) {
duke@435 521 ciEnv *env = CURRENT_THREAD_ENV;
coleenp@2497 522 ciSymbol* ci_name = env->get_symbol(fd.object_key());
duke@435 523 element_klass =
duke@435 524 env->get_klass_by_name(accessing_klass, ci_name, false)->as_instance_klass();
duke@435 525 } else {
duke@435 526 assert(dimension > 1, "one dimensional type arrays are always loaded.");
duke@435 527
duke@435 528 // The type array itself takes care of one of the dimensions.
duke@435 529 dimension--;
duke@435 530
coleenp@4142 531 // The element klass is a TypeArrayKlass.
duke@435 532 element_klass = ciTypeArrayKlass::make(element_type);
duke@435 533 }
duke@435 534 new_klass = new (arena()) ciObjArrayKlass(name, element_klass, dimension);
duke@435 535 } else {
duke@435 536 jobject loader_handle = NULL;
duke@435 537 jobject domain_handle = NULL;
duke@435 538 if (accessing_klass != NULL) {
duke@435 539 loader_handle = accessing_klass->loader_handle();
duke@435 540 domain_handle = accessing_klass->protection_domain_handle();
duke@435 541 }
duke@435 542 new_klass = new (arena()) ciInstanceKlass(name, loader_handle, domain_handle);
duke@435 543 }
duke@435 544 init_ident_of(new_klass);
duke@435 545 _unloaded_klasses->append(new_klass);
duke@435 546
duke@435 547 return new_klass;
duke@435 548 }
duke@435 549
jrose@1957 550
jrose@1957 551 //------------------------------------------------------------------
jrose@1957 552 // ciObjectFactory::get_unloaded_instance
jrose@1957 553 //
jrose@1957 554 // Get a ciInstance representing an as-yet undetermined instance of a given class.
jrose@1957 555 //
jrose@1957 556 ciInstance* ciObjectFactory::get_unloaded_instance(ciInstanceKlass* instance_klass) {
jrose@1957 557 for (int i=0; i<_unloaded_instances->length(); i++) {
jrose@1957 558 ciInstance* entry = _unloaded_instances->at(i);
jrose@1957 559 if (entry->klass()->equals(instance_klass)) {
jrose@1957 560 // We've found a match.
jrose@1957 561 return entry;
jrose@1957 562 }
jrose@1957 563 }
jrose@1957 564
jrose@1957 565 // This is a new unloaded instance. Create it and stick it in
jrose@1957 566 // the cache.
jrose@1957 567 ciInstance* new_instance = new (arena()) ciInstance(instance_klass);
jrose@1957 568
jrose@1957 569 init_ident_of(new_instance);
jrose@1957 570 _unloaded_instances->append(new_instance);
jrose@1957 571
jrose@1957 572 // make sure it looks the way we want:
jrose@1957 573 assert(!new_instance->is_loaded(), "");
jrose@1957 574 assert(new_instance->klass() == instance_klass, "");
jrose@1957 575
jrose@1957 576 return new_instance;
jrose@1957 577 }
jrose@1957 578
jrose@1957 579
jrose@1957 580 //------------------------------------------------------------------
jrose@1957 581 // ciObjectFactory::get_unloaded_klass_mirror
jrose@1957 582 //
jrose@1957 583 // Get a ciInstance representing an unresolved klass mirror.
jrose@1957 584 //
jrose@1957 585 // Currently, this ignores the parameters and returns a unique unloaded instance.
jrose@1957 586 ciInstance* ciObjectFactory::get_unloaded_klass_mirror(ciKlass* type) {
jrose@1957 587 assert(ciEnv::_Class_klass != NULL, "");
jrose@1957 588 return get_unloaded_instance(ciEnv::_Class_klass->as_instance_klass());
jrose@1957 589 }
jrose@1957 590
jrose@1957 591 //------------------------------------------------------------------
jrose@1957 592 // ciObjectFactory::get_unloaded_method_handle_constant
jrose@1957 593 //
jrose@1957 594 // Get a ciInstance representing an unresolved method handle constant.
jrose@1957 595 //
jrose@1957 596 // Currently, this ignores the parameters and returns a unique unloaded instance.
jrose@1957 597 ciInstance* ciObjectFactory::get_unloaded_method_handle_constant(ciKlass* holder,
jrose@1957 598 ciSymbol* name,
jrose@1957 599 ciSymbol* signature,
jrose@1957 600 int ref_kind) {
jrose@1957 601 if (ciEnv::_MethodHandle_klass == NULL) return NULL;
jrose@1957 602 return get_unloaded_instance(ciEnv::_MethodHandle_klass->as_instance_klass());
jrose@1957 603 }
jrose@1957 604
jrose@1957 605 //------------------------------------------------------------------
jrose@1957 606 // ciObjectFactory::get_unloaded_method_type_constant
jrose@1957 607 //
jrose@1957 608 // Get a ciInstance representing an unresolved method type constant.
jrose@1957 609 //
jrose@1957 610 // Currently, this ignores the parameters and returns a unique unloaded instance.
jrose@1957 611 ciInstance* ciObjectFactory::get_unloaded_method_type_constant(ciSymbol* signature) {
jrose@1957 612 if (ciEnv::_MethodType_klass == NULL) return NULL;
jrose@1957 613 return get_unloaded_instance(ciEnv::_MethodType_klass->as_instance_klass());
jrose@1957 614 }
jrose@1957 615
roland@5628 616 ciInstance* ciObjectFactory::get_unloaded_object_constant() {
roland@5628 617 if (ciEnv::_Object_klass == NULL) return NULL;
roland@5628 618 return get_unloaded_instance(ciEnv::_Object_klass->as_instance_klass());
roland@5628 619 }
jrose@1957 620
duke@435 621 //------------------------------------------------------------------
duke@435 622 // ciObjectFactory::get_empty_methodData
duke@435 623 //
duke@435 624 // Get the ciMethodData representing the methodData for a method with
duke@435 625 // none.
duke@435 626 ciMethodData* ciObjectFactory::get_empty_methodData() {
duke@435 627 ciMethodData* new_methodData = new (arena()) ciMethodData();
duke@435 628 init_ident_of(new_methodData);
duke@435 629 return new_methodData;
duke@435 630 }
duke@435 631
duke@435 632 //------------------------------------------------------------------
duke@435 633 // ciObjectFactory::get_return_address
duke@435 634 //
duke@435 635 // Get a ciReturnAddress for a specified bci.
duke@435 636 ciReturnAddress* ciObjectFactory::get_return_address(int bci) {
duke@435 637 for (int i=0; i<_return_addresses->length(); i++) {
duke@435 638 ciReturnAddress* entry = _return_addresses->at(i);
duke@435 639 if (entry->bci() == bci) {
duke@435 640 // We've found a match.
duke@435 641 return entry;
duke@435 642 }
duke@435 643 }
duke@435 644
duke@435 645 ciReturnAddress* new_ret_addr = new (arena()) ciReturnAddress(bci);
duke@435 646 init_ident_of(new_ret_addr);
duke@435 647 _return_addresses->append(new_ret_addr);
duke@435 648 return new_ret_addr;
duke@435 649 }
duke@435 650
duke@435 651 // ------------------------------------------------------------------
duke@435 652 // ciObjectFactory::init_ident_of
coleenp@4037 653 void ciObjectFactory::init_ident_of(ciBaseObject* obj) {
duke@435 654 obj->set_ident(_next_ident++);
duke@435 655 }
duke@435 656
duke@435 657 // ------------------------------------------------------------------
duke@435 658 // ciObjectFactory::find
duke@435 659 //
duke@435 660 // Use binary search to find the position of this oop in the cache.
duke@435 661 // If there is no entry in the cache corresponding to this oop, return
duke@435 662 // the position at which the oop should be inserted.
coleenp@4037 663 int ciObjectFactory::find(Metadata* key, GrowableArray<ciMetadata*>* objects) {
duke@435 664 int min = 0;
duke@435 665 int max = objects->length()-1;
duke@435 666
duke@435 667 // print_contents();
duke@435 668
duke@435 669 while (max >= min) {
duke@435 670 int mid = (max + min) / 2;
coleenp@4037 671 Metadata* value = objects->at(mid)->constant_encoding();
duke@435 672 if (value < key) {
duke@435 673 min = mid + 1;
duke@435 674 } else if (value > key) {
duke@435 675 max = mid - 1;
duke@435 676 } else {
duke@435 677 return mid;
duke@435 678 }
duke@435 679 }
duke@435 680 return min;
duke@435 681 }
duke@435 682
duke@435 683 // ------------------------------------------------------------------
duke@435 684 // ciObjectFactory::is_found_at
duke@435 685 //
duke@435 686 // Verify that the binary seach found the given key.
coleenp@4037 687 bool ciObjectFactory::is_found_at(int index, Metadata* key, GrowableArray<ciMetadata*>* objects) {
duke@435 688 return (index < objects->length() &&
coleenp@4037 689 objects->at(index)->constant_encoding() == key);
duke@435 690 }
duke@435 691
duke@435 692
duke@435 693 // ------------------------------------------------------------------
duke@435 694 // ciObjectFactory::insert
duke@435 695 //
duke@435 696 // Insert a ciObject into the table at some index.
coleenp@4037 697 void ciObjectFactory::insert(int index, ciMetadata* obj, GrowableArray<ciMetadata*>* objects) {
duke@435 698 int len = objects->length();
duke@435 699 if (len == index) {
duke@435 700 objects->append(obj);
duke@435 701 } else {
duke@435 702 objects->append(objects->at(len-1));
duke@435 703 int pos;
duke@435 704 for (pos = len-2; pos >= index; pos--) {
duke@435 705 objects->at_put(pos+1,objects->at(pos));
duke@435 706 }
duke@435 707 objects->at_put(index, obj);
duke@435 708 }
duke@435 709 }
duke@435 710
duke@435 711 static ciObjectFactory::NonPermObject* emptyBucket = NULL;
duke@435 712
duke@435 713 // ------------------------------------------------------------------
duke@435 714 // ciObjectFactory::find_non_perm
duke@435 715 //
duke@435 716 // Use a small hash table, hashed on the klass of the key.
duke@435 717 // If there is no entry in the cache corresponding to this oop, return
duke@435 718 // the null tail of the bucket into which the oop should be inserted.
duke@435 719 ciObjectFactory::NonPermObject* &ciObjectFactory::find_non_perm(oop key) {
vlivanov@7384 720 assert(Universe::heap()->is_in_reserved(key), "must be");
coleenp@4037 721 ciMetadata* klass = get_metadata(key->klass());
duke@435 722 NonPermObject* *bp = &_non_perm_bucket[(unsigned) klass->hash() % NON_PERM_BUCKETS];
duke@435 723 for (NonPermObject* p; (p = (*bp)) != NULL; bp = &p->next()) {
duke@435 724 if (is_equal(p, key)) break;
duke@435 725 }
duke@435 726 return (*bp);
duke@435 727 }
duke@435 728
duke@435 729
duke@435 730
duke@435 731 // ------------------------------------------------------------------
duke@435 732 // Code for for NonPermObject
duke@435 733 //
duke@435 734 inline ciObjectFactory::NonPermObject::NonPermObject(ciObjectFactory::NonPermObject* &bucket, oop key, ciObject* object) {
duke@435 735 assert(ciObjectFactory::is_initialized(), "");
duke@435 736 _object = object;
duke@435 737 _next = bucket;
duke@435 738 bucket = this;
duke@435 739 }
duke@435 740
duke@435 741
duke@435 742
duke@435 743 // ------------------------------------------------------------------
duke@435 744 // ciObjectFactory::insert_non_perm
duke@435 745 //
duke@435 746 // Insert a ciObject into the non-perm table.
duke@435 747 void ciObjectFactory::insert_non_perm(ciObjectFactory::NonPermObject* &where, oop key, ciObject* obj) {
coleenp@4037 748 assert(Universe::heap()->is_in_reserved_or_null(key), "must be");
duke@435 749 assert(&where != &emptyBucket, "must not try to fill empty bucket");
duke@435 750 NonPermObject* p = new (arena()) NonPermObject(where, key, obj);
duke@435 751 assert(where == p && is_equal(p, key) && p->object() == obj, "entry must match");
duke@435 752 assert(find_non_perm(key) == p, "must find the same spot");
duke@435 753 ++_non_perm_count;
duke@435 754 }
duke@435 755
duke@435 756 // ------------------------------------------------------------------
duke@435 757 // ciObjectFactory::vm_symbol_at
duke@435 758 // Get the ciSymbol corresponding to some index in vmSymbols.
duke@435 759 ciSymbol* ciObjectFactory::vm_symbol_at(int index) {
duke@435 760 assert(index >= vmSymbols::FIRST_SID && index < vmSymbols::SID_LIMIT, "oob");
duke@435 761 return _shared_ci_symbols[index];
duke@435 762 }
duke@435 763
duke@435 764 // ------------------------------------------------------------------
coleenp@4037 765 // ciObjectFactory::metadata_do
coleenp@4037 766 void ciObjectFactory::metadata_do(void f(Metadata*)) {
coleenp@4037 767 if (_ci_metadata == NULL) return;
coleenp@4037 768 for (int j = 0; j< _ci_metadata->length(); j++) {
coleenp@4037 769 Metadata* o = _ci_metadata->at(j)->constant_encoding();
coleenp@4037 770 f(o);
coleenp@4037 771 }
coleenp@4037 772 }
coleenp@4037 773
coleenp@4037 774 // ------------------------------------------------------------------
duke@435 775 // ciObjectFactory::print_contents_impl
duke@435 776 void ciObjectFactory::print_contents_impl() {
coleenp@4037 777 int len = _ci_metadata->length();
coleenp@4037 778 tty->print_cr("ciObjectFactory (%d) meta data contents:", len);
duke@435 779 for (int i=0; i<len; i++) {
coleenp@4037 780 _ci_metadata->at(i)->print();
duke@435 781 tty->cr();
duke@435 782 }
duke@435 783 }
duke@435 784
duke@435 785 // ------------------------------------------------------------------
duke@435 786 // ciObjectFactory::print_contents
duke@435 787 void ciObjectFactory::print_contents() {
duke@435 788 print();
duke@435 789 tty->cr();
duke@435 790 GUARDED_VM_ENTRY(print_contents_impl();)
duke@435 791 }
duke@435 792
duke@435 793 // ------------------------------------------------------------------
duke@435 794 // ciObjectFactory::print
duke@435 795 //
duke@435 796 // Print debugging information about the object factory
duke@435 797 void ciObjectFactory::print() {
coleenp@4037 798 tty->print("<ciObjectFactory oops=%d metadata=%d unloaded_methods=%d unloaded_instances=%d unloaded_klasses=%d>",
coleenp@4037 799 _non_perm_count, _ci_metadata->length(), _unloaded_methods->length(),
jrose@1957 800 _unloaded_instances->length(),
duke@435 801 _unloaded_klasses->length());
duke@435 802 }

mercurial