Path: blob/jdk8u272-b10-aarch32-20201026/hotspot/src/share/vm/code/codeBlob.cpp
48785 views
/*1* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "code/codeBlob.hpp"26#include "code/codeCache.hpp"27#include "code/relocInfo.hpp"28#include "compiler/disassembler.hpp"29#include "interpreter/bytecode.hpp"30#include "memory/allocation.inline.hpp"31#include "memory/heap.hpp"32#include "oops/oop.inline.hpp"33#include "prims/forte.hpp"34#include "runtime/handles.inline.hpp"35#include "runtime/interfaceSupport.hpp"36#include "runtime/mutexLocker.hpp"37#include "runtime/safepoint.hpp"38#include "runtime/sharedRuntime.hpp"39#include "runtime/vframe.hpp"40#include "services/memoryService.hpp"41#ifdef TARGET_ARCH_x8642# include "nativeInst_x86.hpp"43#endif44#ifdef TARGET_ARCH_aarch6445# include "nativeInst_aarch64.hpp"46#endif47#ifdef TARGET_ARCH_sparc48# include "nativeInst_sparc.hpp"49#endif50#ifdef TARGET_ARCH_zero51# include "nativeInst_zero.hpp"52#endif53#ifdef TARGET_ARCH_arm54# include "nativeInst_arm.hpp"55#endif56#ifdef TARGET_ARCH_ppc57# include "nativeInst_ppc.hpp"58#endif59#ifdef TARGET_ARCH_aarch3260# include "nativeInst_aarch32.hpp"61#endif62#ifdef COMPILER163#include "c1/c1_Runtime1.hpp"64#endif6566unsigned int CodeBlob::align_code_offset(int offset) {67// align the size to CodeEntryAlignment68return69((offset + (int)CodeHeap::header_size() + (CodeEntryAlignment-1)) & ~(CodeEntryAlignment-1))70- (int)CodeHeap::header_size();71}727374// This must be consistent with the CodeBlob constructor's layout actions.75unsigned int CodeBlob::allocation_size(CodeBuffer* cb, int header_size) {76unsigned int size = header_size;77size += round_to(cb->total_relocation_size(), oopSize);78// align the size to CodeEntryAlignment79size = align_code_offset(size);80size += round_to(cb->total_content_size(), oopSize);81size += round_to(cb->total_oop_size(), oopSize);82size += round_to(cb->total_metadata_size(), oopSize);83return size;84}858687// Creates a simple CodeBlob. Sets up the size of the different regions.88CodeBlob::CodeBlob(const char* name, int header_size, int size, int frame_complete, int locs_size) {89assert(size == round_to(size, oopSize), "unaligned size");90assert(locs_size == round_to(locs_size, oopSize), "unaligned size");91assert(header_size == round_to(header_size, oopSize), "unaligned size");92assert(!UseRelocIndex, "no space allocated for reloc index yet");9394// Note: If UseRelocIndex is enabled, there needs to be (at least) one95// extra word for the relocation information, containing the reloc96// index table length. Unfortunately, the reloc index table imple-97// mentation is not easily understandable and thus it is not clear98// what exactly the format is supposed to be. For now, we just turn99// off the use of this table (gri 7/6/2000).100101_name = name;102_size = size;103_frame_complete_offset = frame_complete;104_header_size = header_size;105_relocation_size = locs_size;106_content_offset = align_code_offset(header_size + _relocation_size);107_code_offset = _content_offset;108_data_offset = size;109_frame_size = 0;110set_oop_maps(NULL);111}112113114// Creates a CodeBlob from a CodeBuffer. Sets up the size of the different regions,115// and copy code and relocation info.116CodeBlob::CodeBlob(117const char* name,118CodeBuffer* cb,119int header_size,120int size,121int frame_complete,122int frame_size,123OopMapSet* oop_maps124) {125assert(size == round_to(size, oopSize), "unaligned size");126assert(header_size == round_to(header_size, oopSize), "unaligned size");127128_name = name;129_size = size;130_frame_complete_offset = frame_complete;131_header_size = header_size;132_relocation_size = round_to(cb->total_relocation_size(), oopSize);133_content_offset = align_code_offset(header_size + _relocation_size);134_code_offset = _content_offset + cb->total_offset_of(cb->insts());135_data_offset = _content_offset + round_to(cb->total_content_size(), oopSize);136assert(_data_offset <= size, "codeBlob is too small");137138cb->copy_code_and_locs_to(this);139set_oop_maps(oop_maps);140_frame_size = frame_size;141#ifdef COMPILER1142// probably wrong for tiered143assert(_frame_size >= -1, "must use frame size or -1 for runtime stubs");144#endif // COMPILER1145}146147148void CodeBlob::set_oop_maps(OopMapSet* p) {149// Danger Will Robinson! This method allocates a big150// chunk of memory, its your job to free it.151if (p != NULL) {152// We need to allocate a chunk big enough to hold the OopMapSet and all of its OopMaps153_oop_maps = (OopMapSet* )NEW_C_HEAP_ARRAY(unsigned char, p->heap_size(), mtCode);154p->copy_to((address)_oop_maps);155} else {156_oop_maps = NULL;157}158}159160161void CodeBlob::trace_new_stub(CodeBlob* stub, const char* name1, const char* name2) {162// Do not hold the CodeCache lock during name formatting.163assert(!CodeCache_lock->owned_by_self(), "release CodeCache before registering the stub");164165if (stub != NULL) {166char stub_id[256];167assert(strlen(name1) + strlen(name2) < sizeof(stub_id), "");168jio_snprintf(stub_id, sizeof(stub_id), "%s%s", name1, name2);169if (PrintStubCode) {170ttyLocker ttyl;171tty->print_cr("Decoding %s " INTPTR_FORMAT, stub_id, (intptr_t) stub);172Disassembler::decode(stub->code_begin(), stub->code_end());173tty->cr();174}175Forte::register_stub(stub_id, stub->code_begin(), stub->code_end());176177if (JvmtiExport::should_post_dynamic_code_generated()) {178const char* stub_name = name2;179if (name2[0] == '\0') stub_name = name1;180JvmtiExport::post_dynamic_code_generated(stub_name, stub->code_begin(), stub->code_end());181}182}183184// Track memory usage statistic after releasing CodeCache_lock185MemoryService::track_code_cache_memory_usage();186}187188189void CodeBlob::flush() {190if (_oop_maps) {191FREE_C_HEAP_ARRAY(unsigned char, _oop_maps, mtCode);192_oop_maps = NULL;193}194_strings.free();195}196197198OopMap* CodeBlob::oop_map_for_return_address(address return_address) {199assert(oop_maps() != NULL, "nope");200return oop_maps()->find_map_at_offset((intptr_t) return_address - (intptr_t) code_begin());201}202203204//----------------------------------------------------------------------------------------------------205// Implementation of BufferBlob206207208BufferBlob::BufferBlob(const char* name, int size)209: CodeBlob(name, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, /*locs_size:*/ 0)210{}211212BufferBlob* BufferBlob::create(const char* name, int buffer_size) {213ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock214215BufferBlob* blob = NULL;216unsigned int size = sizeof(BufferBlob);217// align the size to CodeEntryAlignment218size = align_code_offset(size);219size += round_to(buffer_size, oopSize);220assert(name != NULL, "must provide a name");221{222MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);223blob = new (size) BufferBlob(name, size);224}225// Track memory usage statistic after releasing CodeCache_lock226MemoryService::track_code_cache_memory_usage();227228return blob;229}230231232BufferBlob::BufferBlob(const char* name, int size, CodeBuffer* cb)233: CodeBlob(name, cb, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, 0, NULL)234{}235236BufferBlob* BufferBlob::create(const char* name, CodeBuffer* cb) {237ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock238239BufferBlob* blob = NULL;240unsigned int size = allocation_size(cb, sizeof(BufferBlob));241assert(name != NULL, "must provide a name");242{243MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);244blob = new (size) BufferBlob(name, size, cb);245}246// Track memory usage statistic after releasing CodeCache_lock247MemoryService::track_code_cache_memory_usage();248249return blob;250}251252253void* BufferBlob::operator new(size_t s, unsigned size, bool is_critical) throw() {254void* p = CodeCache::allocate(size, is_critical);255return p;256}257258259void BufferBlob::free( BufferBlob *blob ) {260ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock261blob->flush();262{263MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);264CodeCache::free((CodeBlob*)blob);265}266// Track memory usage statistic after releasing CodeCache_lock267MemoryService::track_code_cache_memory_usage();268}269270271//----------------------------------------------------------------------------------------------------272// Implementation of AdapterBlob273274AdapterBlob::AdapterBlob(int size, CodeBuffer* cb) :275BufferBlob("I2C/C2I adapters", size, cb) {276CodeCache::commit(this);277}278279AdapterBlob* AdapterBlob::create(CodeBuffer* cb) {280ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock281282AdapterBlob* blob = NULL;283unsigned int size = allocation_size(cb, sizeof(AdapterBlob));284{285MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);286// The parameter 'true' indicates a critical memory allocation.287// This means that CodeCacheMinimumFreeSpace is used, if necessary288const bool is_critical = true;289blob = new (size, is_critical) AdapterBlob(size, cb);290}291// Track memory usage statistic after releasing CodeCache_lock292MemoryService::track_code_cache_memory_usage();293294return blob;295}296297VtableBlob::VtableBlob(const char* name, int size) :298BufferBlob(name, size) {299}300301VtableBlob* VtableBlob::create(const char* name, int buffer_size) {302ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock303304VtableBlob* blob = NULL;305unsigned int size = sizeof(VtableBlob);306// align the size to CodeEntryAlignment307size = align_code_offset(size);308size += round_to(buffer_size, oopSize);309assert(name != NULL, "must provide a name");310{311MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);312blob = new (size) VtableBlob(name, size);313}314// Track memory usage statistic after releasing CodeCache_lock315MemoryService::track_code_cache_memory_usage();316317return blob;318}319320//----------------------------------------------------------------------------------------------------321// Implementation of MethodHandlesAdapterBlob322323MethodHandlesAdapterBlob* MethodHandlesAdapterBlob::create(int buffer_size) {324ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock325326MethodHandlesAdapterBlob* blob = NULL;327unsigned int size = sizeof(MethodHandlesAdapterBlob);328// align the size to CodeEntryAlignment329size = align_code_offset(size);330size += round_to(buffer_size, oopSize);331{332MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);333// The parameter 'true' indicates a critical memory allocation.334// This means that CodeCacheMinimumFreeSpace is used, if necessary335const bool is_critical = true;336blob = new (size, is_critical) MethodHandlesAdapterBlob(size);337}338// Track memory usage statistic after releasing CodeCache_lock339MemoryService::track_code_cache_memory_usage();340341return blob;342}343344345//----------------------------------------------------------------------------------------------------346// Implementation of RuntimeStub347348RuntimeStub::RuntimeStub(349const char* name,350CodeBuffer* cb,351int size,352int frame_complete,353int frame_size,354OopMapSet* oop_maps,355bool caller_must_gc_arguments356)357: CodeBlob(name, cb, sizeof(RuntimeStub), size, frame_complete, frame_size, oop_maps)358{359_caller_must_gc_arguments = caller_must_gc_arguments;360}361362363RuntimeStub* RuntimeStub::new_runtime_stub(const char* stub_name,364CodeBuffer* cb,365int frame_complete,366int frame_size,367OopMapSet* oop_maps,368bool caller_must_gc_arguments)369{370RuntimeStub* stub = NULL;371ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock372{373MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);374unsigned int size = allocation_size(cb, sizeof(RuntimeStub));375stub = new (size) RuntimeStub(stub_name, cb, size, frame_complete, frame_size, oop_maps, caller_must_gc_arguments);376}377378trace_new_stub(stub, "RuntimeStub - ", stub_name);379380return stub;381}382383384void* RuntimeStub::operator new(size_t s, unsigned size) throw() {385void* p = CodeCache::allocate(size, true);386if (!p) fatal("Initial size of CodeCache is too small");387return p;388}389390// operator new shared by all singletons:391void* SingletonBlob::operator new(size_t s, unsigned size) throw() {392void* p = CodeCache::allocate(size, true);393if (!p) fatal("Initial size of CodeCache is too small");394return p;395}396397398//----------------------------------------------------------------------------------------------------399// Implementation of DeoptimizationBlob400401DeoptimizationBlob::DeoptimizationBlob(402CodeBuffer* cb,403int size,404OopMapSet* oop_maps,405int unpack_offset,406int unpack_with_exception_offset,407int unpack_with_reexecution_offset,408int frame_size409)410: SingletonBlob("DeoptimizationBlob", cb, sizeof(DeoptimizationBlob), size, frame_size, oop_maps)411{412_unpack_offset = unpack_offset;413_unpack_with_exception = unpack_with_exception_offset;414_unpack_with_reexecution = unpack_with_reexecution_offset;415#ifdef COMPILER1416_unpack_with_exception_in_tls = -1;417#endif418}419420421DeoptimizationBlob* DeoptimizationBlob::create(422CodeBuffer* cb,423OopMapSet* oop_maps,424int unpack_offset,425int unpack_with_exception_offset,426int unpack_with_reexecution_offset,427int frame_size)428{429DeoptimizationBlob* blob = NULL;430ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock431{432MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);433unsigned int size = allocation_size(cb, sizeof(DeoptimizationBlob));434blob = new (size) DeoptimizationBlob(cb,435size,436oop_maps,437unpack_offset,438unpack_with_exception_offset,439unpack_with_reexecution_offset,440frame_size);441}442443trace_new_stub(blob, "DeoptimizationBlob");444445return blob;446}447448449//----------------------------------------------------------------------------------------------------450// Implementation of UncommonTrapBlob451452#ifdef COMPILER2453UncommonTrapBlob::UncommonTrapBlob(454CodeBuffer* cb,455int size,456OopMapSet* oop_maps,457int frame_size458)459: SingletonBlob("UncommonTrapBlob", cb, sizeof(UncommonTrapBlob), size, frame_size, oop_maps)460{}461462463UncommonTrapBlob* UncommonTrapBlob::create(464CodeBuffer* cb,465OopMapSet* oop_maps,466int frame_size)467{468UncommonTrapBlob* blob = NULL;469ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock470{471MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);472unsigned int size = allocation_size(cb, sizeof(UncommonTrapBlob));473blob = new (size) UncommonTrapBlob(cb, size, oop_maps, frame_size);474}475476trace_new_stub(blob, "UncommonTrapBlob");477478return blob;479}480481482#endif // COMPILER2483484485//----------------------------------------------------------------------------------------------------486// Implementation of ExceptionBlob487488#ifdef COMPILER2489ExceptionBlob::ExceptionBlob(490CodeBuffer* cb,491int size,492OopMapSet* oop_maps,493int frame_size494)495: SingletonBlob("ExceptionBlob", cb, sizeof(ExceptionBlob), size, frame_size, oop_maps)496{}497498499ExceptionBlob* ExceptionBlob::create(500CodeBuffer* cb,501OopMapSet* oop_maps,502int frame_size)503{504ExceptionBlob* blob = NULL;505ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock506{507MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);508unsigned int size = allocation_size(cb, sizeof(ExceptionBlob));509blob = new (size) ExceptionBlob(cb, size, oop_maps, frame_size);510}511512trace_new_stub(blob, "ExceptionBlob");513514return blob;515}516517518#endif // COMPILER2519520521//----------------------------------------------------------------------------------------------------522// Implementation of SafepointBlob523524SafepointBlob::SafepointBlob(525CodeBuffer* cb,526int size,527OopMapSet* oop_maps,528int frame_size529)530: SingletonBlob("SafepointBlob", cb, sizeof(SafepointBlob), size, frame_size, oop_maps)531{}532533534SafepointBlob* SafepointBlob::create(535CodeBuffer* cb,536OopMapSet* oop_maps,537int frame_size)538{539SafepointBlob* blob = NULL;540ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock541{542MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);543unsigned int size = allocation_size(cb, sizeof(SafepointBlob));544blob = new (size) SafepointBlob(cb, size, oop_maps, frame_size);545}546547trace_new_stub(blob, "SafepointBlob");548549return blob;550}551552553//----------------------------------------------------------------------------------------------------554// Verification and printing555556void CodeBlob::verify() {557ShouldNotReachHere();558}559560void CodeBlob::print_on(outputStream* st) const {561st->print_cr("[CodeBlob (" INTPTR_FORMAT ")]", p2i(this));562st->print_cr("Framesize: %d", _frame_size);563}564565void CodeBlob::print_value_on(outputStream* st) const {566st->print_cr("[CodeBlob]");567}568569void BufferBlob::verify() {570// unimplemented571}572573void BufferBlob::print_on(outputStream* st) const {574CodeBlob::print_on(st);575print_value_on(st);576}577578void BufferBlob::print_value_on(outputStream* st) const {579st->print_cr("BufferBlob (" INTPTR_FORMAT ") used for %s", p2i(this), name());580}581582void RuntimeStub::verify() {583// unimplemented584}585586void RuntimeStub::print_on(outputStream* st) const {587ttyLocker ttyl;588CodeBlob::print_on(st);589st->print("Runtime Stub (" INTPTR_FORMAT "): ", p2i(this));590st->print_cr("%s", name());591Disassembler::decode((CodeBlob*)this, st);592}593594void RuntimeStub::print_value_on(outputStream* st) const {595st->print("RuntimeStub (" INTPTR_FORMAT "): ", p2i(this)); st->print("%s", name());596}597598void SingletonBlob::verify() {599// unimplemented600}601602void SingletonBlob::print_on(outputStream* st) const {603ttyLocker ttyl;604CodeBlob::print_on(st);605st->print_cr("%s", name());606Disassembler::decode((CodeBlob*)this, st);607}608609void SingletonBlob::print_value_on(outputStream* st) const {610st->print_cr("%s", name());611}612613void DeoptimizationBlob::print_value_on(outputStream* st) const {614st->print_cr("Deoptimization (frame not available)");615}616617618