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