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