src/hotspot/share/runtime/stubCodeGenerator.cpp
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 42664 hotspot/src/share/vm/runtime/stubCodeGenerator.cpp@29142a56c193
child 50528 1fd4844371bb
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
31620
53be635ad49c 8087333: Optionally Pre-Generate the HotSpot Template Interpreter
bdelsart
parents: 31343
diff changeset
     2
 * Copyright (c) 1997, 2015, 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"
14626
0cf4eccf130f 8003240: x86: move MacroAssembler into separate file
twisti
parents: 9980
diff changeset
    26
#include "asm/macroAssembler.hpp"
0cf4eccf130f 8003240: x86: move MacroAssembler into separate file
twisti
parents: 9980
diff changeset
    27
#include "asm/macroAssembler.inline.hpp"
0cf4eccf130f 8003240: x86: move MacroAssembler into separate file
twisti
parents: 9980
diff changeset
    28
#include "code/codeCache.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    29
#include "compiler/disassembler.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    30
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    31
#include "prims/forte.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    32
#include "runtime/stubCodeGenerator.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// Implementation of StubCodeDesc
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
StubCodeDesc* StubCodeDesc::_list = NULL;
36074
11263906664c 8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents: 31620
diff changeset
    38
bool          StubCodeDesc::_frozen = false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
StubCodeDesc* StubCodeDesc::desc_for(address pc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  StubCodeDesc* p = _list;
36301
cb578d8c6cba 8149741: Don't refer to stub entry points by index in external_word relocations
vlivanov
parents: 36074
diff changeset
    42
  while (p != NULL && !p->contains(pc)) {
cb578d8c6cba 8149741: Don't refer to stub entry points by index in external_word relocations
vlivanov
parents: 36074
diff changeset
    43
    p = p->_next;
cb578d8c6cba 8149741: Don't refer to stub entry points by index in external_word relocations
vlivanov
parents: 36074
diff changeset
    44
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  return p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
const char* StubCodeDesc::name_for(address pc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  StubCodeDesc* p = desc_for(pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  return p == NULL ? NULL : p->name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
36074
11263906664c 8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents: 31620
diff changeset
    54
void StubCodeDesc::freeze() {
11263906664c 8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents: 31620
diff changeset
    55
  assert(!_frozen, "repeated freeze operation");
11263906664c 8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents: 31620
diff changeset
    56
  _frozen = true;
11263906664c 8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents: 31620
diff changeset
    57
}
11263906664c 8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents: 31620
diff changeset
    58
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5924
diff changeset
    59
void StubCodeDesc::print_on(outputStream* st) const {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22234
diff changeset
    60
  st->print("%s", group());
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5924
diff changeset
    61
  st->print("::");
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22234
diff changeset
    62
  st->print("%s", name());
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22234
diff changeset
    63
  st->print(" [" INTPTR_FORMAT ", " INTPTR_FORMAT "[ (%d bytes)", p2i(begin()), p2i(end()), size_in_bytes());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
// Implementation of StubCodeGenerator
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
9980
a330de5dea17 7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents: 8921
diff changeset
    68
StubCodeGenerator::StubCodeGenerator(CodeBuffer* code, bool print_code) {
36301
cb578d8c6cba 8149741: Don't refer to stub entry points by index in external_word relocations
vlivanov
parents: 36074
diff changeset
    69
  _masm = new MacroAssembler(code );
cb578d8c6cba 8149741: Don't refer to stub entry points by index in external_word relocations
vlivanov
parents: 36074
diff changeset
    70
  _print_code = PrintStubCode || print_code;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
StubCodeGenerator::~StubCodeGenerator() {
36301
cb578d8c6cba 8149741: Don't refer to stub entry points by index in external_word relocations
vlivanov
parents: 36074
diff changeset
    74
  if (_print_code) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    CodeBuffer* cbuf = _masm->code();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    CodeBlob*   blob = CodeCache::find_blob_unsafe(cbuf->insts()->start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    if (blob != NULL) {
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14626
diff changeset
    78
      blob->set_strings(cbuf->strings());
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
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
void StubCodeGenerator::stub_prolog(StubCodeDesc* cdesc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  // default implementation - do nothing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
void StubCodeGenerator::stub_epilog(StubCodeDesc* cdesc) {
36301
cb578d8c6cba 8149741: Don't refer to stub entry points by index in external_word relocations
vlivanov
parents: 36074
diff changeset
    88
  if (_print_code) {
cb578d8c6cba 8149741: Don't refer to stub entry points by index in external_word relocations
vlivanov
parents: 36074
diff changeset
    89
    cdesc->print();
cb578d8c6cba 8149741: Don't refer to stub entry points by index in external_word relocations
vlivanov
parents: 36074
diff changeset
    90
    tty->cr();
cb578d8c6cba 8149741: Don't refer to stub entry points by index in external_word relocations
vlivanov
parents: 36074
diff changeset
    91
    Disassembler::decode(cdesc->begin(), cdesc->end());
cb578d8c6cba 8149741: Don't refer to stub entry points by index in external_word relocations
vlivanov
parents: 36074
diff changeset
    92
    tty->cr();
cb578d8c6cba 8149741: Don't refer to stub entry points by index in external_word relocations
vlivanov
parents: 36074
diff changeset
    93
  }
1
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
// Implementation of CodeMark
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
StubCodeMark::StubCodeMark(StubCodeGenerator* cgen, const char* group, const char* name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  _cgen  = cgen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  _cdesc = new StubCodeDesc(group, name, _cgen->assembler()->pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  _cgen->stub_prolog(_cdesc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  // define the stub's beginning (= entry point) to be after the prolog:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  _cdesc->set_begin(_cgen->assembler()->pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
StubCodeMark::~StubCodeMark() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  _cgen->assembler()->flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  _cdesc->set_end(_cgen->assembler()->pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  assert(StubCodeDesc::_list == _cdesc, "expected order on list");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  _cgen->stub_epilog(_cdesc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  Forte::register_stub(_cdesc->name(), _cdesc->begin(), _cdesc->end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  if (JvmtiExport::should_post_dynamic_code_generated()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    JvmtiExport::post_dynamic_code_generated(_cdesc->name(), _cdesc->begin(), _cdesc->end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
}