annotate src/share/vm/runtime/stubCodeGenerator.cpp @ 2192:b92c45f2bc75

7016023: Enable building ARM and PPC from src/closed repository Reviewed-by: dholmes, bdelsart
author bobv
date Wed, 02 Feb 2011 11:35:26 -0500
parents f95d63e2154a
children 1d1603768966
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1644
2a47bd84841f 6965184: possible races in make_not_entrant_or_zombie
never
parents: 1552
diff changeset
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 196
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 196
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 196
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1681
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1681
diff changeset
26 #include "compiler/disassembler.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1681
diff changeset
27 #include "oops/oop.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1681
diff changeset
28 #include "prims/forte.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1681
diff changeset
29 #include "runtime/stubCodeGenerator.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1681
diff changeset
30 #ifdef TARGET_ARCH_x86
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1681
diff changeset
31 # include "assembler_x86.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1681
diff changeset
32 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1681
diff changeset
33 #ifdef TARGET_ARCH_sparc
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1681
diff changeset
34 # include "assembler_sparc.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1681
diff changeset
35 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1681
diff changeset
36 #ifdef TARGET_ARCH_zero
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1681
diff changeset
37 # include "assembler_zero.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1681
diff changeset
38 #endif
2192
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 1972
diff changeset
39 #ifdef TARGET_ARCH_arm
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 1972
diff changeset
40 # include "assembler_arm.inline.hpp"
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 1972
diff changeset
41 #endif
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 1972
diff changeset
42 #ifdef TARGET_ARCH_ppc
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 1972
diff changeset
43 # include "assembler_ppc.inline.hpp"
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 1972
diff changeset
44 #endif
0
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // Implementation of StubCodeDesc
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 StubCodeDesc* StubCodeDesc::_list = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 int StubCodeDesc::_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 StubCodeDesc* StubCodeDesc::desc_for(address pc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 StubCodeDesc* p = _list;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 while (p != NULL && !p->contains(pc)) p = p->_next;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // p == NULL || p->contains(pc)
a61af66fc99e Initial load
duke
parents:
diff changeset
57 return p;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 }
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 StubCodeDesc* StubCodeDesc::desc_for_index(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 StubCodeDesc* p = _list;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 while (p != NULL && p->index() != index) p = p->_next;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 return p;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 const char* StubCodeDesc::name_for(address pc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 StubCodeDesc* p = desc_for(pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
70 return p == NULL ? NULL : p->name();
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73
1681
126ea7725993 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 1644
diff changeset
74 void StubCodeDesc::print_on(outputStream* st) const {
126ea7725993 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 1644
diff changeset
75 st->print(group());
126ea7725993 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 1644
diff changeset
76 st->print("::");
126ea7725993 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 1644
diff changeset
77 st->print(name());
126ea7725993 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 1644
diff changeset
78 st->print(" [" INTPTR_FORMAT ", " INTPTR_FORMAT "[ (%d bytes)", begin(), end(), size_in_bytes());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // Implementation of StubCodeGenerator
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 StubCodeGenerator::StubCodeGenerator(CodeBuffer* code) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 _masm = new MacroAssembler(code);
a61af66fc99e Initial load
duke
parents:
diff changeset
85 _first_stub = _last_stub = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 extern "C" {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 static int compare_cdesc(const void* void_a, const void* void_b) {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 int ai = (*((StubCodeDesc**) void_a))->index();
a61af66fc99e Initial load
duke
parents:
diff changeset
91 int bi = (*((StubCodeDesc**) void_b))->index();
a61af66fc99e Initial load
duke
parents:
diff changeset
92 return ai - bi;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 StubCodeGenerator::~StubCodeGenerator() {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 if (PrintStubCode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 CodeBuffer* cbuf = _masm->code();
a61af66fc99e Initial load
duke
parents:
diff changeset
99 CodeBlob* blob = CodeCache::find_blob_unsafe(cbuf->insts()->start());
a61af66fc99e Initial load
duke
parents:
diff changeset
100 if (blob != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 blob->set_comments(cbuf->comments());
a61af66fc99e Initial load
duke
parents:
diff changeset
102 }
a61af66fc99e Initial load
duke
parents:
diff changeset
103 bool saw_first = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 StubCodeDesc* toprint[1000];
a61af66fc99e Initial load
duke
parents:
diff changeset
105 int toprint_len = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 for (StubCodeDesc* cdesc = _last_stub; cdesc != NULL; cdesc = cdesc->_next) {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 toprint[toprint_len++] = cdesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 if (cdesc == _first_stub) { saw_first = true; break; }
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 assert(saw_first, "must get both first & last");
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // Print in reverse order:
a61af66fc99e Initial load
duke
parents:
diff changeset
112 qsort(toprint, toprint_len, sizeof(toprint[0]), compare_cdesc);
a61af66fc99e Initial load
duke
parents:
diff changeset
113 for (int i = 0; i < toprint_len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 StubCodeDesc* cdesc = toprint[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
115 cdesc->print();
a61af66fc99e Initial load
duke
parents:
diff changeset
116 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
117 Disassembler::decode(cdesc->begin(), cdesc->end());
a61af66fc99e Initial load
duke
parents:
diff changeset
118 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 void StubCodeGenerator::stub_prolog(StubCodeDesc* cdesc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // default implementation - do nothing
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 void StubCodeGenerator::stub_epilog(StubCodeDesc* cdesc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 // default implementation - record the cdesc
a61af66fc99e Initial load
duke
parents:
diff changeset
131 if (_first_stub == NULL) _first_stub = cdesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 _last_stub = cdesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // Implementation of CodeMark
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 StubCodeMark::StubCodeMark(StubCodeGenerator* cgen, const char* group, const char* name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 _cgen = cgen;
a61af66fc99e Initial load
duke
parents:
diff changeset
140 _cdesc = new StubCodeDesc(group, name, _cgen->assembler()->pc());
a61af66fc99e Initial load
duke
parents:
diff changeset
141 _cgen->stub_prolog(_cdesc);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 // define the stub's beginning (= entry point) to be after the prolog:
a61af66fc99e Initial load
duke
parents:
diff changeset
143 _cdesc->set_begin(_cgen->assembler()->pc());
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 StubCodeMark::~StubCodeMark() {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 _cgen->assembler()->flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
148 _cdesc->set_end(_cgen->assembler()->pc());
a61af66fc99e Initial load
duke
parents:
diff changeset
149 assert(StubCodeDesc::_list == _cdesc, "expected order on list");
a61af66fc99e Initial load
duke
parents:
diff changeset
150 _cgen->stub_epilog(_cdesc);
a61af66fc99e Initial load
duke
parents:
diff changeset
151 Forte::register_stub(_cdesc->name(), _cdesc->begin(), _cdesc->end());
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153 if (JvmtiExport::should_post_dynamic_code_generated()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 JvmtiExport::post_dynamic_code_generated(_cdesc->name(), _cdesc->begin(), _cdesc->end());
a61af66fc99e Initial load
duke
parents:
diff changeset
155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }