Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/interpreter/interpreter.hpp
32285 views
/*1* Copyright (c) 1997, 2018, 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#ifndef SHARE_VM_INTERPRETER_INTERPRETER_HPP25#define SHARE_VM_INTERPRETER_INTERPRETER_HPP2627#include "code/stubs.hpp"28#include "interpreter/cppInterpreter.hpp"29#include "interpreter/templateInterpreter.hpp"30#ifdef TARGET_ARCH_zero31# include "entry_zero.hpp"32#endif3334// This file contains the platform-independent parts35// of the interpreter and the interpreter generator.3637//------------------------------------------------------------------------------------------------------------------------38// An InterpreterCodelet is a piece of interpreter code. All39// interpreter code is generated into little codelets which40// contain extra information for debugging and printing purposes.4142class InterpreterCodelet: public Stub {43friend class VMStructs;44private:45int _size; // the size in bytes46const char* _description; // a description of the codelet, for debugging & printing47Bytecodes::Code _bytecode; // associated bytecode if any48DEBUG_ONLY(CodeStrings _strings;) // Comments for annotating assembler output.4950public:51// Initialization/finalization52void initialize(int size,53CodeStrings& strings) { _size = size;54DEBUG_ONLY(::new(&_strings) CodeStrings();)55DEBUG_ONLY(_strings.assign(strings);) }56void finalize() { ShouldNotCallThis(); }5758// General info/converters59int size() const { return _size; }60static int code_size_to_size(int code_size) { return round_to(sizeof(InterpreterCodelet), CodeEntryAlignment) + code_size; }6162// Code info63address code_begin() const { return (address)this + round_to(sizeof(InterpreterCodelet), CodeEntryAlignment); }64address code_end() const { return (address)this + size(); }6566// Debugging67void verify();68void print_on(outputStream* st) const;69void print() const { print_on(tty); }7071// Interpreter-specific initialization72void initialize(const char* description, Bytecodes::Code bytecode);7374// Interpreter-specific attributes75int code_size() const { return code_end() - code_begin(); }76const char* description() const { return _description; }77Bytecodes::Code bytecode() const { return _bytecode; }78};7980// Define a prototype interface81DEF_STUB_INTERFACE(InterpreterCodelet);828384//------------------------------------------------------------------------------------------------------------------------85// A CodeletMark serves as an automatic creator/initializer for Codelets86// (As a subclass of ResourceMark it automatically GC's the allocated87// code buffer and assemblers).8889class CodeletMark: ResourceMark {90private:91InterpreterCodelet* _clet;92InterpreterMacroAssembler** _masm;93CodeBuffer _cb;9495int codelet_size() {96// Request the whole code buffer (minus a little for alignment).97// The commit call below trims it back for each codelet.98int codelet_size = AbstractInterpreter::code()->available_space() - 2*K;99100// Guarantee there's a little bit of code space left.101guarantee (codelet_size > 0 && (size_t)codelet_size > 2*K,102"not enough space for interpreter generation");103104return codelet_size;105}106107public:108CodeletMark(109InterpreterMacroAssembler*& masm,110const char* description,111Bytecodes::Code bytecode = Bytecodes::_illegal):112_clet((InterpreterCodelet*)AbstractInterpreter::code()->request(codelet_size())),113_cb(_clet->code_begin(), _clet->code_size())114115{ // request all space (add some slack for Codelet data)116assert (_clet != NULL, "we checked not enough space already");117118// initialize Codelet attributes119_clet->initialize(description, bytecode);120// create assembler for code generation121masm = new InterpreterMacroAssembler(&_cb);122_masm = &masm;123}124125~CodeletMark() {126// align so printing shows nop's instead of random code at the end (Codelets are aligned)127(*_masm)->align(wordSize);128// make sure all code is in code buffer129(*_masm)->flush();130131132// commit Codelet133AbstractInterpreter::code()->commit((*_masm)->code()->pure_insts_size(), (*_masm)->code()->strings());134// make sure nobody can use _masm outside a CodeletMark lifespan135*_masm = NULL;136}137};138139// Wrapper classes to produce Interpreter/InterpreterGenerator from either140// the c++ interpreter or the template interpreter.141142class Interpreter: public CC_INTERP_ONLY(CppInterpreter) NOT_CC_INTERP(TemplateInterpreter) {143144public:145// Debugging/printing146static InterpreterCodelet* codelet_containing(address pc) { return (InterpreterCodelet*)_code->stub_containing(pc); }147#ifdef TARGET_ARCH_x86148# include "interpreter_x86.hpp"149#endif150#ifdef TARGET_ARCH_aarch32151# include "interpreter_aarch32.hpp"152#endif153#ifdef TARGET_ARCH_aarch64154# include "interpreter_aarch64.hpp"155#endif156#ifdef TARGET_ARCH_sparc157# include "interpreter_sparc.hpp"158#endif159#ifdef TARGET_ARCH_zero160# include "interpreter_zero.hpp"161#endif162#ifdef TARGET_ARCH_arm163# include "interpreter_arm.hpp"164#endif165#ifdef TARGET_ARCH_ppc166# include "interpreter_ppc.hpp"167#endif168169};170171#endif // SHARE_VM_INTERPRETER_INTERPRETER_HPP172173174