Sat, 07 Nov 2020 10:30:02 +0800
Added tag mips-jdk8u275-b01 for changeset d3b4d62f391f
1 /*
2 * Copyright (c) 1997, 2018, 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 */
25 /*
26 * This file has been modified by Loongson Technology in 2015. These
27 * modifications are Copyright (c) 2015 Loongson Technology, and are made
28 * available on the same license terms set forth above.
29 */
31 #ifndef SHARE_VM_INTERPRETER_INTERPRETER_HPP
32 #define SHARE_VM_INTERPRETER_INTERPRETER_HPP
34 #include "code/stubs.hpp"
35 #include "interpreter/cppInterpreter.hpp"
36 #include "interpreter/templateInterpreter.hpp"
37 #ifdef TARGET_ARCH_zero
38 # include "entry_zero.hpp"
39 #endif
41 // This file contains the platform-independent parts
42 // of the interpreter and the interpreter generator.
44 //------------------------------------------------------------------------------------------------------------------------
45 // An InterpreterCodelet is a piece of interpreter code. All
46 // interpreter code is generated into little codelets which
47 // contain extra information for debugging and printing purposes.
49 class InterpreterCodelet: public Stub {
50 friend class VMStructs;
51 private:
52 int _size; // the size in bytes
53 const char* _description; // a description of the codelet, for debugging & printing
54 Bytecodes::Code _bytecode; // associated bytecode if any
55 DEBUG_ONLY(CodeStrings _strings;) // Comments for annotating assembler output.
57 public:
58 // Initialization/finalization
59 void initialize(int size,
60 CodeStrings& strings) { _size = size;
61 DEBUG_ONLY(::new(&_strings) CodeStrings();)
62 DEBUG_ONLY(_strings.assign(strings);) }
63 void finalize() { ShouldNotCallThis(); }
65 // General info/converters
66 int size() const { return _size; }
67 static int code_size_to_size(int code_size) { return round_to(sizeof(InterpreterCodelet), CodeEntryAlignment) + code_size; }
69 // Code info
70 address code_begin() const { return (address)this + round_to(sizeof(InterpreterCodelet), CodeEntryAlignment); }
71 address code_end() const { return (address)this + size(); }
73 // Debugging
74 void verify();
75 void print_on(outputStream* st) const;
76 void print() const { print_on(tty); }
78 // Interpreter-specific initialization
79 void initialize(const char* description, Bytecodes::Code bytecode);
81 // Interpreter-specific attributes
82 int code_size() const { return code_end() - code_begin(); }
83 const char* description() const { return _description; }
84 Bytecodes::Code bytecode() const { return _bytecode; }
85 };
87 // Define a prototype interface
88 DEF_STUB_INTERFACE(InterpreterCodelet);
91 //------------------------------------------------------------------------------------------------------------------------
92 // A CodeletMark serves as an automatic creator/initializer for Codelets
93 // (As a subclass of ResourceMark it automatically GC's the allocated
94 // code buffer and assemblers).
96 class CodeletMark: ResourceMark {
97 private:
98 InterpreterCodelet* _clet;
99 InterpreterMacroAssembler** _masm;
100 CodeBuffer _cb;
102 int codelet_size() {
103 // Request the whole code buffer (minus a little for alignment).
104 // The commit call below trims it back for each codelet.
105 int codelet_size = AbstractInterpreter::code()->available_space() - 2*K;
107 // Guarantee there's a little bit of code space left.
108 guarantee (codelet_size > 0 && (size_t)codelet_size > 2*K,
109 "not enough space for interpreter generation");
111 return codelet_size;
112 }
114 public:
115 CodeletMark(
116 InterpreterMacroAssembler*& masm,
117 const char* description,
118 Bytecodes::Code bytecode = Bytecodes::_illegal):
119 _clet((InterpreterCodelet*)AbstractInterpreter::code()->request(codelet_size())),
120 _cb(_clet->code_begin(), _clet->code_size())
122 { // request all space (add some slack for Codelet data)
123 assert (_clet != NULL, "we checked not enough space already");
125 // initialize Codelet attributes
126 _clet->initialize(description, bytecode);
127 // create assembler for code generation
128 masm = new InterpreterMacroAssembler(&_cb);
129 _masm = &masm;
130 }
132 ~CodeletMark() {
133 // align so printing shows nop's instead of random code at the end (Codelets are aligned)
134 (*_masm)->align(wordSize);
135 // make sure all code is in code buffer
136 (*_masm)->flush();
139 // commit Codelet
140 AbstractInterpreter::code()->commit((*_masm)->code()->pure_insts_size(), (*_masm)->code()->strings());
141 // make sure nobody can use _masm outside a CodeletMark lifespan
142 *_masm = NULL;
143 }
144 };
146 // Wrapper classes to produce Interpreter/InterpreterGenerator from either
147 // the c++ interpreter or the template interpreter.
149 class Interpreter: public CC_INTERP_ONLY(CppInterpreter) NOT_CC_INTERP(TemplateInterpreter) {
151 public:
152 // Debugging/printing
153 static InterpreterCodelet* codelet_containing(address pc) { return (InterpreterCodelet*)_code->stub_containing(pc); }
154 #ifdef TARGET_ARCH_x86
155 # include "interpreter_x86.hpp"
156 #endif
157 #ifdef TARGET_ARCH_mips
158 # include "interpreter_mips.hpp"
159 #endif
160 #ifdef TARGET_ARCH_sparc
161 # include "interpreter_sparc.hpp"
162 #endif
163 #ifdef TARGET_ARCH_zero
164 # include "interpreter_zero.hpp"
165 #endif
166 #ifdef TARGET_ARCH_arm
167 # include "interpreter_arm.hpp"
168 #endif
169 #ifdef TARGET_ARCH_ppc
170 # include "interpreter_ppc.hpp"
171 #endif
173 };
175 #endif // SHARE_VM_INTERPRETER_INTERPRETER_HPP