Path: blob/master/src/hotspot/share/interpreter/interpreter.cpp
40949 views
/*1* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "asm/macroAssembler.hpp"26#include "asm/macroAssembler.inline.hpp"27#include "compiler/disassembler.hpp"28#include "interpreter/interpreter.hpp"29#include "interpreter/interpreterRuntime.hpp"30#include "interpreter/interp_masm.hpp"31#include "interpreter/templateTable.hpp"32#include "memory/allocation.inline.hpp"33#include "memory/resourceArea.hpp"34#include "oops/arrayOop.hpp"35#include "oops/methodData.hpp"36#include "oops/method.hpp"37#include "oops/oop.inline.hpp"38#include "prims/forte.hpp"39#include "prims/jvmtiExport.hpp"40#include "prims/methodHandles.hpp"41#include "runtime/handles.inline.hpp"42#include "runtime/sharedRuntime.hpp"43#include "runtime/stubRoutines.hpp"44#include "runtime/timer.hpp"4546# define __ _masm->474849//------------------------------------------------------------------------------------------------------------------------50// Implementation of InterpreterCodelet5152void InterpreterCodelet::initialize(const char* description, Bytecodes::Code bytecode) {53_description = description;54_bytecode = bytecode;55}565758void InterpreterCodelet::verify() {59}606162void InterpreterCodelet::print_on(outputStream* st) const {63ttyLocker ttyl;6465if (PrintInterpreter) {66st->cr();67st->print_cr("----------------------------------------------------------------------");68}6970if (description() != NULL) st->print("%s ", description());71if (bytecode() >= 0 ) st->print("%d %s ", bytecode(), Bytecodes::name(bytecode()));72st->print_cr("[" INTPTR_FORMAT ", " INTPTR_FORMAT "] %d bytes",73p2i(code_begin()), p2i(code_end()), code_size());7475if (PrintInterpreter) {76st->cr();77Disassembler::decode(code_begin(), code_end(), st DEBUG_ONLY(COMMA &_strings));78}79}8081void InterpreterCodelet::print() const { print_on(tty); }8283CodeletMark::CodeletMark(InterpreterMacroAssembler*& masm,84const char* description,85Bytecodes::Code bytecode) :86_clet((InterpreterCodelet*)AbstractInterpreter::code()->request(codelet_size())),87_cb(_clet->code_begin(), _clet->code_size()) {88// Request all space (add some slack for Codelet data).89assert(_clet != NULL, "we checked not enough space already");9091// Initialize Codelet attributes.92_clet->initialize(description, bytecode);93// Create assembler for code generation.94masm = new InterpreterMacroAssembler(&_cb);95_masm = &masm;96}9798CodeletMark::~CodeletMark() {99// Align so printing shows nop's instead of random code at the end (Codelets are aligned).100(*_masm)->align(wordSize);101// Make sure all code is in code buffer.102(*_masm)->flush();103104// Commit Codelet.105int committed_code_size = (*_masm)->code()->pure_insts_size();106if (committed_code_size) {107CodeStrings cs NOT_PRODUCT(= (*_masm)->code()->strings());108AbstractInterpreter::code()->commit(committed_code_size, cs);109}110// Make sure nobody can use _masm outside a CodeletMark lifespan.111*_masm = NULL;112}113114// The reason that interpreter initialization is split into two parts is that the first part115// needs to run before methods are loaded (which with CDS implies linked also), and the other116// part needs to run after. The reason is that when methods are loaded (with CDS) or linked117// (without CDS), the i2c adapters are generated that assert we are currently in the interpreter.118// Asserting that requires knowledge about where the interpreter is in memory. Therefore,119// establishing the interpreter address must be done before methods are loaded. However,120// we would like to actually generate the interpreter after methods are loaded. That allows121// us to remove otherwise hardcoded offsets regarding fields that are needed in the interpreter122// code. This leads to a split if 1. reserving the memory for the interpreter, 2. loading methods123// and 3. generating the interpreter.124void interpreter_init_stub() {125Interpreter::initialize_stub();126}127128void interpreter_init_code() {129Interpreter::initialize_code();130#ifndef PRODUCT131if (TraceBytecodes) BytecodeTracer::set_closure(BytecodeTracer::std_closure());132#endif // PRODUCT133// need to hit every safepoint in order to call zapping routine134// register the interpreter135Forte::register_stub(136"Interpreter",137AbstractInterpreter::code()->code_start(),138AbstractInterpreter::code()->code_end()139);140141// notify JVMTI profiler142if (JvmtiExport::should_post_dynamic_code_generated()) {143JvmtiExport::post_dynamic_code_generated("Interpreter",144AbstractInterpreter::code()->code_start(),145AbstractInterpreter::code()->code_end());146}147}148149150