|
1 /* |
|
2 * Copyright 1997-2004 Sun Microsystems, Inc. All Rights Reserved. |
|
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 * |
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 * have any questions. |
|
22 * |
|
23 */ |
|
24 |
|
25 #include "incls/_precompiled.incl" |
|
26 #include "incls/_stubCodeGenerator.cpp.incl" |
|
27 |
|
28 |
|
29 // Implementation of StubCodeDesc |
|
30 |
|
31 StubCodeDesc* StubCodeDesc::_list = NULL; |
|
32 int StubCodeDesc::_count = 0; |
|
33 |
|
34 |
|
35 StubCodeDesc* StubCodeDesc::desc_for(address pc) { |
|
36 StubCodeDesc* p = _list; |
|
37 while (p != NULL && !p->contains(pc)) p = p->_next; |
|
38 // p == NULL || p->contains(pc) |
|
39 return p; |
|
40 } |
|
41 |
|
42 |
|
43 StubCodeDesc* StubCodeDesc::desc_for_index(int index) { |
|
44 StubCodeDesc* p = _list; |
|
45 while (p != NULL && p->index() != index) p = p->_next; |
|
46 return p; |
|
47 } |
|
48 |
|
49 |
|
50 const char* StubCodeDesc::name_for(address pc) { |
|
51 StubCodeDesc* p = desc_for(pc); |
|
52 return p == NULL ? NULL : p->name(); |
|
53 } |
|
54 |
|
55 |
|
56 void StubCodeDesc::print() { |
|
57 tty->print(group()); |
|
58 tty->print("::"); |
|
59 tty->print(name()); |
|
60 tty->print(" [" INTPTR_FORMAT ", " INTPTR_FORMAT "[ (%d bytes)", begin(), end(), size_in_bytes()); |
|
61 } |
|
62 |
|
63 |
|
64 |
|
65 // Implementation of StubCodeGenerator |
|
66 |
|
67 StubCodeGenerator::StubCodeGenerator(CodeBuffer* code) { |
|
68 _masm = new MacroAssembler(code); |
|
69 _first_stub = _last_stub = NULL; |
|
70 } |
|
71 |
|
72 #ifndef PRODUCT |
|
73 extern "C" { |
|
74 static int compare_cdesc(const void* void_a, const void* void_b) { |
|
75 int ai = (*((StubCodeDesc**) void_a))->index(); |
|
76 int bi = (*((StubCodeDesc**) void_b))->index(); |
|
77 return ai - bi; |
|
78 } |
|
79 } |
|
80 #endif |
|
81 |
|
82 StubCodeGenerator::~StubCodeGenerator() { |
|
83 #ifndef PRODUCT |
|
84 if (PrintStubCode) { |
|
85 CodeBuffer* cbuf = _masm->code(); |
|
86 CodeBlob* blob = CodeCache::find_blob_unsafe(cbuf->insts()->start()); |
|
87 if (blob != NULL) { |
|
88 blob->set_comments(cbuf->comments()); |
|
89 } |
|
90 bool saw_first = false; |
|
91 StubCodeDesc* toprint[1000]; |
|
92 int toprint_len = 0; |
|
93 for (StubCodeDesc* cdesc = _last_stub; cdesc != NULL; cdesc = cdesc->_next) { |
|
94 toprint[toprint_len++] = cdesc; |
|
95 if (cdesc == _first_stub) { saw_first = true; break; } |
|
96 } |
|
97 assert(saw_first, "must get both first & last"); |
|
98 // Print in reverse order: |
|
99 qsort(toprint, toprint_len, sizeof(toprint[0]), compare_cdesc); |
|
100 for (int i = 0; i < toprint_len; i++) { |
|
101 StubCodeDesc* cdesc = toprint[i]; |
|
102 cdesc->print(); |
|
103 tty->cr(); |
|
104 Disassembler::decode(cdesc->begin(), cdesc->end()); |
|
105 tty->cr(); |
|
106 } |
|
107 } |
|
108 #endif //PRODUCT |
|
109 } |
|
110 |
|
111 |
|
112 void StubCodeGenerator::stub_prolog(StubCodeDesc* cdesc) { |
|
113 // default implementation - do nothing |
|
114 } |
|
115 |
|
116 |
|
117 void StubCodeGenerator::stub_epilog(StubCodeDesc* cdesc) { |
|
118 // default implementation - record the cdesc |
|
119 if (_first_stub == NULL) _first_stub = cdesc; |
|
120 _last_stub = cdesc; |
|
121 } |
|
122 |
|
123 |
|
124 // Implementation of CodeMark |
|
125 |
|
126 StubCodeMark::StubCodeMark(StubCodeGenerator* cgen, const char* group, const char* name) { |
|
127 _cgen = cgen; |
|
128 _cdesc = new StubCodeDesc(group, name, _cgen->assembler()->pc()); |
|
129 _cgen->stub_prolog(_cdesc); |
|
130 // define the stub's beginning (= entry point) to be after the prolog: |
|
131 _cdesc->set_begin(_cgen->assembler()->pc()); |
|
132 } |
|
133 |
|
134 StubCodeMark::~StubCodeMark() { |
|
135 _cgen->assembler()->flush(); |
|
136 _cdesc->set_end(_cgen->assembler()->pc()); |
|
137 assert(StubCodeDesc::_list == _cdesc, "expected order on list"); |
|
138 _cgen->stub_epilog(_cdesc); |
|
139 VTune::register_stub(_cdesc->name(), _cdesc->begin(), _cdesc->end()); |
|
140 Forte::register_stub(_cdesc->name(), _cdesc->begin(), _cdesc->end()); |
|
141 |
|
142 if (JvmtiExport::should_post_dynamic_code_generated()) { |
|
143 JvmtiExport::post_dynamic_code_generated(_cdesc->name(), _cdesc->begin(), _cdesc->end()); |
|
144 } |
|
145 } |