annotate src/share/vm/interpreter/interpreter.hpp @ 1601:126ea7725993

6953477: Increase portability and flexibility of building Hotspot Summary: A collection of portability improvements including shared code support for PPC, ARM platforms, software floating point, cross compilation support and improvements in error crash detail. Reviewed-by: phh, never, coleenp, dholmes
author bobv
date Tue, 03 Aug 2010 08:13:38 -0400
parents c18cbe5936b8
children 3e8fbc61cee8
rev   line source
duke@0 1 /*
trims@1472 2 * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
twisti@605 25 // This file contains the platform-independent parts
duke@0 26 // of the interpreter and the interpreter generator.
duke@0 27
duke@0 28 //------------------------------------------------------------------------------------------------------------------------
duke@0 29 // An InterpreterCodelet is a piece of interpreter code. All
duke@0 30 // interpreter code is generated into little codelets which
duke@0 31 // contain extra information for debugging and printing purposes.
duke@0 32
duke@0 33 class InterpreterCodelet: public Stub {
duke@0 34 friend class VMStructs;
duke@0 35 private:
duke@0 36 int _size; // the size in bytes
duke@0 37 const char* _description; // a description of the codelet, for debugging & printing
duke@0 38 Bytecodes::Code _bytecode; // associated bytecode if any
duke@0 39
duke@0 40 public:
duke@0 41 // Initialization/finalization
duke@0 42 void initialize(int size) { _size = size; }
duke@0 43 void finalize() { ShouldNotCallThis(); }
duke@0 44
duke@0 45 // General info/converters
duke@0 46 int size() const { return _size; }
duke@0 47 static int code_size_to_size(int code_size) { return round_to(sizeof(InterpreterCodelet), CodeEntryAlignment) + code_size; }
duke@0 48
duke@0 49 // Code info
duke@0 50 address code_begin() const { return (address)this + round_to(sizeof(InterpreterCodelet), CodeEntryAlignment); }
duke@0 51 address code_end() const { return (address)this + size(); }
duke@0 52
duke@0 53 // Debugging
duke@0 54 void verify();
bobv@1601 55 void print_on(outputStream* st) const;
bobv@1601 56 void print() const { print_on(tty); }
duke@0 57
duke@0 58 // Interpreter-specific initialization
duke@0 59 void initialize(const char* description, Bytecodes::Code bytecode);
duke@0 60
duke@0 61 // Interpreter-specific attributes
duke@0 62 int code_size() const { return code_end() - code_begin(); }
duke@0 63 const char* description() const { return _description; }
duke@0 64 Bytecodes::Code bytecode() const { return _bytecode; }
duke@0 65 };
duke@0 66
duke@0 67 // Define a prototype interface
duke@0 68 DEF_STUB_INTERFACE(InterpreterCodelet);
duke@0 69
duke@0 70
duke@0 71 //------------------------------------------------------------------------------------------------------------------------
duke@0 72 // A CodeletMark serves as an automatic creator/initializer for Codelets
duke@0 73 // (As a subclass of ResourceMark it automatically GC's the allocated
duke@0 74 // code buffer and assemblers).
duke@0 75
duke@0 76 class CodeletMark: ResourceMark {
duke@0 77 private:
duke@0 78 InterpreterCodelet* _clet;
duke@0 79 InterpreterMacroAssembler** _masm;
duke@0 80 CodeBuffer _cb;
duke@0 81
duke@0 82 int codelet_size() {
duke@0 83 // Request the whole code buffer (minus a little for alignment).
duke@0 84 // The commit call below trims it back for each codelet.
duke@0 85 int codelet_size = AbstractInterpreter::code()->available_space() - 2*K;
duke@0 86
duke@0 87 // Guarantee there's a little bit of code space left.
duke@0 88 guarantee (codelet_size > 0 && (size_t)codelet_size > 2*K,
duke@0 89 "not enough space for interpreter generation");
duke@0 90
duke@0 91 return codelet_size;
duke@0 92 }
duke@0 93
duke@0 94 public:
duke@0 95 CodeletMark(
duke@0 96 InterpreterMacroAssembler*& masm,
duke@0 97 const char* description,
duke@0 98 Bytecodes::Code bytecode = Bytecodes::_illegal):
duke@0 99 _clet((InterpreterCodelet*)AbstractInterpreter::code()->request(codelet_size())),
duke@0 100 _cb(_clet->code_begin(), _clet->code_size())
duke@0 101
duke@0 102 { // request all space (add some slack for Codelet data)
duke@0 103 assert (_clet != NULL, "we checked not enough space already");
duke@0 104
duke@0 105 // initialize Codelet attributes
duke@0 106 _clet->initialize(description, bytecode);
duke@0 107 // create assembler for code generation
duke@0 108 masm = new InterpreterMacroAssembler(&_cb);
duke@0 109 _masm = &masm;
duke@0 110 }
duke@0 111
duke@0 112 ~CodeletMark() {
duke@0 113 // align so printing shows nop's instead of random code at the end (Codelets are aligned)
duke@0 114 (*_masm)->align(wordSize);
duke@0 115 // make sure all code is in code buffer
duke@0 116 (*_masm)->flush();
duke@0 117
duke@0 118
duke@0 119 // commit Codelet
duke@0 120 AbstractInterpreter::code()->commit((*_masm)->code()->pure_code_size());
duke@0 121 // make sure nobody can use _masm outside a CodeletMark lifespan
duke@0 122 *_masm = NULL;
duke@0 123 }
duke@0 124 };
duke@0 125
duke@0 126 // Wrapper classes to produce Interpreter/InterpreterGenerator from either
duke@0 127 // the c++ interpreter or the template interpreter.
duke@0 128
duke@0 129 class Interpreter: public CC_INTERP_ONLY(CppInterpreter) NOT_CC_INTERP(TemplateInterpreter) {
duke@0 130
duke@0 131 public:
duke@0 132 // Debugging/printing
duke@0 133 static InterpreterCodelet* codelet_containing(address pc) { return (InterpreterCodelet*)_code->stub_containing(pc); }
duke@0 134 #include "incls/_interpreter_pd.hpp.incl"
duke@0 135 };