< prev index next >

src/hotspot/share/oops/cpCache.cpp

Print this page

  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  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"

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   }
427   if (_resolved_method_entries != nullptr) {
428     MetadataFactory::free_array<ResolvedMethodEntry>(data, _resolved_method_entries);
429     _resolved_method_entries = nullptr;
430   }
431 #endif

  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  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/cdsConfig.hpp"
 27 #include "cds/heapShared.hpp"
 28 #include "classfile/resolutionErrors.hpp"
 29 #include "classfile/systemDictionary.hpp"
 30 #include "classfile/systemDictionaryShared.hpp"
 31 #include "classfile/vmClasses.hpp"
 32 #include "code/codeCache.hpp"
 33 #include "interpreter/bytecodeStream.hpp"
 34 #include "interpreter/bytecodes.hpp"
 35 #include "interpreter/interpreter.hpp"
 36 #include "interpreter/linkResolver.hpp"
 37 #include "interpreter/rewriter.hpp"
 38 #include "logging/log.hpp"
 39 #include "logging/logStream.hpp"
 40 #include "memory/metadataFactory.hpp"
 41 #include "memory/metaspaceClosure.hpp"
 42 #include "memory/resourceArea.hpp"
 43 #include "oops/access.inline.hpp"
 44 #include "oops/compressedOops.hpp"
 45 #include "oops/constantPool.inline.hpp"

155     }
156     default:
157       ShouldNotReachHere();
158       break;
159   }
160 
161   // Note:  byte_no also appears in TemplateTable::resolve.
162   if (byte_no == 1) {
163     assert(invoke_code != Bytecodes::_invokevirtual &&
164            invoke_code != Bytecodes::_invokeinterface, "");
165     bool do_resolve = true;
166     // Don't mark invokespecial to method as resolved if sender is an interface.  The receiver
167     // has to be checked that it is a subclass of the current class every time this bytecode
168     // is executed.
169     if (invoke_code == Bytecodes::_invokespecial && sender_is_interface &&
170         method->name() != vmSymbols::object_initializer_name()) {
171       do_resolve = false;
172     }
173     if (invoke_code == Bytecodes::_invokestatic) {
174       assert(method->method_holder()->is_initialized() ||
175              method->method_holder()->is_init_thread(JavaThread::current()) ||
176              (CDSConfig::is_dumping_archive() && VM_Version::supports_fast_class_init_checks()),
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 #if 0
364  else {
365     assert(is_field_entry(), "must be a field entry");
366     st->print_cr(" - F1:  [   " PTR_FORMAT "]", (intptr_t)_f1);
367     st->print_cr(" - F2:  [   " PTR_FORMAT "]", (intptr_t)_f2);
368     st->print_cr(" - flag values: [%02x|0|1|0|0|0|%01x|%01x|0|0|%04x]",
369                  flag_state(), is_final(), is_volatile(), field_index());
370     st->print_cr(" - tos: %s\n - final: %d\n - volatile: %d\n - field index: %04x",
371                  type2name(as_BasicType(flag_state())), is_final(), is_volatile(), field_index());
372   }
373   st->print_cr("                 -------------");
374 #endif
375 }
376 
377 ConstantPoolCache* ConstantPoolCache::allocate(ClassLoaderData* loader_data,
378                                      const intStack& invokedynamic_map,
379                                      const GrowableArray<ResolvedIndyEntry> indy_entries,
380                                      const GrowableArray<ResolvedFieldEntry> field_entries,
381                                      const GrowableArray<ResolvedMethodEntry> method_entries,
382                                      TRAPS) {
383 
384   int size = ConstantPoolCache::size();
385 
386   // Initialize resolved entry arrays with available data
387   Array<ResolvedFieldEntry>* resolved_field_entries = initialize_resolved_entries_array(loader_data, field_entries, CHECK_NULL);
388   Array<ResolvedIndyEntry>* resolved_indy_entries = initialize_resolved_entries_array(loader_data, indy_entries, CHECK_NULL);
389   Array<ResolvedMethodEntry>* resolved_method_entries = initialize_resolved_entries_array(loader_data, method_entries, CHECK_NULL);
390 
391   return new (loader_data, size, MetaspaceObj::ConstantPoolCacheType, THREAD)
392               ConstantPoolCache(invokedynamic_map, resolved_indy_entries, resolved_field_entries, resolved_method_entries);
393 }
394 
395 // Record the GC marking cycle when redefined vs. when found in the loom stack chunks.
396 void ConstantPoolCache::record_gc_epoch() {
397   _gc_epoch = CodeCache::gc_epoch();
398 }
399 
























400 void ConstantPoolCache::deallocate_contents(ClassLoaderData* data) {
401   assert(!is_shared(), "shared caches are not deallocated");
402   data->remove_handle(_resolved_references);
403   set_resolved_references(OopHandle());
404   MetadataFactory::free_array<u2>(data, _reference_map);
405   set_reference_map(nullptr);
406 #if INCLUDE_CDS
407   if (_resolved_indy_entries != nullptr) {
408     MetadataFactory::free_array<ResolvedIndyEntry>(data, _resolved_indy_entries);
409     _resolved_indy_entries = nullptr;
410   }
411   if (_resolved_field_entries != nullptr) {
412     MetadataFactory::free_array<ResolvedFieldEntry>(data, _resolved_field_entries);
413     _resolved_field_entries = nullptr;
414   }
415   if (_resolved_method_entries != nullptr) {
416     MetadataFactory::free_array<ResolvedMethodEntry>(data, _resolved_method_entries);
417     _resolved_method_entries = nullptr;
418   }
419 #endif
< prev index next >