Path: blob/master/src/hotspot/share/interpreter/templateTable.hpp
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#ifndef SHARE_INTERPRETER_TEMPLATETABLE_HPP25#define SHARE_INTERPRETER_TEMPLATETABLE_HPP2627#include "interpreter/bytecodes.hpp"28#include "memory/allocation.hpp"29#include "runtime/frame.hpp"30#include "utilities/macros.hpp"3132#ifndef ZERO33// All the necessary definitions used for (bytecode) template generation. Instead of34// spreading the implementation functionality for each bytecode in the interpreter35// and the snippet generator, a template is assigned to each bytecode which can be36// used to generate the bytecode's implementation if needed.3738class InterpreterMacroAssembler;3940// A Template describes the properties of a code template for a given bytecode41// and provides a generator to generate the code template.4243class Template {44private:45enum Flags {46uses_bcp_bit, // set if template needs the bcp pointing to bytecode47does_dispatch_bit, // set if template dispatches on its own48calls_vm_bit, // set if template calls the vm49wide_bit // set if template belongs to a wide instruction50};5152typedef void (*generator)(int arg);5354int _flags; // describes interpreter template properties (bcp unknown)55TosState _tos_in; // tos cache state before template execution56TosState _tos_out; // tos cache state after template execution57generator _gen; // template code generator58int _arg; // argument for template code generator5960void initialize(int flags, TosState tos_in, TosState tos_out, generator gen, int arg);6162friend class TemplateTable;6364public:65Bytecodes::Code bytecode() const;66bool is_valid() const { return _gen != NULL; }67bool uses_bcp() const { return (_flags & (1 << uses_bcp_bit )) != 0; }68bool does_dispatch() const { return (_flags & (1 << does_dispatch_bit)) != 0; }69bool calls_vm() const { return (_flags & (1 << calls_vm_bit )) != 0; }70bool is_wide() const { return (_flags & (1 << wide_bit )) != 0; }71TosState tos_in() const { return _tos_in; }72TosState tos_out() const { return _tos_out; }73void generate(InterpreterMacroAssembler* masm);74};757677// The TemplateTable defines all Templates and provides accessor functions78// to get the template for a given bytecode.7980class TemplateTable: AllStatic {81public:82enum Operation { add, sub, mul, div, rem, _and, _or, _xor, shl, shr, ushr };83enum Condition { equal, not_equal, less, less_equal, greater, greater_equal };84enum CacheByte { f1_byte = 1, f2_byte = 2 }; // byte_no codes85enum RewriteControl { may_rewrite, may_not_rewrite }; // control for fast code under CDS8687private:88static Template _template_table [Bytecodes::number_of_codes];89static Template _template_table_wide[Bytecodes::number_of_codes];9091static Template* _desc; // the current template to be generated92static Bytecodes::Code bytecode() { return _desc->bytecode(); }93public:94//%note templates_195static InterpreterMacroAssembler* _masm; // the assembler used when generating templates9697private:9899// special registers100static inline Address at_bcp(int offset);101102// helpers103static void unimplemented_bc();104static void patch_bytecode(Bytecodes::Code bc, Register bc_reg,105Register temp_reg, bool load_bc_into_bc_reg = true, int byte_no = -1);106107// C calls108static void call_VM(Register oop_result, address entry_point);109static void call_VM(Register oop_result, address entry_point, Register arg_1);110static void call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2);111static void call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, Register arg_3);112113// these overloadings are not presently used on SPARC:114static void call_VM(Register oop_result, Register last_java_sp, address entry_point);115static void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1);116static void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2);117static void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2, Register arg_3);118119// bytecodes120static void nop();121122static void aconst_null();123static void iconst(int value);124static void lconst(int value);125static void fconst(int value);126static void dconst(int value);127128static void bipush();129static void sipush();130static void ldc(bool wide);131static void ldc2_w();132static void fast_aldc(bool wide);133134static void locals_index(Register reg, int offset = 1);135static void iload();136static void fast_iload();137static void fast_iload2();138static void fast_icaload();139static void lload();140static void fload();141static void dload();142static void aload();143144static void locals_index_wide(Register reg);145static void wide_iload();146static void wide_lload();147static void wide_fload();148static void wide_dload();149static void wide_aload();150151static void iaload();152static void laload();153static void faload();154static void daload();155static void aaload();156static void baload();157static void caload();158static void saload();159160static void iload(int n);161static void lload(int n);162static void fload(int n);163static void dload(int n);164static void aload(int n);165static void aload_0();166static void nofast_aload_0();167static void nofast_iload();168static void iload_internal(RewriteControl rc = may_rewrite);169static void aload_0_internal(RewriteControl rc = may_rewrite);170171static void istore();172static void lstore();173static void fstore();174static void dstore();175static void astore();176177static void wide_istore();178static void wide_lstore();179static void wide_fstore();180static void wide_dstore();181static void wide_astore();182183static void iastore();184static void lastore();185static void fastore();186static void dastore();187static void aastore();188static void bastore();189static void castore();190static void sastore();191192static void istore(int n);193static void lstore(int n);194static void fstore(int n);195static void dstore(int n);196static void astore(int n);197198static void pop();199static void pop2();200static void dup();201static void dup_x1();202static void dup_x2();203static void dup2();204static void dup2_x1();205static void dup2_x2();206static void swap();207208static void iop2(Operation op);209static void lop2(Operation op);210static void fop2(Operation op);211static void dop2(Operation op);212213static void idiv();214static void irem();215216static void lmul();217static void ldiv();218static void lrem();219static void lshl();220static void lshr();221static void lushr();222223static void ineg();224static void lneg();225static void fneg();226static void dneg();227228static void iinc();229static void wide_iinc();230static void convert();231static void lcmp();232233static void float_cmp (bool is_float, int unordered_result);234static void float_cmp (int unordered_result);235static void double_cmp(int unordered_result);236237static void branch(bool is_jsr, bool is_wide);238static void if_0cmp (Condition cc);239static void if_icmp (Condition cc);240static void if_nullcmp(Condition cc);241static void if_acmp (Condition cc);242243static void _goto();244static void jsr();245static void ret();246static void wide_ret();247248static void goto_w();249static void jsr_w();250251static void tableswitch();252static void lookupswitch();253static void fast_linearswitch();254static void fast_binaryswitch();255256static void _return(TosState state);257258static void resolve_cache_and_index(int byte_no, // one of 1,2,11259Register cache, // output for CP cache260Register index, // output for CP index261size_t index_size); // one of 1,2,4262static void load_invoke_cp_cache_entry(int byte_no,263Register method,264Register itable_index,265Register flags,266bool is_invokevirtual,267bool is_virtual_final,268bool is_invokedynamic);269static void load_field_cp_cache_entry(Register obj,270Register cache,271Register index,272Register offset,273Register flags,274bool is_static);275static void invokevirtual(int byte_no);276static void invokespecial(int byte_no);277static void invokestatic(int byte_no);278static void invokeinterface(int byte_no);279static void invokedynamic(int byte_no);280static void invokehandle(int byte_no);281static void fast_invokevfinal(int byte_no);282283static void getfield_or_static(int byte_no, bool is_static, RewriteControl rc = may_rewrite);284static void putfield_or_static(int byte_no, bool is_static, RewriteControl rc = may_rewrite);285286static void getfield(int byte_no);287static void putfield(int byte_no);288static void nofast_getfield(int byte_no);289static void nofast_putfield(int byte_no);290static void getstatic(int byte_no);291static void putstatic(int byte_no);292static void pop_and_check_object(Register obj);293static void condy_helper(Label& Done); // shared by ldc instances294295static void _new();296static void newarray();297static void anewarray();298static void arraylength();299static void checkcast();300static void instanceof();301302static void athrow();303304static void monitorenter();305static void monitorexit();306307static void wide();308static void multianewarray();309310static void fast_xaccess(TosState state);311static void fast_accessfield(TosState state);312static void fast_storefield(TosState state);313314static void _breakpoint();315316static void shouldnotreachhere();317318// jvmti support319static void jvmti_post_field_access(Register cache, Register index, bool is_static, bool has_tos);320static void jvmti_post_field_mod(Register cache, Register index, bool is_static);321static void jvmti_post_fast_field_mod();322323// debugging of TemplateGenerator324static void transition(TosState tos_in, TosState tos_out);// checks if in/out states expected by template generator correspond to table entries325326// initialization helpers327static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)( ), char filler );328static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(int arg ), int arg );329static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(bool arg ), bool arg );330static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(TosState tos), TosState tos);331static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(Operation op), Operation op);332static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(Condition cc), Condition cc);333334friend class Template;335336// InterpreterMacroAssembler::is_a(), etc., need TemplateTable::call_VM().337friend class InterpreterMacroAssembler;338339public:340// Initialization341static void initialize();342343// Templates344static Template* template_for (Bytecodes::Code code) { Bytecodes::check (code); return &_template_table [code]; }345static Template* template_for_wide(Bytecodes::Code code) { Bytecodes::wide_check(code); return &_template_table_wide[code]; }346347// Platform specifics348#include CPU_HEADER(templateTable)349350};351#endif /* !ZERO */352353#endif // SHARE_INTERPRETER_TEMPLATETABLE_HPP354355356