1/*
2 * Copyright (c) 1997, 2019, 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_INTERPRETER_INTERPRETER_HPP
26#define SHARE_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#include "utilities/align.hpp"
33
34// This file contains the platform-independent parts
35// of the interpreter and the interpreter generator.
36
37class InterpreterMacroAssembler;
38
39//------------------------------------------------------------------------------------------------------------------------
40// An InterpreterCodelet is a piece of interpreter code. All
41// interpreter code is generated into little codelets which
42// contain extra information for debugging and printing purposes.
43
44class InterpreterCodelet: public Stub {
45 friend class VMStructs;
46 friend class CodeCacheDumper; // possible extension [do not remove]
47 private:
48 int _size; // the size in bytes
49 const char* _description; // a description of the codelet, for debugging & printing
50 Bytecodes::Code _bytecode; // associated bytecode if any
51 DEBUG_ONLY(CodeStrings _strings;) // Comments for annotating assembler output.
52
53 public:
54 // Initialization/finalization
55 void initialize(int size,
56 CodeStrings& strings) { _size = size;
57 DEBUG_ONLY(::new(&_strings) CodeStrings();)
58 DEBUG_ONLY(_strings.assign(strings);) }
59 void finalize() { ShouldNotCallThis(); }
60
61 // General info/converters
62 int size() const { return _size; }
63 static int code_size_to_size(int code_size) { return align_up((int)sizeof(InterpreterCodelet), CodeEntryAlignment) + code_size; }
64
65 // Code info
66 address code_begin() const { return (address)this + align_up(sizeof(InterpreterCodelet), CodeEntryAlignment); }
67 address code_end() const { return (address)this + size(); }
68
69 // Debugging
70 void verify();
71 void print_on(outputStream* st) const;
72 void print() const;
73
74 // Interpreter-specific initialization
75 void initialize(const char* description, Bytecodes::Code bytecode);
76
77 // Interpreter-specific attributes
78 int code_size() const { return code_end() - code_begin(); }
79 const char* description() const { return _description; }
80 Bytecodes::Code bytecode() const { return _bytecode; }
81};
82
83// Define a prototype interface
84DEF_STUB_INTERFACE(InterpreterCodelet);
85
86
87//------------------------------------------------------------------------------------------------------------------------
88// A CodeletMark serves as an automatic creator/initializer for Codelets
89// (As a subclass of ResourceMark it automatically GC's the allocated
90// code buffer and assemblers).
91
92class CodeletMark: ResourceMark {
93 private:
94 InterpreterCodelet* _clet;
95 InterpreterMacroAssembler** _masm;
96 CodeBuffer _cb;
97
98 int codelet_size() {
99 // Request the whole code buffer (minus a little for alignment).
100 // The commit call below trims it back for each codelet.
101 int codelet_size = AbstractInterpreter::code()->available_space() - 2*K;
102
103 // Guarantee there's a little bit of code space left.
104 guarantee(codelet_size > 0 && (size_t)codelet_size > 2*K,
105 "not enough space for interpreter generation");
106
107 return codelet_size;
108 }
109
110 public:
111 CodeletMark(InterpreterMacroAssembler*& masm,
112 const char* description,
113 Bytecodes::Code bytecode = Bytecodes::_illegal);
114 ~CodeletMark();
115};
116
117// Wrapper typedef to use the name Interpreter to mean either
118// the c++ interpreter or the template interpreter.
119
120typedef CC_INTERP_ONLY(CppInterpreter) NOT_CC_INTERP(TemplateInterpreter) Interpreter;
121
122#endif // SHARE_INTERPRETER_INTERPRETER_HPP
123