src/share/vm/interpreter/interpreter.hpp

Tue, 03 Aug 2010 08:13:38 -0400

author
bobv
date
Tue, 03 Aug 2010 08:13:38 -0400
changeset 2036
126ea7725993
parent 1907
c18cbe5936b8
child 2103
3e8fbc61cee8
permissions
-rw-r--r--

6953477: Increase portability and flexibility of building Hotspot
Summary: A collection of portability improvements including shared code support for PPC, ARM platforms, software floating point, cross compilation support and improvements in error crash detail.
Reviewed-by: phh, never, coleenp, dholmes

duke@435 1 /*
trims@1907 2 * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
twisti@1040 25 // This file contains the platform-independent parts
duke@435 26 // of the interpreter and the interpreter generator.
duke@435 27
duke@435 28 //------------------------------------------------------------------------------------------------------------------------
duke@435 29 // An InterpreterCodelet is a piece of interpreter code. All
duke@435 30 // interpreter code is generated into little codelets which
duke@435 31 // contain extra information for debugging and printing purposes.
duke@435 32
duke@435 33 class InterpreterCodelet: public Stub {
duke@435 34 friend class VMStructs;
duke@435 35 private:
duke@435 36 int _size; // the size in bytes
duke@435 37 const char* _description; // a description of the codelet, for debugging & printing
duke@435 38 Bytecodes::Code _bytecode; // associated bytecode if any
duke@435 39
duke@435 40 public:
duke@435 41 // Initialization/finalization
duke@435 42 void initialize(int size) { _size = size; }
duke@435 43 void finalize() { ShouldNotCallThis(); }
duke@435 44
duke@435 45 // General info/converters
duke@435 46 int size() const { return _size; }
duke@435 47 static int code_size_to_size(int code_size) { return round_to(sizeof(InterpreterCodelet), CodeEntryAlignment) + code_size; }
duke@435 48
duke@435 49 // Code info
duke@435 50 address code_begin() const { return (address)this + round_to(sizeof(InterpreterCodelet), CodeEntryAlignment); }
duke@435 51 address code_end() const { return (address)this + size(); }
duke@435 52
duke@435 53 // Debugging
duke@435 54 void verify();
bobv@2036 55 void print_on(outputStream* st) const;
bobv@2036 56 void print() const { print_on(tty); }
duke@435 57
duke@435 58 // Interpreter-specific initialization
duke@435 59 void initialize(const char* description, Bytecodes::Code bytecode);
duke@435 60
duke@435 61 // Interpreter-specific attributes
duke@435 62 int code_size() const { return code_end() - code_begin(); }
duke@435 63 const char* description() const { return _description; }
duke@435 64 Bytecodes::Code bytecode() const { return _bytecode; }
duke@435 65 };
duke@435 66
duke@435 67 // Define a prototype interface
duke@435 68 DEF_STUB_INTERFACE(InterpreterCodelet);
duke@435 69
duke@435 70
duke@435 71 //------------------------------------------------------------------------------------------------------------------------
duke@435 72 // A CodeletMark serves as an automatic creator/initializer for Codelets
duke@435 73 // (As a subclass of ResourceMark it automatically GC's the allocated
duke@435 74 // code buffer and assemblers).
duke@435 75
duke@435 76 class CodeletMark: ResourceMark {
duke@435 77 private:
duke@435 78 InterpreterCodelet* _clet;
duke@435 79 InterpreterMacroAssembler** _masm;
duke@435 80 CodeBuffer _cb;
duke@435 81
duke@435 82 int codelet_size() {
duke@435 83 // Request the whole code buffer (minus a little for alignment).
duke@435 84 // The commit call below trims it back for each codelet.
duke@435 85 int codelet_size = AbstractInterpreter::code()->available_space() - 2*K;
duke@435 86
duke@435 87 // Guarantee there's a little bit of code space left.
duke@435 88 guarantee (codelet_size > 0 && (size_t)codelet_size > 2*K,
duke@435 89 "not enough space for interpreter generation");
duke@435 90
duke@435 91 return codelet_size;
duke@435 92 }
duke@435 93
duke@435 94 public:
duke@435 95 CodeletMark(
duke@435 96 InterpreterMacroAssembler*& masm,
duke@435 97 const char* description,
duke@435 98 Bytecodes::Code bytecode = Bytecodes::_illegal):
duke@435 99 _clet((InterpreterCodelet*)AbstractInterpreter::code()->request(codelet_size())),
duke@435 100 _cb(_clet->code_begin(), _clet->code_size())
duke@435 101
duke@435 102 { // request all space (add some slack for Codelet data)
duke@435 103 assert (_clet != NULL, "we checked not enough space already");
duke@435 104
duke@435 105 // initialize Codelet attributes
duke@435 106 _clet->initialize(description, bytecode);
duke@435 107 // create assembler for code generation
duke@435 108 masm = new InterpreterMacroAssembler(&_cb);
duke@435 109 _masm = &masm;
duke@435 110 }
duke@435 111
duke@435 112 ~CodeletMark() {
duke@435 113 // align so printing shows nop's instead of random code at the end (Codelets are aligned)
duke@435 114 (*_masm)->align(wordSize);
duke@435 115 // make sure all code is in code buffer
duke@435 116 (*_masm)->flush();
duke@435 117
duke@435 118
duke@435 119 // commit Codelet
duke@435 120 AbstractInterpreter::code()->commit((*_masm)->code()->pure_code_size());
duke@435 121 // make sure nobody can use _masm outside a CodeletMark lifespan
duke@435 122 *_masm = NULL;
duke@435 123 }
duke@435 124 };
duke@435 125
duke@435 126 // Wrapper classes to produce Interpreter/InterpreterGenerator from either
duke@435 127 // the c++ interpreter or the template interpreter.
duke@435 128
duke@435 129 class Interpreter: public CC_INTERP_ONLY(CppInterpreter) NOT_CC_INTERP(TemplateInterpreter) {
duke@435 130
duke@435 131 public:
duke@435 132 // Debugging/printing
duke@435 133 static InterpreterCodelet* codelet_containing(address pc) { return (InterpreterCodelet*)_code->stub_containing(pc); }
duke@435 134 #include "incls/_interpreter_pd.hpp.incl"
duke@435 135 };

mercurial