abstractInterpreter.hpp revision 0
0N/A/*
0N/A * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
0N/A *
0N/A */
0N/A
0N/A// This file contains the platform-independant parts
0N/A// of the abstract interpreter and the abstract interpreter generator.
0N/A
0N/A// Organization of the interpreter(s). There exists two different interpreters in hotpot
0N/A// an assembly language version (aka template interpreter) and a high level language version
0N/A// (aka c++ interpreter). Th division of labor is as follows:
0N/A
0N/A// Template Interpreter C++ Interpreter Functionality
0N/A//
0N/A// templateTable* bytecodeInterpreter* actual interpretation of bytecodes
0N/A//
0N/A// templateInterpreter* cppInterpreter* generation of assembly code that creates
0N/A// and manages interpreter runtime frames.
0N/A// Also code for populating interpreter
0N/A// frames created during deoptimization.
0N/A//
0N/A// For both template and c++ interpreter. There are common files for aspects of the interpreter
0N/A// that are generic to both interpreters. This is the layout:
0N/A//
0N/A// abstractInterpreter.hpp: generic description of the interpreter.
0N/A// interpreter*: generic frame creation and handling.
0N/A//
0N/A
0N/A//------------------------------------------------------------------------------------------------------------------------
0N/A// The C++ interface to the bytecode interpreter(s).
0N/A
0N/Aclass AbstractInterpreter: AllStatic {
0N/A friend class VMStructs;
0N/A friend class Interpreter;
0N/A friend class CppInterpreterGenerator;
0N/A public:
0N/A enum MethodKind {
0N/A zerolocals, // method needs locals initialization
0N/A zerolocals_synchronized, // method needs locals initialization & is synchronized
0N/A native, // native method
0N/A native_synchronized, // native method & is synchronized
0N/A empty, // empty method (code: _return)
0N/A accessor, // accessor method (code: _aload_0, _getfield, _(a|i)return)
0N/A abstract, // abstract method (throws an AbstractMethodException)
0N/A java_lang_math_sin, // implementation of java.lang.Math.sin (x)
0N/A java_lang_math_cos, // implementation of java.lang.Math.cos (x)
0N/A java_lang_math_tan, // implementation of java.lang.Math.tan (x)
0N/A java_lang_math_abs, // implementation of java.lang.Math.abs (x)
0N/A java_lang_math_sqrt, // implementation of java.lang.Math.sqrt (x)
0N/A java_lang_math_log, // implementation of java.lang.Math.log (x)
0N/A java_lang_math_log10, // implementation of java.lang.Math.log10 (x)
0N/A number_of_method_entries,
0N/A invalid = -1
0N/A };
0N/A
0N/A enum SomeConstants {
0N/A number_of_result_handlers = 10 // number of result handlers for native calls
0N/A };
0N/A
0N/A protected:
0N/A static StubQueue* _code; // the interpreter code (codelets)
0N/A
0N/A static bool _notice_safepoints; // true if safepoints are activated
0N/A
0N/A static address _native_entry_begin; // Region for native entry code
0N/A static address _native_entry_end;
0N/A
0N/A // method entry points
0N/A static address _entry_table[number_of_method_entries]; // entry points for a given method
0N/A static address _native_abi_to_tosca[number_of_result_handlers]; // for native method result handlers
0N/A static address _slow_signature_handler; // the native method generic (slow) signature handler
0N/A
0N/A static address _rethrow_exception_entry; // rethrows an activation in previous frame
0N/A
0N/A
0N/A
0N/A friend class AbstractInterpreterGenerator;
0N/A friend class InterpreterGenerator;
0N/A friend class InterpreterMacroAssembler;
0N/A
0N/A public:
0N/A // Initialization/debugging
0N/A static void initialize();
0N/A static StubQueue* code() { return _code; }
0N/A
0N/A
0N/A // Method activation
0N/A static MethodKind method_kind(methodHandle m);
0N/A static address entry_for_kind(MethodKind k) { assert(0 <= k && k < number_of_method_entries, "illegal kind"); return _entry_table[k]; }
0N/A static address entry_for_method(methodHandle m) { return _entry_table[method_kind(m)]; }
0N/A
0N/A static void print_method_kind(MethodKind kind) PRODUCT_RETURN;
0N/A
0N/A // Runtime support
0N/A
0N/A // length = invoke bytecode length (to advance to next bytecode)
0N/A static address deopt_entry (TosState state, int length) { ShouldNotReachHere(); return NULL; }
0N/A static address return_entry (TosState state, int length) { ShouldNotReachHere(); return NULL; }
0N/A
0N/A static address rethrow_exception_entry() { return _rethrow_exception_entry; }
0N/A
0N/A // Activation size in words for a method that is just being called.
0N/A // Parameters haven't been pushed so count them too.
0N/A static int size_top_interpreter_activation(methodOop method);
0N/A
0N/A // Deoptimization support
0N/A static address continuation_for(methodOop method,
0N/A address bcp,
0N/A int callee_parameters,
0N/A bool is_top_frame,
0N/A bool& use_next_mdp);
0N/A
0N/A // share implementation of size_activation and layout_activation:
0N/A static int size_activation(methodOop method,
0N/A int temps,
0N/A int popframe_args,
0N/A int monitors,
0N/A int callee_params,
0N/A int callee_locals,
0N/A bool is_top_frame);
0N/A
0N/A static int layout_activation(methodOop method,
0N/A int temps,
0N/A int popframe_args,
0N/A int monitors,
0N/A int callee_params,
0N/A int callee_locals,
0N/A frame* caller,
0N/A frame* interpreter_frame,
0N/A bool is_top_frame);
0N/A
0N/A // Runtime support
0N/A static bool is_not_reached( methodHandle method, int bci);
0N/A // Safepoint support
0N/A static void notice_safepoints() { ShouldNotReachHere(); } // stops the thread when reaching a safepoint
0N/A static void ignore_safepoints() { ShouldNotReachHere(); } // ignores safepoints
0N/A
0N/A // Support for native calls
0N/A static address slow_signature_handler() { return _slow_signature_handler; }
0N/A static address result_handler(BasicType type) { return _native_abi_to_tosca[BasicType_as_index(type)]; }
0N/A static int BasicType_as_index(BasicType type); // computes index into result_handler_by_index table
0N/A static bool in_native_entry(address pc) { return _native_entry_begin <= pc && pc < _native_entry_end; }
0N/A // Debugging/printing
0N/A static void print(); // prints the interpreter code
0N/A
0N/A // Support for Tagged Stacks
0N/A //
0N/A // Tags are stored on the Java Expression stack above the value:
0N/A //
0N/A // tag
0N/A // value
0N/A //
0N/A // For double values:
0N/A //
0N/A // tag2
0N/A // high word
0N/A // tag1
0N/A // low word
0N/A
0N/A public:
0N/A static int stackElementWords() { return TaggedStackInterpreter ? 2 : 1; }
0N/A static int stackElementSize() { return stackElementWords()*wordSize; }
0N/A static int logStackElementSize() { return
0N/A TaggedStackInterpreter? LogBytesPerWord+1 : LogBytesPerWord; }
0N/A
0N/A // Tag is at pointer, value is one below for a stack growing down
0N/A // (or above for stack growing up)
0N/A static int value_offset_in_bytes() {
0N/A return TaggedStackInterpreter ?
0N/A frame::interpreter_frame_expression_stack_direction() * wordSize : 0;
0N/A }
0N/A static int tag_offset_in_bytes() {
0N/A assert(TaggedStackInterpreter, "should not call this");
0N/A return 0;
0N/A }
0N/A
0N/A // Tagged Locals
0N/A // Locals are stored relative to Llocals:
0N/A //
0N/A // tag <- Llocals[n]
0N/A // value
0N/A //
0N/A // Category 2 types are indexed as:
0N/A //
0N/A // tag <- Llocals[-n]
0N/A // high word
0N/A // tag <- Llocals[-n+1]
0N/A // low word
0N/A //
0N/A
0N/A // Local values relative to locals[n]
0N/A static int local_offset_in_bytes(int n) {
0N/A return ((frame::interpreter_frame_expression_stack_direction() * n) *
0N/A stackElementSize()) + value_offset_in_bytes();
0N/A }
0N/A static int local_tag_offset_in_bytes(int n) {
0N/A assert(TaggedStackInterpreter, "should not call this");
0N/A return ((frame::interpreter_frame_expression_stack_direction() * n) *
0N/A stackElementSize()) + tag_offset_in_bytes();
0N/A }
0N/A
0N/A};
0N/A
0N/A//------------------------------------------------------------------------------------------------------------------------
0N/A// The interpreter generator.
0N/A
0N/Aclass Template;
0N/Aclass AbstractInterpreterGenerator: public StackObj {
0N/A protected:
0N/A InterpreterMacroAssembler* _masm;
0N/A
0N/A // shared code sequences
0N/A // Converter for native abi result to tosca result
0N/A address generate_result_handler_for(BasicType type);
0N/A address generate_slow_signature_handler();
0N/A
0N/A // entry point generator
0N/A address generate_method_entry(AbstractInterpreter::MethodKind kind);
0N/A
0N/A void bang_stack_shadow_pages(bool native_call);
0N/A
0N/A void generate_all();
0N/A
0N/A public:
0N/A AbstractInterpreterGenerator(StubQueue* _code);
0N/A};