< prev index next >

src/hotspot/share/oops/cpCache.cpp

Print this page

  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "cds/archiveBuilder.hpp"
 27 #include "cds/cdsConfig.hpp"

 28 #include "cds/heapShared.hpp"
 29 #include "classfile/resolutionErrors.hpp"
 30 #include "classfile/systemDictionary.hpp"
 31 #include "classfile/systemDictionaryShared.hpp"
 32 #include "classfile/vmClasses.hpp"
 33 #include "code/codeCache.hpp"
 34 #include "interpreter/bytecodeStream.hpp"
 35 #include "interpreter/bytecodes.hpp"
 36 #include "interpreter/interpreter.hpp"
 37 #include "interpreter/linkResolver.hpp"
 38 #include "interpreter/rewriter.hpp"
 39 #include "logging/log.hpp"
 40 #include "logging/logStream.hpp"
 41 #include "memory/metadataFactory.hpp"
 42 #include "memory/metaspaceClosure.hpp"
 43 #include "memory/resourceArea.hpp"
 44 #include "oops/access.inline.hpp"
 45 #include "oops/compressedOops.hpp"
 46 #include "oops/constantPool.inline.hpp"
 47 #include "oops/cpCache.inline.hpp"

156     }
157     default:
158       ShouldNotReachHere();
159       break;
160   }
161 
162   // Note:  byte_no also appears in TemplateTable::resolve.
163   if (byte_no == 1) {
164     assert(invoke_code != Bytecodes::_invokevirtual &&
165            invoke_code != Bytecodes::_invokeinterface, "");
166     bool do_resolve = true;
167     // Don't mark invokespecial to method as resolved if sender is an interface.  The receiver
168     // has to be checked that it is a subclass of the current class every time this bytecode
169     // is executed.
170     if (invoke_code == Bytecodes::_invokespecial && sender_is_interface &&
171         method->name() != vmSymbols::object_initializer_name()) {
172       do_resolve = false;
173     }
174     if (invoke_code == Bytecodes::_invokestatic) {
175       assert(method->method_holder()->is_initialized() ||
176              method->method_holder()->is_init_thread(JavaThread::current()),

177              "invalid class initialization state for invoke_static");
178 
179       if (!VM_Version::supports_fast_class_init_checks() && method->needs_clinit_barrier()) {
180         // Don't mark invokestatic to method as resolved if the holder class has not yet completed
181         // initialization. An invokestatic must only proceed if the class is initialized, but if
182         // we resolve it before then that class initialization check is skipped.
183         //
184         // When fast class initialization checks are supported (VM_Version::supports_fast_class_init_checks() == true),
185         // template interpreter supports fast class initialization check for
186         // invokestatic which doesn't require call site re-resolution to
187         // enforce class initialization barrier.
188         do_resolve = false;
189       }
190     }
191     if (do_resolve) {
192       method_entry->set_bytecode1(invoke_code);
193     }
194   } else if (byte_no == 2)  {
195     if (change_to_virtual) {
196       assert(invoke_code == Bytecodes::_invokeinterface, "");

343     case Bytecodes::_invokedynamic:
344       ShouldNotReachHere();
345     default:
346       assert(invoke_code == (Bytecodes::Code)0, "unexpected bytecode");
347       break;
348   }
349 
350   invoke_code = (Bytecodes::Code)method_entry->bytecode2();
351   if (invoke_code == Bytecodes::_invokevirtual) {
352     if (method_entry->is_vfinal()) {
353       return method_entry->method();
354     } else {
355       int holder_index = constant_pool()->uncached_klass_ref_index_at(method_entry->constant_pool_index());
356       if (constant_pool()->tag_at(holder_index).is_klass()) {
357         Klass* klass = constant_pool()->resolved_klass_at(holder_index);
358         return klass->method_at_vtable(method_entry->table_index());
359       }
360     }
361   }
362   return nullptr;












363 }
364 
365 ConstantPoolCache* ConstantPoolCache::allocate(ClassLoaderData* loader_data,
366                                      const intStack& invokedynamic_map,
367                                      const GrowableArray<ResolvedIndyEntry> indy_entries,
368                                      const GrowableArray<ResolvedFieldEntry> field_entries,
369                                      const GrowableArray<ResolvedMethodEntry> method_entries,
370                                      TRAPS) {
371 
372   int size = ConstantPoolCache::size();
373 
374   // Initialize resolved entry arrays with available data
375   Array<ResolvedFieldEntry>* resolved_field_entries = initialize_resolved_entries_array(loader_data, field_entries, CHECK_NULL);
376   Array<ResolvedIndyEntry>* resolved_indy_entries = initialize_resolved_entries_array(loader_data, indy_entries, CHECK_NULL);
377   Array<ResolvedMethodEntry>* resolved_method_entries = initialize_resolved_entries_array(loader_data, method_entries, CHECK_NULL);
378 
379   return new (loader_data, size, MetaspaceObj::ConstantPoolCacheType, THREAD)
380               ConstantPoolCache(invokedynamic_map, resolved_indy_entries, resolved_field_entries, resolved_method_entries);
381 }
382 
383 // Record the GC marking cycle when redefined vs. when found in the loom stack chunks.
384 void ConstantPoolCache::record_gc_epoch() {
385   _gc_epoch = CodeCache::gc_epoch();
386 }
387 
388 #if INCLUDE_CDS
389 void ConstantPoolCache::remove_unshareable_info() {
390   assert(CDSConfig::is_dumping_archive(), "sanity");
391   // <this> is the copy to be written into the archive. It's in the ArchiveBuilder's "buffer space".
392   // However, this->_initial_entries was not copied/relocated by the ArchiveBuilder, so it's
393   // still pointing to the array allocated inside save_for_archive().
394   if (_resolved_indy_entries != nullptr) {
395     for (int i = 0; i < _resolved_indy_entries->length(); i++) {
396       resolved_indy_entry_at(i)->remove_unshareable_info();




















397     }
398   }

399   if (_resolved_field_entries != nullptr) {
400     for (int i = 0; i < _resolved_field_entries->length(); i++) {
401       resolved_field_entry_at(i)->remove_unshareable_info();























402     }
403   }

404   if (_resolved_method_entries != nullptr) {
405     for (int i = 0; i < _resolved_method_entries->length(); i++) {
406       resolved_method_entry_at(i)->remove_unshareable_info();








407     }
408   }
409 }
410 #endif // INCLUDE_CDS
411 
412 void ConstantPoolCache::deallocate_contents(ClassLoaderData* data) {
413   assert(!is_shared(), "shared caches are not deallocated");
414   data->remove_handle(_resolved_references);
415   set_resolved_references(OopHandle());
416   MetadataFactory::free_array<u2>(data, _reference_map);
417   set_reference_map(nullptr);
418 #if INCLUDE_CDS
419   if (_resolved_indy_entries != nullptr) {
420     MetadataFactory::free_array<ResolvedIndyEntry>(data, _resolved_indy_entries);
421     _resolved_indy_entries = nullptr;
422   }
423   if (_resolved_field_entries != nullptr) {
424     MetadataFactory::free_array<ResolvedFieldEntry>(data, _resolved_field_entries);
425     _resolved_field_entries = nullptr;
426   }

  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "cds/archiveBuilder.hpp"
 27 #include "cds/cdsConfig.hpp"
 28 #include "cds/classPrelinker.hpp"
 29 #include "cds/heapShared.hpp"
 30 #include "classfile/resolutionErrors.hpp"
 31 #include "classfile/systemDictionary.hpp"
 32 #include "classfile/systemDictionaryShared.hpp"
 33 #include "classfile/vmClasses.hpp"
 34 #include "code/codeCache.hpp"
 35 #include "interpreter/bytecodeStream.hpp"
 36 #include "interpreter/bytecodes.hpp"
 37 #include "interpreter/interpreter.hpp"
 38 #include "interpreter/linkResolver.hpp"
 39 #include "interpreter/rewriter.hpp"
 40 #include "logging/log.hpp"
 41 #include "logging/logStream.hpp"
 42 #include "memory/metadataFactory.hpp"
 43 #include "memory/metaspaceClosure.hpp"
 44 #include "memory/resourceArea.hpp"
 45 #include "oops/access.inline.hpp"
 46 #include "oops/compressedOops.hpp"
 47 #include "oops/constantPool.inline.hpp"
 48 #include "oops/cpCache.inline.hpp"

157     }
158     default:
159       ShouldNotReachHere();
160       break;
161   }
162 
163   // Note:  byte_no also appears in TemplateTable::resolve.
164   if (byte_no == 1) {
165     assert(invoke_code != Bytecodes::_invokevirtual &&
166            invoke_code != Bytecodes::_invokeinterface, "");
167     bool do_resolve = true;
168     // Don't mark invokespecial to method as resolved if sender is an interface.  The receiver
169     // has to be checked that it is a subclass of the current class every time this bytecode
170     // is executed.
171     if (invoke_code == Bytecodes::_invokespecial && sender_is_interface &&
172         method->name() != vmSymbols::object_initializer_name()) {
173       do_resolve = false;
174     }
175     if (invoke_code == Bytecodes::_invokestatic) {
176       assert(method->method_holder()->is_initialized() ||
177              method->method_holder()->is_init_thread(JavaThread::current()) ||
178              (CDSConfig::is_dumping_archive() && VM_Version::supports_fast_class_init_checks()),
179              "invalid class initialization state for invoke_static");
180 
181       if (!VM_Version::supports_fast_class_init_checks() && method->needs_clinit_barrier()) {
182         // Don't mark invokestatic to method as resolved if the holder class has not yet completed
183         // initialization. An invokestatic must only proceed if the class is initialized, but if
184         // we resolve it before then that class initialization check is skipped.
185         //
186         // When fast class initialization checks are supported (VM_Version::supports_fast_class_init_checks() == true),
187         // template interpreter supports fast class initialization check for
188         // invokestatic which doesn't require call site re-resolution to
189         // enforce class initialization barrier.
190         do_resolve = false;
191       }
192     }
193     if (do_resolve) {
194       method_entry->set_bytecode1(invoke_code);
195     }
196   } else if (byte_no == 2)  {
197     if (change_to_virtual) {
198       assert(invoke_code == Bytecodes::_invokeinterface, "");

345     case Bytecodes::_invokedynamic:
346       ShouldNotReachHere();
347     default:
348       assert(invoke_code == (Bytecodes::Code)0, "unexpected bytecode");
349       break;
350   }
351 
352   invoke_code = (Bytecodes::Code)method_entry->bytecode2();
353   if (invoke_code == Bytecodes::_invokevirtual) {
354     if (method_entry->is_vfinal()) {
355       return method_entry->method();
356     } else {
357       int holder_index = constant_pool()->uncached_klass_ref_index_at(method_entry->constant_pool_index());
358       if (constant_pool()->tag_at(holder_index).is_klass()) {
359         Klass* klass = constant_pool()->resolved_klass_at(holder_index);
360         return klass->method_at_vtable(method_entry->table_index());
361       }
362     }
363   }
364   return nullptr;
365 #if 0
366  else {
367     assert(is_field_entry(), "must be a field entry");
368     st->print_cr(" - F1:  [   " PTR_FORMAT "]", (intptr_t)_f1);
369     st->print_cr(" - F2:  [   " PTR_FORMAT "]", (intptr_t)_f2);
370     st->print_cr(" - flag values: [%02x|0|1|0|0|0|%01x|%01x|0|0|%04x]",
371                  flag_state(), is_final(), is_volatile(), field_index());
372     st->print_cr(" - tos: %s\n - final: %d\n - volatile: %d\n - field index: %04x",
373                  type2name(as_BasicType(flag_state())), is_final(), is_volatile(), field_index());
374   }
375   st->print_cr("                 -------------");
376 #endif
377 }
378 
379 ConstantPoolCache* ConstantPoolCache::allocate(ClassLoaderData* loader_data,
380                                      const intStack& invokedynamic_map,
381                                      const GrowableArray<ResolvedIndyEntry> indy_entries,
382                                      const GrowableArray<ResolvedFieldEntry> field_entries,
383                                      const GrowableArray<ResolvedMethodEntry> method_entries,
384                                      TRAPS) {
385 
386   int size = ConstantPoolCache::size();
387 
388   // Initialize resolved entry arrays with available data
389   Array<ResolvedFieldEntry>* resolved_field_entries = initialize_resolved_entries_array(loader_data, field_entries, CHECK_NULL);
390   Array<ResolvedIndyEntry>* resolved_indy_entries = initialize_resolved_entries_array(loader_data, indy_entries, CHECK_NULL);
391   Array<ResolvedMethodEntry>* resolved_method_entries = initialize_resolved_entries_array(loader_data, method_entries, CHECK_NULL);
392 
393   return new (loader_data, size, MetaspaceObj::ConstantPoolCacheType, THREAD)
394               ConstantPoolCache(invokedynamic_map, resolved_indy_entries, resolved_field_entries, resolved_method_entries);
395 }
396 
397 // Record the GC marking cycle when redefined vs. when found in the loom stack chunks.
398 void ConstantPoolCache::record_gc_epoch() {
399   _gc_epoch = CodeCache::gc_epoch();
400 }
401 
402 #if INCLUDE_CDS
403 void ConstantPoolCache::remove_unshareable_info() {
404   assert(CDSConfig::is_dumping_archive(), "sanity");
405   ConstantPool* cp = constant_pool();
406   ConstantPool* src_cp =  ArchiveBuilder::current()->get_source_addr(cp);
407 
408   if (_resolved_indy_entries != nullptr) {
409     for (int i = 0; i < _resolved_indy_entries->length(); i++) {
410       ResolvedIndyEntry *rei = resolved_indy_entry_at(i);
411       int cp_index = rei->constant_pool_index();
412       bool archived = false;
413       if (rei->is_resolved() && ClassPrelinker::is_indy_archivable(src_cp, cp_index)) {
414         if (log_is_enabled(Debug, cds, resolve)) {
415           ResourceMark rm;
416           int bsm = cp->bootstrap_method_ref_index_at(cp_index);
417           int bsm_ref = cp->method_handle_index_at(bsm);
418           Symbol* bsm_name = cp->uncached_name_ref_at(bsm_ref);
419           Symbol* bsm_signature = cp->uncached_signature_ref_at(bsm_ref);
420           Symbol* bsm_klass = cp->klass_name_at(cp->uncached_klass_ref_index_at(bsm_ref));
421           log_debug(cds, resolve)("archived indy   CP entry [%3d]: %s (%d) => %s.%s:%s", cp_index,
422                                   cp->pool_holder()->name()->as_C_string(), i,
423                                   bsm_klass->as_C_string(), bsm_name->as_C_string(), bsm_signature->as_C_string());
424         }
425         rei->mark_and_relocate();
426         archived = true;
427       } else {
428         rei->remove_unshareable_info();
429       }
430       ArchiveBuilder::alloc_stats()->record_indy_cp_entry(archived);
431     }
432   }
433 
434   if (_resolved_field_entries != nullptr) {
435     for (int i = 0; i < _resolved_field_entries->length(); i++) {
436       ResolvedFieldEntry *rfi = resolved_field_entry_at(i);
437       int cp_index = rfi->constant_pool_index();
438       bool archived = false;
439       if ((rfi->is_resolved(Bytecodes::_getstatic) ||
440            rfi->is_resolved(Bytecodes::_putstatic) ||
441            rfi->is_resolved(Bytecodes::_putfield) ||
442            rfi->is_resolved(Bytecodes::_putfield)) &&
443           ClassPrelinker::can_archive_resolved_field(src_cp, cp_index)) {
444         if (log_is_enabled(Debug, cds, resolve)) {
445           ResourceMark rm;
446           int klass_cp_index = cp->uncached_klass_ref_index_at(cp_index);
447           Symbol* klass_name = cp->klass_name_at(klass_cp_index);
448           Symbol* name = cp->uncached_name_ref_at(cp_index);
449           Symbol* signature = cp->uncached_signature_ref_at(cp_index);
450           log_debug(cds, resolve)("archived field  CP entry [%3d]: %s => %s.%s:%s", cp_index,
451                                   cp->pool_holder()->name()->as_C_string(), klass_name->as_C_string(),
452                                   name->as_C_string(), signature->as_C_string());
453         }
454         rfi->mark_and_relocate();
455         archived = true;
456       } else {
457         rfi->remove_unshareable_info();
458       }
459       ArchiveBuilder::alloc_stats()->record_field_cp_entry(archived);
460     }
461   }
462 
463   if (_resolved_method_entries != nullptr) {
464     for (int i = 0; i < _resolved_method_entries->length(); i++) {
465       ResolvedMethodEntry *rme = resolved_method_entry_at(i);
466       bool archived = false;
467       if (cp->can_archive_resolved_method(rme)) {
468         rme->mark_and_relocate(src_cp);
469         archived = true;
470       } else {
471         rme->remove_unshareable_info();
472       }
473       ArchiveBuilder::alloc_stats()->record_method_cp_entry(archived);
474     }
475   }
476 }
477 #endif // INCLUDE_CDS
478 
479 void ConstantPoolCache::deallocate_contents(ClassLoaderData* data) {
480   assert(!is_shared(), "shared caches are not deallocated");
481   data->remove_handle(_resolved_references);
482   set_resolved_references(OopHandle());
483   MetadataFactory::free_array<u2>(data, _reference_map);
484   set_reference_map(nullptr);
485 #if INCLUDE_CDS
486   if (_resolved_indy_entries != nullptr) {
487     MetadataFactory::free_array<ResolvedIndyEntry>(data, _resolved_indy_entries);
488     _resolved_indy_entries = nullptr;
489   }
490   if (_resolved_field_entries != nullptr) {
491     MetadataFactory::free_array<ResolvedFieldEntry>(data, _resolved_field_entries);
492     _resolved_field_entries = nullptr;
493   }
< prev index next >