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