hotspot/src/share/vm/runtime/stubCodeGenerator.hpp
author mgerdin
Thu, 23 Feb 2012 14:58:35 +0100
changeset 12095 cc3d6f08a4c4
parent 9980 a330de5dea17
child 13195 be27e1b6a4b9
permissions -rw-r--r--
7148152: Add whitebox testing API to HotSpot Summary: Add an internal testing API to HotSpot to enable more targeted testing of vm functionality Reviewed-by: phh, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
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: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
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: 1
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
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    25
#ifndef SHARE_VM_RUNTIME_STUBCODEGENERATOR_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    26
#define SHARE_VM_RUNTIME_STUBCODEGENERATOR_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    28
#include "asm/assembler.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    29
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    30
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// All the basic framework for stubcode generation/debugging/printing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// A StubCodeDesc describes a piece of generated code (usually stubs).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// This information is mainly useful for debugging and printing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// Currently, code descriptors are simply chained in a linked list,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// this may have to change if searching becomes too slow.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
class StubCodeDesc: public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  static StubCodeDesc* _list;                  // the list of all descriptors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  static int           _count;                 // length of list
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  StubCodeDesc*        _next;                  // the next element in the linked list
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  const char*          _group;                 // the group to which the stub code belongs
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  const char*          _name;                  // the name assigned to the stub code
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  int                  _index;                 // serial number assigned to the stub
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  address              _begin;                 // points to the first byte of the stub code    (included)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  address              _end;                   // points to the first byte after the stub code (excluded)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  void set_end(address end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    assert(_begin <= end, "begin & end not properly ordered");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    _end = end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  void set_begin(address begin) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    assert(begin >= _begin, "begin may not decrease");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    assert(_end == NULL || begin <= _end, "begin & end not properly ordered");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    _begin = begin;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  friend class StubCodeMark;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  friend class StubCodeGenerator;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  static StubCodeDesc* desc_for(address pc);     // returns the code descriptor for the code containing pc or NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  static StubCodeDesc* desc_for_index(int);      // returns the code descriptor for the index or NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  static const char*   name_for(address pc);     // returns the name of the code containing pc or NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  StubCodeDesc(const char* group, const char* name, address begin) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    assert(name != NULL, "no name specified");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    _next           = _list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    _group          = group;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    _name           = name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    _index          = ++_count; // (never zero)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    _begin          = begin;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    _end            = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    _list           = this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  const char* group() const                      { return _group; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  const char* name() const                       { return _name; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  int         index() const                      { return _index; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  address     begin() const                      { return _begin; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  address     end() const                        { return _end; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  int         size_in_bytes() const              { return _end - _begin; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  bool        contains(address pc) const         { return _begin <= pc && pc < _end; }
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
    88
  void        print_on(outputStream* st) const;
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
    89
  void        print() const                      { print_on(tty); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
// The base class for all stub-generating code generators.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
// Provides utility functions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
class StubCodeGenerator: public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  MacroAssembler*  _masm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  StubCodeDesc* _first_stub;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  StubCodeDesc* _last_stub;
9980
a330de5dea17 7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents: 7397
diff changeset
   101
  bool _print_code;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
 public:
9980
a330de5dea17 7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents: 7397
diff changeset
   104
  StubCodeGenerator(CodeBuffer* code, bool print_code = false);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  ~StubCodeGenerator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  MacroAssembler* assembler() const              { return _masm; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  virtual void stub_prolog(StubCodeDesc* cdesc); // called by StubCodeMark constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  virtual void stub_epilog(StubCodeDesc* cdesc); // called by StubCodeMark destructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
// Stack-allocated helper class used to assciate a stub code with a name.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
// All stub code generating functions that use a StubCodeMark will be registered
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
// in the global StubCodeDesc list and the generated stub code can be identified
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
// later via an address pointing into it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
class StubCodeMark: public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  StubCodeGenerator* _cgen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  StubCodeDesc*      _cdesc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  StubCodeMark(StubCodeGenerator* cgen, const char* group, const char* name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  ~StubCodeMark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
   129
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
   130
#endif // SHARE_VM_RUNTIME_STUBCODEGENERATOR_HPP