Wed, 03 Jul 2013 11:50:29 -0700
Merge
duke@435 | 1 | /* |
mikael@4153 | 2 | * Copyright (c) 1997, 2012, 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 | |
stefank@2314 | 25 | #ifndef SHARE_VM_INTERPRETER_INTERPRETER_HPP |
stefank@2314 | 26 | #define SHARE_VM_INTERPRETER_INTERPRETER_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "code/stubs.hpp" |
stefank@2314 | 29 | #include "interpreter/cppInterpreter.hpp" |
stefank@2314 | 30 | #include "interpreter/templateInterpreter.hpp" |
stefank@2314 | 31 | #ifdef ZERO |
stefank@2314 | 32 | #ifdef TARGET_ARCH_zero |
stefank@2314 | 33 | # include "entry_zero.hpp" |
stefank@2314 | 34 | #endif |
stefank@2314 | 35 | #endif |
stefank@2314 | 36 | |
twisti@1040 | 37 | // This file contains the platform-independent parts |
duke@435 | 38 | // of the interpreter and the interpreter generator. |
duke@435 | 39 | |
duke@435 | 40 | //------------------------------------------------------------------------------------------------------------------------ |
duke@435 | 41 | // An InterpreterCodelet is a piece of interpreter code. All |
duke@435 | 42 | // interpreter code is generated into little codelets which |
duke@435 | 43 | // contain extra information for debugging and printing purposes. |
duke@435 | 44 | |
duke@435 | 45 | class InterpreterCodelet: public Stub { |
duke@435 | 46 | friend class VMStructs; |
duke@435 | 47 | private: |
duke@435 | 48 | int _size; // the size in bytes |
duke@435 | 49 | const char* _description; // a description of the codelet, for debugging & printing |
duke@435 | 50 | Bytecodes::Code _bytecode; // associated bytecode if any |
roland@4767 | 51 | DEBUG_ONLY(CodeStrings _strings;) // Comments for annotating assembler output. |
duke@435 | 52 | |
duke@435 | 53 | public: |
duke@435 | 54 | // Initialization/finalization |
kvn@4107 | 55 | void initialize(int size, |
roland@4767 | 56 | CodeStrings& strings) { _size = size; DEBUG_ONLY(_strings.assign(strings);) } |
duke@435 | 57 | void finalize() { ShouldNotCallThis(); } |
duke@435 | 58 | |
duke@435 | 59 | // General info/converters |
duke@435 | 60 | int size() const { return _size; } |
duke@435 | 61 | static int code_size_to_size(int code_size) { return round_to(sizeof(InterpreterCodelet), CodeEntryAlignment) + code_size; } |
duke@435 | 62 | |
duke@435 | 63 | // Code info |
duke@435 | 64 | address code_begin() const { return (address)this + round_to(sizeof(InterpreterCodelet), CodeEntryAlignment); } |
duke@435 | 65 | address code_end() const { return (address)this + size(); } |
duke@435 | 66 | |
duke@435 | 67 | // Debugging |
duke@435 | 68 | void verify(); |
bobv@2036 | 69 | void print_on(outputStream* st) const; |
bobv@2036 | 70 | void print() const { print_on(tty); } |
duke@435 | 71 | |
duke@435 | 72 | // Interpreter-specific initialization |
duke@435 | 73 | void initialize(const char* description, Bytecodes::Code bytecode); |
duke@435 | 74 | |
duke@435 | 75 | // Interpreter-specific attributes |
duke@435 | 76 | int code_size() const { return code_end() - code_begin(); } |
duke@435 | 77 | const char* description() const { return _description; } |
duke@435 | 78 | Bytecodes::Code bytecode() const { return _bytecode; } |
duke@435 | 79 | }; |
duke@435 | 80 | |
duke@435 | 81 | // Define a prototype interface |
duke@435 | 82 | DEF_STUB_INTERFACE(InterpreterCodelet); |
duke@435 | 83 | |
duke@435 | 84 | |
duke@435 | 85 | //------------------------------------------------------------------------------------------------------------------------ |
duke@435 | 86 | // A CodeletMark serves as an automatic creator/initializer for Codelets |
duke@435 | 87 | // (As a subclass of ResourceMark it automatically GC's the allocated |
duke@435 | 88 | // code buffer and assemblers). |
duke@435 | 89 | |
duke@435 | 90 | class CodeletMark: ResourceMark { |
duke@435 | 91 | private: |
duke@435 | 92 | InterpreterCodelet* _clet; |
duke@435 | 93 | InterpreterMacroAssembler** _masm; |
duke@435 | 94 | CodeBuffer _cb; |
duke@435 | 95 | |
duke@435 | 96 | int codelet_size() { |
duke@435 | 97 | // Request the whole code buffer (minus a little for alignment). |
duke@435 | 98 | // The commit call below trims it back for each codelet. |
duke@435 | 99 | int codelet_size = AbstractInterpreter::code()->available_space() - 2*K; |
duke@435 | 100 | |
duke@435 | 101 | // Guarantee there's a little bit of code space left. |
duke@435 | 102 | guarantee (codelet_size > 0 && (size_t)codelet_size > 2*K, |
duke@435 | 103 | "not enough space for interpreter generation"); |
duke@435 | 104 | |
duke@435 | 105 | return codelet_size; |
duke@435 | 106 | } |
duke@435 | 107 | |
duke@435 | 108 | public: |
duke@435 | 109 | CodeletMark( |
duke@435 | 110 | InterpreterMacroAssembler*& masm, |
duke@435 | 111 | const char* description, |
duke@435 | 112 | Bytecodes::Code bytecode = Bytecodes::_illegal): |
duke@435 | 113 | _clet((InterpreterCodelet*)AbstractInterpreter::code()->request(codelet_size())), |
duke@435 | 114 | _cb(_clet->code_begin(), _clet->code_size()) |
duke@435 | 115 | |
duke@435 | 116 | { // request all space (add some slack for Codelet data) |
duke@435 | 117 | assert (_clet != NULL, "we checked not enough space already"); |
duke@435 | 118 | |
duke@435 | 119 | // initialize Codelet attributes |
duke@435 | 120 | _clet->initialize(description, bytecode); |
duke@435 | 121 | // create assembler for code generation |
duke@435 | 122 | masm = new InterpreterMacroAssembler(&_cb); |
duke@435 | 123 | _masm = &masm; |
duke@435 | 124 | } |
duke@435 | 125 | |
duke@435 | 126 | ~CodeletMark() { |
duke@435 | 127 | // align so printing shows nop's instead of random code at the end (Codelets are aligned) |
duke@435 | 128 | (*_masm)->align(wordSize); |
duke@435 | 129 | // make sure all code is in code buffer |
duke@435 | 130 | (*_masm)->flush(); |
duke@435 | 131 | |
duke@435 | 132 | |
duke@435 | 133 | // commit Codelet |
roland@4767 | 134 | AbstractInterpreter::code()->commit((*_masm)->code()->pure_insts_size(), (*_masm)->code()->strings()); |
duke@435 | 135 | // make sure nobody can use _masm outside a CodeletMark lifespan |
duke@435 | 136 | *_masm = NULL; |
duke@435 | 137 | } |
duke@435 | 138 | }; |
duke@435 | 139 | |
duke@435 | 140 | // Wrapper classes to produce Interpreter/InterpreterGenerator from either |
duke@435 | 141 | // the c++ interpreter or the template interpreter. |
duke@435 | 142 | |
duke@435 | 143 | class Interpreter: public CC_INTERP_ONLY(CppInterpreter) NOT_CC_INTERP(TemplateInterpreter) { |
duke@435 | 144 | |
duke@435 | 145 | public: |
duke@435 | 146 | // Debugging/printing |
duke@435 | 147 | static InterpreterCodelet* codelet_containing(address pc) { return (InterpreterCodelet*)_code->stub_containing(pc); } |
stefank@2314 | 148 | #ifdef TARGET_ARCH_x86 |
stefank@2314 | 149 | # include "interpreter_x86.hpp" |
stefank@2314 | 150 | #endif |
stefank@2314 | 151 | #ifdef TARGET_ARCH_sparc |
stefank@2314 | 152 | # include "interpreter_sparc.hpp" |
stefank@2314 | 153 | #endif |
stefank@2314 | 154 | #ifdef TARGET_ARCH_zero |
stefank@2314 | 155 | # include "interpreter_zero.hpp" |
stefank@2314 | 156 | #endif |
bobv@2508 | 157 | #ifdef TARGET_ARCH_arm |
bobv@2508 | 158 | # include "interpreter_arm.hpp" |
bobv@2508 | 159 | #endif |
bobv@2508 | 160 | #ifdef TARGET_ARCH_ppc |
bobv@2508 | 161 | # include "interpreter_ppc.hpp" |
bobv@2508 | 162 | #endif |
stefank@2314 | 163 | |
duke@435 | 164 | }; |
stefank@2314 | 165 | |
stefank@2314 | 166 | #endif // SHARE_VM_INTERPRETER_INTERPRETER_HPP |