hotspot/src/share/vm/runtime/stubCodeGenerator.cpp
author mgerdin
Thu, 23 Feb 2012 14:58:35 +0100
changeset 12095 cc3d6f08a4c4
parent 9980 a330de5dea17
child 14626 0cf4eccf130f
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
/*
8921
14bfe81f2a9d 7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents: 8107
diff changeset
     2
 * Copyright (c) 1997, 2011, 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: 670
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 670
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: 670
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
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    26
#include "compiler/disassembler.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    27
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    28
#include "prims/forte.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    29
#include "runtime/stubCodeGenerator.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    30
#ifdef TARGET_ARCH_x86
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    31
# include "assembler_x86.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    32
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    33
#ifdef TARGET_ARCH_sparc
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    34
# include "assembler_sparc.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    35
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    36
#ifdef TARGET_ARCH_zero
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    37
# include "assembler_zero.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    38
#endif
8107
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 7397
diff changeset
    39
#ifdef TARGET_ARCH_arm
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 7397
diff changeset
    40
# include "assembler_arm.inline.hpp"
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 7397
diff changeset
    41
#endif
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 7397
diff changeset
    42
#ifdef TARGET_ARCH_ppc
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 7397
diff changeset
    43
# include "assembler_ppc.inline.hpp"
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 7397
diff changeset
    44
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
// Implementation of StubCodeDesc
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
StubCodeDesc* StubCodeDesc::_list = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
int           StubCodeDesc::_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
StubCodeDesc* StubCodeDesc::desc_for(address pc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  StubCodeDesc* p = _list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  while (p != NULL && !p->contains(pc)) p = p->_next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  // p == NULL || p->contains(pc)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  return p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
StubCodeDesc* StubCodeDesc::desc_for_index(int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  StubCodeDesc* p = _list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  while (p != NULL && p->index() != index) p = p->_next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  return p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
const char* StubCodeDesc::name_for(address pc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  StubCodeDesc* p = desc_for(pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  return p == NULL ? NULL : p->name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5924
diff changeset
    74
void StubCodeDesc::print_on(outputStream* st) const {
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5924
diff changeset
    75
  st->print(group());
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5924
diff changeset
    76
  st->print("::");
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5924
diff changeset
    77
  st->print(name());
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5924
diff changeset
    78
  st->print(" [" INTPTR_FORMAT ", " INTPTR_FORMAT "[ (%d bytes)", begin(), end(), size_in_bytes());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
// Implementation of StubCodeGenerator
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
9980
a330de5dea17 7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents: 8921
diff changeset
    83
StubCodeGenerator::StubCodeGenerator(CodeBuffer* code, bool print_code) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  _masm = new MacroAssembler(code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  _first_stub = _last_stub = NULL;
9980
a330de5dea17 7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents: 8921
diff changeset
    86
  _print_code = print_code;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
extern "C" {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  static int compare_cdesc(const void* void_a, const void* void_b) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    int ai = (*((StubCodeDesc**) void_a))->index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    int bi = (*((StubCodeDesc**) void_b))->index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    return ai - bi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
StubCodeGenerator::~StubCodeGenerator() {
9980
a330de5dea17 7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents: 8921
diff changeset
    98
  if (PrintStubCode || _print_code) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    CodeBuffer* cbuf = _masm->code();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    CodeBlob*   blob = CodeCache::find_blob_unsafe(cbuf->insts()->start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    if (blob != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
      blob->set_comments(cbuf->comments());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    bool saw_first = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    StubCodeDesc* toprint[1000];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    int toprint_len = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    for (StubCodeDesc* cdesc = _last_stub; cdesc != NULL; cdesc = cdesc->_next) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      toprint[toprint_len++] = cdesc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
      if (cdesc == _first_stub) { saw_first = true; break; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    assert(saw_first, "must get both first & last");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    // Print in reverse order:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    qsort(toprint, toprint_len, sizeof(toprint[0]), compare_cdesc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    for (int i = 0; i < toprint_len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
      StubCodeDesc* cdesc = toprint[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      cdesc->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      Disassembler::decode(cdesc->begin(), cdesc->end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
      tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
void StubCodeGenerator::stub_prolog(StubCodeDesc* cdesc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  // default implementation - do nothing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
void StubCodeGenerator::stub_epilog(StubCodeDesc* cdesc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  // default implementation - record the cdesc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  if (_first_stub == NULL)  _first_stub = cdesc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  _last_stub = cdesc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
// Implementation of CodeMark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
StubCodeMark::StubCodeMark(StubCodeGenerator* cgen, const char* group, const char* name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  _cgen  = cgen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  _cdesc = new StubCodeDesc(group, name, _cgen->assembler()->pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  _cgen->stub_prolog(_cdesc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  // define the stub's beginning (= entry point) to be after the prolog:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  _cdesc->set_begin(_cgen->assembler()->pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
StubCodeMark::~StubCodeMark() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  _cgen->assembler()->flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  _cdesc->set_end(_cgen->assembler()->pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  assert(StubCodeDesc::_list == _cdesc, "expected order on list");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  _cgen->stub_epilog(_cdesc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  Forte::register_stub(_cdesc->name(), _cdesc->begin(), _cdesc->end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  if (JvmtiExport::should_post_dynamic_code_generated()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    JvmtiExport::post_dynamic_code_generated(_cdesc->name(), _cdesc->begin(), _cdesc->end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
}