author | rprotacio |
Wed, 02 Mar 2016 15:10:38 -0500 | |
changeset 36396 | 26a241a959de |
parent 36074 | 11263906664c |
child 36301 | cb578d8c6cba |
permissions | -rw-r--r-- |
1 | 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 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
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 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 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" |
31620
53be635ad49c
8087333: Optionally Pre-Generate the HotSpot Template Interpreter
bdelsart
parents:
31343
diff
changeset
|
29 |
#include "code/codeCacheExtensions.hpp" |
7397 | 30 |
#include "compiler/disassembler.hpp" |
31 |
#include "oops/oop.inline.hpp" |
|
32 |
#include "prims/forte.hpp" |
|
33 |
#include "runtime/stubCodeGenerator.hpp" |
|
1 | 34 |
|
35 |
||
36 |
// Implementation of StubCodeDesc |
|
37 |
||
38 |
StubCodeDesc* StubCodeDesc::_list = NULL; |
|
39 |
int StubCodeDesc::_count = 0; |
|
36074
11263906664c
8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents:
31620
diff
changeset
|
40 |
bool StubCodeDesc::_frozen = false; |
1 | 41 |
|
42 |
StubCodeDesc* StubCodeDesc::desc_for(address pc) { |
|
43 |
StubCodeDesc* p = _list; |
|
44 |
while (p != NULL && !p->contains(pc)) p = p->_next; |
|
45 |
// p == NULL || p->contains(pc) |
|
46 |
return p; |
|
47 |
} |
|
48 |
||
49 |
StubCodeDesc* StubCodeDesc::desc_for_index(int index) { |
|
50 |
StubCodeDesc* p = _list; |
|
51 |
while (p != NULL && p->index() != index) p = p->_next; |
|
52 |
return p; |
|
53 |
} |
|
54 |
||
55 |
const char* StubCodeDesc::name_for(address pc) { |
|
56 |
StubCodeDesc* p = desc_for(pc); |
|
57 |
return p == NULL ? NULL : p->name(); |
|
58 |
} |
|
59 |
||
60 |
||
36074
11263906664c
8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents:
31620
diff
changeset
|
61 |
void StubCodeDesc::freeze() { |
11263906664c
8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents:
31620
diff
changeset
|
62 |
assert(!_frozen, "repeated freeze operation"); |
11263906664c
8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents:
31620
diff
changeset
|
63 |
_frozen = true; |
11263906664c
8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents:
31620
diff
changeset
|
64 |
} |
11263906664c
8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents:
31620
diff
changeset
|
65 |
|
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5924
diff
changeset
|
66 |
void StubCodeDesc::print_on(outputStream* st) const { |
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
22234
diff
changeset
|
67 |
st->print("%s", group()); |
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5924
diff
changeset
|
68 |
st->print("::"); |
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
22234
diff
changeset
|
69 |
st->print("%s", name()); |
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
22234
diff
changeset
|
70 |
st->print(" [" INTPTR_FORMAT ", " INTPTR_FORMAT "[ (%d bytes)", p2i(begin()), p2i(end()), size_in_bytes()); |
1 | 71 |
} |
72 |
||
73 |
// Implementation of StubCodeGenerator |
|
74 |
||
9980
a330de5dea17
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
8921
diff
changeset
|
75 |
StubCodeGenerator::StubCodeGenerator(CodeBuffer* code, bool print_code) { |
1 | 76 |
_masm = new MacroAssembler(code); |
77 |
_first_stub = _last_stub = NULL; |
|
9980
a330de5dea17
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
8921
diff
changeset
|
78 |
_print_code = print_code; |
1 | 79 |
} |
80 |
||
81 |
extern "C" { |
|
82 |
static int compare_cdesc(const void* void_a, const void* void_b) { |
|
83 |
int ai = (*((StubCodeDesc**) void_a))->index(); |
|
84 |
int bi = (*((StubCodeDesc**) void_b))->index(); |
|
85 |
return ai - bi; |
|
86 |
} |
|
87 |
} |
|
88 |
||
89 |
StubCodeGenerator::~StubCodeGenerator() { |
|
9980
a330de5dea17
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
8921
diff
changeset
|
90 |
if (PrintStubCode || _print_code) { |
1 | 91 |
CodeBuffer* cbuf = _masm->code(); |
92 |
CodeBlob* blob = CodeCache::find_blob_unsafe(cbuf->insts()->start()); |
|
93 |
if (blob != NULL) { |
|
16368
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14626
diff
changeset
|
94 |
blob->set_strings(cbuf->strings()); |
1 | 95 |
} |
96 |
bool saw_first = false; |
|
97 |
StubCodeDesc* toprint[1000]; |
|
98 |
int toprint_len = 0; |
|
99 |
for (StubCodeDesc* cdesc = _last_stub; cdesc != NULL; cdesc = cdesc->_next) { |
|
100 |
toprint[toprint_len++] = cdesc; |
|
101 |
if (cdesc == _first_stub) { saw_first = true; break; } |
|
102 |
} |
|
31343
63ace334eb46
8086073: Fix PrintStubCode for empty StubCodeGenerator.
goetz
parents:
24424
diff
changeset
|
103 |
assert(toprint_len == 0 || saw_first, "must get both first & last"); |
1 | 104 |
// Print in reverse order: |
105 |
qsort(toprint, toprint_len, sizeof(toprint[0]), compare_cdesc); |
|
106 |
for (int i = 0; i < toprint_len; i++) { |
|
107 |
StubCodeDesc* cdesc = toprint[i]; |
|
108 |
cdesc->print(); |
|
109 |
tty->cr(); |
|
110 |
Disassembler::decode(cdesc->begin(), cdesc->end()); |
|
111 |
tty->cr(); |
|
112 |
} |
|
113 |
} |
|
114 |
} |
|
115 |
||
116 |
void StubCodeGenerator::stub_prolog(StubCodeDesc* cdesc) { |
|
117 |
// default implementation - do nothing |
|
118 |
} |
|
119 |
||
120 |
void StubCodeGenerator::stub_epilog(StubCodeDesc* cdesc) { |
|
121 |
// default implementation - record the cdesc |
|
122 |
if (_first_stub == NULL) _first_stub = cdesc; |
|
123 |
_last_stub = cdesc; |
|
124 |
} |
|
125 |
||
126 |
||
127 |
// Implementation of CodeMark |
|
128 |
||
129 |
StubCodeMark::StubCodeMark(StubCodeGenerator* cgen, const char* group, const char* name) { |
|
130 |
_cgen = cgen; |
|
131 |
_cdesc = new StubCodeDesc(group, name, _cgen->assembler()->pc()); |
|
132 |
_cgen->stub_prolog(_cdesc); |
|
133 |
// define the stub's beginning (= entry point) to be after the prolog: |
|
134 |
_cdesc->set_begin(_cgen->assembler()->pc()); |
|
135 |
} |
|
136 |
||
137 |
StubCodeMark::~StubCodeMark() { |
|
138 |
_cgen->assembler()->flush(); |
|
139 |
_cdesc->set_end(_cgen->assembler()->pc()); |
|
140 |
assert(StubCodeDesc::_list == _cdesc, "expected order on list"); |
|
141 |
_cgen->stub_epilog(_cdesc); |
|
142 |
Forte::register_stub(_cdesc->name(), _cdesc->begin(), _cdesc->end()); |
|
143 |
||
144 |
if (JvmtiExport::should_post_dynamic_code_generated()) { |
|
145 |
JvmtiExport::post_dynamic_code_generated(_cdesc->name(), _cdesc->begin(), _cdesc->end()); |
|
146 |
} |
|
147 |
} |