duke@435: /* coleenp@5614: * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_CODE_CODEBLOB_HPP stefank@2314: #define SHARE_VM_CODE_CODEBLOB_HPP stefank@2314: stefank@2314: #include "asm/codeBuffer.hpp" stefank@2314: #include "compiler/oopMap.hpp" stefank@2314: #include "runtime/frame.hpp" stefank@2314: #include "runtime/handles.hpp" stefank@2314: duke@435: // CodeBlob - superclass for all entries in the CodeCache. duke@435: // duke@435: // Suptypes are: duke@435: // nmethod : Compiled Java methods (include method that calls to native code) duke@435: // RuntimeStub : Call to VM runtime methods duke@435: // DeoptimizationBlob : Used for deoptimizatation duke@435: // ExceptionBlob : Used for stack unrolling duke@435: // SafepointBlob : Used to handle illegal instruction exceptions duke@435: // duke@435: // duke@435: // Layout: duke@435: // - header duke@435: // - relocation twisti@2103: // - content space twisti@2103: // - instruction space duke@435: // - data space duke@435: class DeoptimizationBlob; duke@435: duke@435: class CodeBlob VALUE_OBJ_CLASS_SPEC { duke@435: duke@435: friend class VMStructs; duke@435: duke@435: private: duke@435: const char* _name; duke@435: int _size; // total size of CodeBlob in bytes duke@435: int _header_size; // size of header (depends on subclass) duke@435: int _relocation_size; // size of relocation twisti@2103: int _content_offset; // offset to where content region begins (this includes consts, insts, stubs) twisti@2103: int _code_offset; // offset to where instructions region begins (this includes insts, stubs) duke@435: int _frame_complete_offset; // instruction offsets in [0.._frame_complete_offset) have duke@435: // not finished setting up their frame. Beware of pc's in duke@435: // that range. There is a similar range(s) on returns duke@435: // which we don't detect. duke@435: int _data_offset; // offset to where data region begins duke@435: int _frame_size; // size of stack frame duke@435: OopMapSet* _oop_maps; // OopMap for this CodeBlob roland@4767: CodeStrings _strings; duke@435: duke@435: public: duke@435: // Returns the space needed for CodeBlob duke@435: static unsigned int allocation_size(CodeBuffer* cb, int header_size); duke@435: duke@435: // Creation duke@435: // a) simple CodeBlob duke@435: // frame_complete is the offset from the beginning of the instructions duke@435: // to where the frame setup (from stackwalk viewpoint) is complete. duke@435: CodeBlob(const char* name, int header_size, int size, int frame_complete, int locs_size); duke@435: duke@435: // b) full CodeBlob duke@435: CodeBlob( duke@435: const char* name, duke@435: CodeBuffer* cb, duke@435: int header_size, duke@435: int size, duke@435: int frame_complete, duke@435: int frame_size, duke@435: OopMapSet* oop_maps duke@435: ); duke@435: duke@435: // Deletion duke@435: void flush(); duke@435: duke@435: // Typing never@2895: virtual bool is_buffer_blob() const { return false; } never@2895: virtual bool is_nmethod() const { return false; } never@2895: virtual bool is_runtime_stub() const { return false; } never@2895: virtual bool is_deoptimization_stub() const { return false; } never@2895: virtual bool is_uncommon_trap_stub() const { return false; } never@2895: virtual bool is_exception_stub() const { return false; } twisti@1734: virtual bool is_safepoint_stub() const { return false; } twisti@1734: virtual bool is_adapter_blob() const { return false; } twisti@1734: virtual bool is_method_handles_adapter_blob() const { return false; } duke@435: duke@435: virtual bool is_compiled_by_c2() const { return false; } duke@435: virtual bool is_compiled_by_c1() const { return false; } duke@435: twisti@1570: // Casting twisti@1570: nmethod* as_nmethod_or_null() { return is_nmethod() ? (nmethod*) this : NULL; } twisti@1570: duke@435: // Boundaries duke@435: address header_begin() const { return (address) this; } duke@435: address header_end() const { return ((address) this) + _header_size; }; duke@435: relocInfo* relocation_begin() const { return (relocInfo*) header_end(); }; duke@435: relocInfo* relocation_end() const { return (relocInfo*)(header_end() + _relocation_size); } twisti@2103: address content_begin() const { return (address) header_begin() + _content_offset; } twisti@2103: address content_end() const { return (address) header_begin() + _data_offset; } twisti@2103: address code_begin() const { return (address) header_begin() + _code_offset; } twisti@2103: address code_end() const { return (address) header_begin() + _data_offset; } duke@435: address data_begin() const { return (address) header_begin() + _data_offset; } duke@435: address data_end() const { return (address) header_begin() + _size; } duke@435: duke@435: // Offsets duke@435: int relocation_offset() const { return _header_size; } twisti@2103: int content_offset() const { return _content_offset; } twisti@2103: int code_offset() const { return _code_offset; } duke@435: int data_offset() const { return _data_offset; } duke@435: duke@435: // Sizes duke@435: int size() const { return _size; } duke@435: int header_size() const { return _header_size; } duke@435: int relocation_size() const { return (address) relocation_end() - (address) relocation_begin(); } twisti@2103: int content_size() const { return content_end() - content_begin(); } twisti@2103: int code_size() const { return code_end() - code_begin(); } twisti@2103: int data_size() const { return data_end() - data_begin(); } duke@435: duke@435: // Containment twisti@2103: bool blob_contains(address addr) const { return header_begin() <= addr && addr < data_end(); } duke@435: bool relocation_contains(relocInfo* addr) const{ return relocation_begin() <= addr && addr < relocation_end(); } twisti@2103: bool content_contains(address addr) const { return content_begin() <= addr && addr < content_end(); } twisti@2103: bool code_contains(address addr) const { return code_begin() <= addr && addr < code_end(); } twisti@2103: bool data_contains(address addr) const { return data_begin() <= addr && addr < data_end(); } twisti@2103: bool contains(address addr) const { return content_contains(addr); } twisti@2103: bool is_frame_complete_at(address addr) const { return code_contains(addr) && twisti@2103: addr >= code_begin() + _frame_complete_offset; } duke@435: duke@435: // CodeCache support: really only used by the nmethods, but in order to get duke@435: // asserts and certain bookkeeping to work in the CodeCache they are defined duke@435: // virtual here. duke@435: virtual bool is_zombie() const { return false; } duke@435: virtual bool is_locked_by_vm() const { return false; } duke@435: duke@435: virtual bool is_unloaded() const { return false; } duke@435: virtual bool is_not_entrant() const { return false; } duke@435: duke@435: // GC support duke@435: virtual bool is_alive() const = 0; duke@435: duke@435: // OopMap for frame duke@435: OopMapSet* oop_maps() const { return _oop_maps; } duke@435: void set_oop_maps(OopMapSet* p); duke@435: OopMap* oop_map_for_return_address(address return_address); duke@435: virtual void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { ShouldNotReachHere(); } duke@435: duke@435: // Frame support duke@435: int frame_size() const { return _frame_size; } duke@435: void set_frame_size(int size) { _frame_size = size; } duke@435: duke@435: // Returns true, if the next frame is responsible for GC'ing oops passed as arguments duke@435: virtual bool caller_must_gc_arguments(JavaThread* thread) const { return false; } duke@435: duke@435: // Naming duke@435: const char* name() const { return _name; } duke@435: void set_name(const char* name) { _name = name; } duke@435: duke@435: // Debugging duke@435: virtual void verify(); bobv@2036: void print() const { print_on(tty); } bobv@2036: virtual void print_on(outputStream* st) const; bobv@2036: virtual void print_value_on(outputStream* st) const; duke@435: never@2895: // Deal with Disassembler, VTune, Forte, JvmtiExport, MemoryService. never@2895: static void trace_new_stub(CodeBlob* blob, const char* name1, const char* name2 = ""); never@2895: duke@435: // Print the comment associated with offset on stream, if there is one kvn@4107: virtual void print_block_comment(outputStream* stream, address block_begin) const { twisti@2103: intptr_t offset = (intptr_t)(block_begin - code_begin()); roland@4767: _strings.print_block_comment(stream, offset); duke@435: } duke@435: duke@435: // Transfer ownership of comments to this CodeBlob roland@4767: void set_strings(CodeStrings& strings) { roland@4767: _strings.assign(strings); duke@435: } duke@435: }; duke@435: duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // BufferBlob: used to hold non-relocatable machine code such as the interpreter, stubroutines, etc. duke@435: duke@435: class BufferBlob: public CodeBlob { duke@435: friend class VMStructs; twisti@1734: friend class AdapterBlob; twisti@1734: friend class MethodHandlesAdapterBlob; twisti@1734: duke@435: private: duke@435: // Creation support duke@435: BufferBlob(const char* name, int size); duke@435: BufferBlob(const char* name, int size, CodeBuffer* cb); duke@435: anoll@5919: void* operator new(size_t s, unsigned size, bool is_critical = false) throw(); duke@435: duke@435: public: duke@435: // Creation duke@435: static BufferBlob* create(const char* name, int buffer_size); duke@435: static BufferBlob* create(const char* name, CodeBuffer* cb); duke@435: duke@435: static void free(BufferBlob* buf); duke@435: duke@435: // Typing twisti@1734: virtual bool is_buffer_blob() const { return true; } duke@435: duke@435: // GC/Verification support duke@435: void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { /* nothing to do */ } duke@435: bool is_alive() const { return true; } duke@435: duke@435: void verify(); bobv@2036: void print_on(outputStream* st) const; bobv@2036: void print_value_on(outputStream* st) const; duke@435: }; duke@435: duke@435: duke@435: //---------------------------------------------------------------------------------------------------- twisti@1734: // AdapterBlob: used to hold C2I/I2C adapters twisti@1734: twisti@1734: class AdapterBlob: public BufferBlob { twisti@1734: private: never@2018: AdapterBlob(int size, CodeBuffer* cb); twisti@1734: twisti@1734: public: twisti@1734: // Creation twisti@1734: static AdapterBlob* create(CodeBuffer* cb); twisti@1734: twisti@1734: // Typing twisti@1734: virtual bool is_adapter_blob() const { return true; } twisti@1734: }; twisti@1734: twisti@1734: twisti@1734: //---------------------------------------------------------------------------------------------------- twisti@1734: // MethodHandlesAdapterBlob: used to hold MethodHandles adapters twisti@1734: twisti@1734: class MethodHandlesAdapterBlob: public BufferBlob { twisti@1734: private: twisti@1734: MethodHandlesAdapterBlob(int size) : BufferBlob("MethodHandles adapters", size) {} twisti@1734: twisti@1734: public: twisti@1734: // Creation twisti@1734: static MethodHandlesAdapterBlob* create(int buffer_size); twisti@1734: twisti@1734: // Typing twisti@1734: virtual bool is_method_handles_adapter_blob() const { return true; } twisti@1734: }; twisti@1734: twisti@1734: twisti@1734: //---------------------------------------------------------------------------------------------------- duke@435: // RuntimeStub: describes stubs used by compiled code to call a (static) C++ runtime routine duke@435: duke@435: class RuntimeStub: public CodeBlob { duke@435: friend class VMStructs; duke@435: private: duke@435: bool _caller_must_gc_arguments; duke@435: duke@435: // Creation support duke@435: RuntimeStub( duke@435: const char* name, duke@435: CodeBuffer* cb, duke@435: int size, duke@435: int frame_complete, duke@435: int frame_size, duke@435: OopMapSet* oop_maps, duke@435: bool caller_must_gc_arguments duke@435: ); duke@435: coleenp@5614: void* operator new(size_t s, unsigned size) throw(); duke@435: duke@435: public: duke@435: // Creation duke@435: static RuntimeStub* new_runtime_stub( duke@435: const char* stub_name, duke@435: CodeBuffer* cb, duke@435: int frame_complete, duke@435: int frame_size, duke@435: OopMapSet* oop_maps, duke@435: bool caller_must_gc_arguments duke@435: ); duke@435: duke@435: // Typing duke@435: bool is_runtime_stub() const { return true; } duke@435: duke@435: // GC support duke@435: bool caller_must_gc_arguments(JavaThread* thread) const { return _caller_must_gc_arguments; } duke@435: twisti@2103: address entry_point() { return code_begin(); } duke@435: duke@435: // GC/Verification support duke@435: void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { /* nothing to do */ } duke@435: bool is_alive() const { return true; } duke@435: duke@435: void verify(); bobv@2036: void print_on(outputStream* st) const; bobv@2036: void print_value_on(outputStream* st) const; duke@435: }; duke@435: duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Super-class for all blobs that exist in only one instance. Implements default behaviour. duke@435: duke@435: class SingletonBlob: public CodeBlob { duke@435: friend class VMStructs; never@2895: never@2895: protected: coleenp@5614: void* operator new(size_t s, unsigned size) throw(); never@2895: never@2895: public: duke@435: SingletonBlob( duke@435: const char* name, duke@435: CodeBuffer* cb, duke@435: int header_size, duke@435: int size, duke@435: int frame_size, duke@435: OopMapSet* oop_maps duke@435: ) duke@435: : CodeBlob(name, cb, header_size, size, CodeOffsets::frame_never_safe, frame_size, oop_maps) twisti@2103: {}; duke@435: twisti@2103: address entry_point() { return code_begin(); } duke@435: twisti@2103: bool is_alive() const { return true; } twisti@2103: twisti@2103: void verify(); // does nothing twisti@2103: void print_on(outputStream* st) const; twisti@2103: void print_value_on(outputStream* st) const; duke@435: }; duke@435: duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // DeoptimizationBlob duke@435: duke@435: class DeoptimizationBlob: public SingletonBlob { duke@435: friend class VMStructs; duke@435: private: duke@435: int _unpack_offset; duke@435: int _unpack_with_exception; duke@435: int _unpack_with_reexecution; duke@435: duke@435: int _unpack_with_exception_in_tls; duke@435: duke@435: // Creation support duke@435: DeoptimizationBlob( duke@435: CodeBuffer* cb, duke@435: int size, duke@435: OopMapSet* oop_maps, duke@435: int unpack_offset, duke@435: int unpack_with_exception_offset, duke@435: int unpack_with_reexecution_offset, duke@435: int frame_size duke@435: ); duke@435: duke@435: public: duke@435: // Creation duke@435: static DeoptimizationBlob* create( duke@435: CodeBuffer* cb, duke@435: OopMapSet* oop_maps, duke@435: int unpack_offset, duke@435: int unpack_with_exception_offset, duke@435: int unpack_with_reexecution_offset, duke@435: int frame_size duke@435: ); duke@435: duke@435: // Typing duke@435: bool is_deoptimization_stub() const { return true; } duke@435: bool exception_address_is_unpack_entry(address pc) const { duke@435: address unpack_pc = unpack(); duke@435: return (pc == unpack_pc || (pc + frame::pc_return_offset) == unpack_pc); duke@435: } duke@435: duke@435: duke@435: duke@435: duke@435: // GC for args duke@435: void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { /* Nothing to do */ } duke@435: duke@435: // Printing bobv@2036: void print_value_on(outputStream* st) const; duke@435: twisti@2103: address unpack() const { return code_begin() + _unpack_offset; } twisti@2103: address unpack_with_exception() const { return code_begin() + _unpack_with_exception; } twisti@2103: address unpack_with_reexecution() const { return code_begin() + _unpack_with_reexecution; } duke@435: duke@435: // Alternate entry point for C1 where the exception and issuing pc duke@435: // are in JavaThread::_exception_oop and JavaThread::_exception_pc duke@435: // instead of being in registers. This is needed because C1 doesn't duke@435: // model exception paths in a way that keeps these registers free so duke@435: // there may be live values in those registers during deopt. duke@435: void set_unpack_with_exception_in_tls_offset(int offset) { duke@435: _unpack_with_exception_in_tls = offset; twisti@2103: assert(code_contains(code_begin() + _unpack_with_exception_in_tls), "must be PC inside codeblob"); duke@435: } twisti@2103: address unpack_with_exception_in_tls() const { return code_begin() + _unpack_with_exception_in_tls; } duke@435: }; duke@435: duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // UncommonTrapBlob (currently only used by Compiler 2) duke@435: duke@435: #ifdef COMPILER2 duke@435: duke@435: class UncommonTrapBlob: public SingletonBlob { duke@435: friend class VMStructs; duke@435: private: duke@435: // Creation support duke@435: UncommonTrapBlob( duke@435: CodeBuffer* cb, duke@435: int size, duke@435: OopMapSet* oop_maps, duke@435: int frame_size duke@435: ); duke@435: duke@435: public: duke@435: // Creation duke@435: static UncommonTrapBlob* create( duke@435: CodeBuffer* cb, duke@435: OopMapSet* oop_maps, duke@435: int frame_size duke@435: ); duke@435: duke@435: // GC for args duke@435: void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { /* nothing to do */ } duke@435: duke@435: // Typing duke@435: bool is_uncommon_trap_stub() const { return true; } duke@435: }; duke@435: duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // ExceptionBlob: used for exception unwinding in compiled code (currently only used by Compiler 2) duke@435: duke@435: class ExceptionBlob: public SingletonBlob { duke@435: friend class VMStructs; duke@435: private: duke@435: // Creation support duke@435: ExceptionBlob( duke@435: CodeBuffer* cb, duke@435: int size, duke@435: OopMapSet* oop_maps, duke@435: int frame_size duke@435: ); duke@435: duke@435: public: duke@435: // Creation duke@435: static ExceptionBlob* create( duke@435: CodeBuffer* cb, duke@435: OopMapSet* oop_maps, duke@435: int frame_size duke@435: ); duke@435: duke@435: // GC for args duke@435: void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { /* nothing to do */ } duke@435: duke@435: // Typing duke@435: bool is_exception_stub() const { return true; } duke@435: }; duke@435: #endif // COMPILER2 duke@435: duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // SafepointBlob: handles illegal_instruction exceptions during a safepoint duke@435: duke@435: class SafepointBlob: public SingletonBlob { duke@435: friend class VMStructs; duke@435: private: duke@435: // Creation support duke@435: SafepointBlob( duke@435: CodeBuffer* cb, duke@435: int size, duke@435: OopMapSet* oop_maps, duke@435: int frame_size duke@435: ); duke@435: duke@435: public: duke@435: // Creation duke@435: static SafepointBlob* create( duke@435: CodeBuffer* cb, duke@435: OopMapSet* oop_maps, duke@435: int frame_size duke@435: ); duke@435: duke@435: // GC for args duke@435: void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { /* nothing to do */ } duke@435: duke@435: // Typing duke@435: bool is_safepoint_stub() const { return true; } duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_CODE_CODEBLOB_HPP