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#include "precompiled.hpp"
26#include "asm/macroAssembler.hpp"
27#include "asm/macroAssembler.inline.hpp"
28#include "compiler/disassembler.hpp"
29#include "interpreter/bytecodeHistogram.hpp"
30#include "interpreter/bytecodeInterpreter.hpp"
31#include "interpreter/interpreter.hpp"
32#include "interpreter/interpreterRuntime.hpp"
33#include "interpreter/interp_masm.hpp"
34#include "interpreter/templateTable.hpp"
35#include "memory/allocation.inline.hpp"
36#include "memory/resourceArea.hpp"
37#include "oops/arrayOop.hpp"
38#include "oops/methodData.hpp"
39#include "oops/method.hpp"
40#include "oops/oop.inline.hpp"
41#include "prims/forte.hpp"
42#include "prims/jvmtiExport.hpp"
43#include "prims/methodHandles.hpp"
44#include "runtime/handles.inline.hpp"
45#include "runtime/sharedRuntime.hpp"
46#include "runtime/stubRoutines.hpp"
47#include "runtime/timer.hpp"
48
49# define __ _masm->
50
51
52//------------------------------------------------------------------------------------------------------------------------
53// Implementation of InterpreterCodelet
54
55void InterpreterCodelet::initialize(const char* description, Bytecodes::Code bytecode) {
56 _description = description;
57 _bytecode = bytecode;
58}
59
60
61void InterpreterCodelet::verify() {
62}
63
64
65void InterpreterCodelet::print_on(outputStream* st) const {
66 ttyLocker ttyl;
67
68 if (PrintInterpreter) {
69 st->cr();
70 st->print_cr("----------------------------------------------------------------------");
71 }
72
73 if (description() != NULL) st->print("%s ", description());
74 if (bytecode() >= 0 ) st->print("%d %s ", bytecode(), Bytecodes::name(bytecode()));
75 st->print_cr("[" INTPTR_FORMAT ", " INTPTR_FORMAT "] %d bytes",
76 p2i(code_begin()), p2i(code_end()), code_size());
77
78 if (PrintInterpreter) {
79 st->cr();
80 Disassembler::decode(code_begin(), code_end(), st, DEBUG_ONLY(_strings) NOT_DEBUG(CodeStrings()));
81 }
82}
83
84void InterpreterCodelet::print() const { print_on(tty); }
85
86CodeletMark::CodeletMark(InterpreterMacroAssembler*& masm,
87 const char* description,
88 Bytecodes::Code bytecode) :
89 _clet((InterpreterCodelet*)AbstractInterpreter::code()->request(codelet_size())),
90 _cb(_clet->code_begin(), _clet->code_size()) {
91 // Request all space (add some slack for Codelet data).
92 assert(_clet != NULL, "we checked not enough space already");
93
94 // Initialize Codelet attributes.
95 _clet->initialize(description, bytecode);
96 // Create assembler for code generation.
97 masm = new InterpreterMacroAssembler(&_cb);
98 _masm = &masm;
99}
100
101CodeletMark::~CodeletMark() {
102 // Align so printing shows nop's instead of random code at the end (Codelets are aligned).
103 (*_masm)->align(wordSize);
104 // Make sure all code is in code buffer.
105 (*_masm)->flush();
106
107 // Commit Codelet.
108 int committed_code_size = (*_masm)->code()->pure_insts_size();
109 if (committed_code_size) {
110 AbstractInterpreter::code()->commit(committed_code_size, (*_masm)->code()->strings());
111 }
112 // Make sure nobody can use _masm outside a CodeletMark lifespan.
113 *_masm = NULL;
114}
115
116
117void interpreter_init() {
118 Interpreter::initialize();
119#ifndef PRODUCT
120 if (TraceBytecodes) BytecodeTracer::set_closure(BytecodeTracer::std_closure());
121#endif // PRODUCT
122 // need to hit every safepoint in order to call zapping routine
123 // register the interpreter
124 Forte::register_stub(
125 "Interpreter",
126 AbstractInterpreter::code()->code_start(),
127 AbstractInterpreter::code()->code_end()
128 );
129
130 // notify JVMTI profiler
131 if (JvmtiExport::should_post_dynamic_code_generated()) {
132 JvmtiExport::post_dynamic_code_generated("Interpreter",
133 AbstractInterpreter::code()->code_start(),
134 AbstractInterpreter::code()->code_end());
135 }
136}
137