codeBlob.hpp revision 1135
/*
* Copyright 1998-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
// CodeBlob - superclass for all entries in the CodeCache.
//
// Suptypes are:
// nmethod : Compiled Java methods (include method that calls to native code)
// RuntimeStub : Call to VM runtime methods
// DeoptimizationBlob : Used for deoptimizatation
// ExceptionBlob : Used for stack unrolling
// SafepointBlob : Used to handle illegal instruction exceptions
//
//
// Layout:
// - header
// - relocation
// - instruction space
// - data space
class DeoptimizationBlob;
class CodeBlob VALUE_OBJ_CLASS_SPEC {
friend class VMStructs;
private:
const char* _name;
int _size; // total size of CodeBlob in bytes
int _header_size; // size of header (depends on subclass)
int _relocation_size; // size of relocation
int _instructions_offset; // offset to where instructions region begins
int _frame_complete_offset; // instruction offsets in [0.._frame_complete_offset) have
// not finished setting up their frame. Beware of pc's in
// that range. There is a similar range(s) on returns
// which we don't detect.
int _data_offset; // offset to where data region begins
int _oops_offset; // offset to where embedded oop table begins (inside data)
int _oops_length; // number of embedded oops
int _frame_size; // size of stack frame
friend class OopRecorder;
public:
// Returns the space needed for CodeBlob
// Creation
// a) simple CodeBlob
// frame_complete is the offset from the beginning of the instructions
// to where the frame setup (from stackwalk viewpoint) is complete.
// b) full CodeBlob
const char* name,
CodeBuffer* cb,
int header_size,
int size,
int frame_complete,
int frame_size,
);
// Deletion
void flush();
// Typing
virtual bool is_buffer_blob() const { return false; }
virtual bool is_nmethod() const { return false; }
virtual bool is_runtime_stub() const { return false; }
virtual bool is_deoptimization_stub() const { return false; }
virtual bool is_uncommon_trap_stub() const { return false; }
virtual bool is_exception_stub() const { return false; }
virtual bool is_safepoint_stub() const { return false; }
virtual bool is_adapter_blob() const { return false; }
virtual bool is_compiled_by_c2() const { return false; }
virtual bool is_compiled_by_c1() const { return false; }
// Casting
// Boundaries
// Offsets
int relocation_offset() const { return _header_size; }
int instructions_offset() const { return _instructions_offset; }
int data_offset() const { return _data_offset; }
int oops_offset() const { return _oops_offset; }
// Sizes
int header_size() const { return _header_size; }
// Containment
bool relocation_contains(relocInfo* addr) const{ return relocation_begin() <= addr && addr < relocation_end(); }
bool instructions_contains(address addr) const { return instructions_begin() <= addr && addr < instructions_end(); }
// Relocation support
}
void fix_oop_relocations() {
}
// Support for oops in scopes and relocs:
// Note: index 0 is reserved for null.
// relocation indexes are biased by 1 (because 0 is reserved)
}
// CodeCache support: really only used by the nmethods, but in order to get
// asserts and certain bookkeeping to work in the CodeCache they are defined
// virtual here.
virtual bool is_zombie() const { return false; }
virtual bool is_locked_by_vm() const { return false; }
virtual bool is_unloaded() const { return false; }
virtual bool is_not_entrant() const { return false; }
// GC support
virtual bool is_alive() const = 0;
bool unloading_occurred);
virtual void oops_do(OopClosure* f) = 0;
// (All CodeBlob subtypes other than NMethod currently have
// an empty oops_do() method.
// OopMap for frame
void set_oop_maps(OopMapSet* p);
virtual void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { ShouldNotReachHere(); }
// Frame support
int frame_size() const { return _frame_size; }
// Returns true, if the next frame is responsible for GC'ing oops passed as arguments
// Naming
// Debugging
virtual void verify();
virtual void print() const PRODUCT_RETURN;
// Print the comment associated with offset on stream, if there is one
}
// Transfer ownership of comments to this CodeBlob
}
};
//----------------------------------------------------------------------------------------------------
// BufferBlob: used to hold non-relocatable machine code such as the interpreter, stubroutines, etc.
class BufferBlob: public CodeBlob {
friend class VMStructs;
private:
// Creation support
public:
// Creation
// Typing
bool is_buffer_blob() const { return true; }
bool is_adapter_blob() const;
// GC/Verification support
void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { /* nothing to do */ }
bool is_alive() const { return true; }
bool unloading_occurred) { /* do nothing */ }
void verify();
void print() const PRODUCT_RETURN;
};
//----------------------------------------------------------------------------------------------------
// RuntimeStub: describes stubs used by compiled code to call a (static) C++ runtime routine
class RuntimeStub: public CodeBlob {
friend class VMStructs;
private:
// Creation support
const char* name,
CodeBuffer* cb,
int size,
int frame_complete,
int frame_size,
);
public:
// Creation
static RuntimeStub* new_runtime_stub(
const char* stub_name,
CodeBuffer* cb,
int frame_complete,
int frame_size,
);
// Typing
bool is_runtime_stub() const { return true; }
// GC support
// GC/Verification support
void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { /* nothing to do */ }
bool is_alive() const { return true; }
bool unloading_occurred) { /* do nothing */ }
void verify();
void print() const PRODUCT_RETURN;
};
//----------------------------------------------------------------------------------------------------
// Super-class for all blobs that exist in only one instance. Implements default behaviour.
class SingletonBlob: public CodeBlob {
friend class VMStructs;
public:
const char* name,
CodeBuffer* cb,
int header_size,
int size,
int frame_size,
)
{};
bool is_alive() const { return true; }
bool unloading_occurred) { /* do-nothing*/ }
void verify(); // does nothing
void print() const PRODUCT_RETURN;
};
//----------------------------------------------------------------------------------------------------
// DeoptimizationBlob
class DeoptimizationBlob: public SingletonBlob {
friend class VMStructs;
private:
int _unpack_offset;
// Creation support
CodeBuffer* cb,
int size,
int unpack_offset,
int frame_size
);
public:
// Creation
static DeoptimizationBlob* create(
CodeBuffer* cb,
int unpack_offset,
int frame_size
);
// Typing
bool is_deoptimization_stub() const { return true; }
const DeoptimizationBlob *as_deoptimization_stub() const { return this; }
}
// GC for args
void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { /* Nothing to do */ }
// Iteration
void oops_do(OopClosure* f) {}
// Printing
// Alternate entry point for C1 where the exception and issuing pc
// are in JavaThread::_exception_oop and JavaThread::_exception_pc
// instead of being in registers. This is needed because C1 doesn't
// model exception paths in a way that keeps these registers free so
// there may be live values in those registers during deopt.
void set_unpack_with_exception_in_tls_offset(int offset) {
assert(contains(instructions_begin() + _unpack_with_exception_in_tls), "must be PC inside codeblob");
}
address unpack_with_exception_in_tls() const { return instructions_begin() + _unpack_with_exception_in_tls; }
};
//----------------------------------------------------------------------------------------------------
// UncommonTrapBlob (currently only used by Compiler 2)
#ifdef COMPILER2
class UncommonTrapBlob: public SingletonBlob {
friend class VMStructs;
private:
// Creation support
CodeBuffer* cb,
int size,
int frame_size
);
public:
// Creation
static UncommonTrapBlob* create(
CodeBuffer* cb,
int frame_size
);
// GC for args
void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { /* nothing to do */ }
// Typing
bool is_uncommon_trap_stub() const { return true; }
// Iteration
void oops_do(OopClosure* f) {}
};
//----------------------------------------------------------------------------------------------------
// ExceptionBlob: used for exception unwinding in compiled code (currently only used by Compiler 2)
class ExceptionBlob: public SingletonBlob {
friend class VMStructs;
private:
// Creation support
CodeBuffer* cb,
int size,
int frame_size
);
public:
// Creation
static ExceptionBlob* create(
CodeBuffer* cb,
int frame_size
);
// GC for args
void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { /* nothing to do */ }
// Typing
bool is_exception_stub() const { return true; }
// Iteration
void oops_do(OopClosure* f) {}
};
#endif // COMPILER2
//----------------------------------------------------------------------------------------------------
// SafepointBlob: handles illegal_instruction exceptions during a safepoint
class SafepointBlob: public SingletonBlob {
friend class VMStructs;
private:
// Creation support
CodeBuffer* cb,
int size,
int frame_size
);
public:
// Creation
static SafepointBlob* create(
CodeBuffer* cb,
int frame_size
);
// GC for args
void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { /* nothing to do */ }
// Typing
bool is_safepoint_stub() const { return true; }
// Iteration
void oops_do(OopClosure* f) {}
};