Mercurial > hg > truffle
annotate src/cpu/zero/vm/stubGenerator_zero.cpp @ 13563:fb846424299f
Truffle/Ruby: extend Instrumentation framework with language-agnostic interfaces for access to AST printing utilities and a Ruby implementation
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Tue, 07 Jan 2014 18:09:42 -0800 |
parents | c54a3122f9c8 |
children | de6a9e811145 |
rev | line source |
---|---|
1010 | 1 /* |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3960
diff
changeset
|
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. |
1379 | 3 * Copyright 2007, 2008, 2010 Red Hat, Inc. |
1010 | 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5 * | |
6 * This code is free software; you can redistribute it and/or modify it | |
7 * under the terms of the GNU General Public License version 2 only, as | |
8 * published by the Free Software Foundation. | |
9 * | |
10 * This code is distributed in the hope that it will be useful, but WITHOUT | |
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 * version 2 for more details (a copy is included in the LICENSE file that | |
14 * accompanied this code). | |
15 * | |
16 * You should have received a copy of the GNU General Public License version | |
17 * 2 along with this work; if not, write to the Free Software Foundation, | |
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
19 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1511
diff
changeset
|
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1511
diff
changeset
|
21 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1511
diff
changeset
|
22 * questions. |
1010 | 23 * |
24 */ | |
25 | |
1972 | 26 #include "precompiled.hpp" |
27 #include "asm/assembler.hpp" | |
28 #include "assembler_zero.inline.hpp" | |
29 #include "interpreter/interpreter.hpp" | |
30 #include "nativeInst_zero.hpp" | |
31 #include "oops/instanceOop.hpp" | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3960
diff
changeset
|
32 #include "oops/method.hpp" |
1972 | 33 #include "oops/objArrayKlass.hpp" |
34 #include "oops/oop.inline.hpp" | |
35 #include "prims/methodHandles.hpp" | |
36 #include "runtime/frame.inline.hpp" | |
37 #include "runtime/handles.inline.hpp" | |
38 #include "runtime/sharedRuntime.hpp" | |
39 #include "runtime/stubCodeGenerator.hpp" | |
40 #include "runtime/stubRoutines.hpp" | |
7180
f34d701e952e
8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
6725
diff
changeset
|
41 #include "runtime/thread.inline.hpp" |
1972 | 42 #include "stack_zero.inline.hpp" |
43 #include "utilities/top.hpp" | |
44 #ifdef COMPILER2 | |
45 #include "opto/runtime.hpp" | |
46 #endif | |
1010 | 47 |
48 // Declaration and definition of StubGenerator (no .hpp file). | |
49 // For a more detailed description of the stub routine structure | |
50 // see the comment in stubRoutines.hpp | |
51 | |
52 class StubGenerator: public StubCodeGenerator { | |
53 private: | |
54 // The call stub is used to call Java from C | |
55 static void call_stub( | |
56 JavaCallWrapper *call_wrapper, | |
57 intptr_t* result, | |
58 BasicType result_type, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3960
diff
changeset
|
59 Method* method, |
1010 | 60 address entry_point, |
61 intptr_t* parameters, | |
62 int parameter_words, | |
63 TRAPS) { | |
64 JavaThread *thread = (JavaThread *) THREAD; | |
65 ZeroStack *stack = thread->zero_stack(); | |
66 | |
67 // Make sure we have no pending exceptions | |
68 assert(!HAS_PENDING_EXCEPTION, "call_stub called with pending exception"); | |
69 | |
70 // Set up the stack if necessary | |
71 bool stack_needs_teardown = false; | |
72 if (stack->needs_setup()) { | |
1511 | 73 size_t zero_stack_size = stack->suggest_size(thread); |
1010 | 74 stack->setup(alloca(zero_stack_size), zero_stack_size); |
75 stack_needs_teardown = true; | |
76 } | |
77 | |
78 // Allocate and initialize our frame | |
1379 | 79 EntryFrame *frame = |
80 EntryFrame::build(parameters, parameter_words, call_wrapper, THREAD); | |
1010 | 81 |
82 if (!HAS_PENDING_EXCEPTION) { | |
1379 | 83 // Push the frame |
84 thread->push_zero_frame(frame); | |
85 | |
86 // Make the call | |
87 Interpreter::invoke_method(method, entry_point, THREAD); | |
88 | |
89 // Store the result | |
90 if (!HAS_PENDING_EXCEPTION) { | |
91 switch (result_type) { | |
92 case T_INT: | |
93 *(jint *) result = *(jint *) stack->sp(); | |
94 break; | |
95 case T_LONG: | |
96 *(jlong *) result = *(jlong *) stack->sp(); | |
97 break; | |
98 case T_FLOAT: | |
99 *(jfloat *) result = *(jfloat *) stack->sp(); | |
100 break; | |
101 case T_DOUBLE: | |
102 *(jdouble *) result = *(jdouble *) stack->sp(); | |
103 break; | |
104 case T_OBJECT: | |
105 *(oop *) result = *(oop *) stack->sp(); | |
106 break; | |
107 default: | |
108 ShouldNotReachHere(); | |
109 } | |
1010 | 110 } |
1379 | 111 |
112 // Unwind the frame | |
113 thread->pop_zero_frame(); | |
1010 | 114 } |
115 | |
116 // Tear down the stack if necessary | |
117 if (stack_needs_teardown) | |
118 stack->teardown(); | |
119 } | |
120 | |
121 // These stubs get called from some dumb test routine. | |
122 // I'll write them properly when they're called from | |
123 // something that's actually doing something. | |
124 static void fake_arraycopy_stub(address src, address dst, int count) { | |
125 assert(count == 0, "huh?"); | |
126 } | |
127 | |
128 void generate_arraycopy_stubs() { | |
129 // Call the conjoint generation methods immediately after | |
130 // the disjoint ones so that short branches from the former | |
131 // to the latter can be generated. | |
132 StubRoutines::_jbyte_disjoint_arraycopy = (address) fake_arraycopy_stub; | |
133 StubRoutines::_jbyte_arraycopy = (address) fake_arraycopy_stub; | |
134 | |
135 StubRoutines::_jshort_disjoint_arraycopy = (address) fake_arraycopy_stub; | |
136 StubRoutines::_jshort_arraycopy = (address) fake_arraycopy_stub; | |
137 | |
138 StubRoutines::_jint_disjoint_arraycopy = (address) fake_arraycopy_stub; | |
139 StubRoutines::_jint_arraycopy = (address) fake_arraycopy_stub; | |
140 | |
141 StubRoutines::_jlong_disjoint_arraycopy = (address) fake_arraycopy_stub; | |
142 StubRoutines::_jlong_arraycopy = (address) fake_arraycopy_stub; | |
143 | |
144 StubRoutines::_oop_disjoint_arraycopy = ShouldNotCallThisStub(); | |
145 StubRoutines::_oop_arraycopy = ShouldNotCallThisStub(); | |
146 | |
147 StubRoutines::_checkcast_arraycopy = ShouldNotCallThisStub(); | |
148 StubRoutines::_unsafe_arraycopy = ShouldNotCallThisStub(); | |
149 StubRoutines::_generic_arraycopy = ShouldNotCallThisStub(); | |
150 | |
151 // We don't generate specialized code for HeapWord-aligned source | |
152 // arrays, so just use the code we've already generated | |
153 StubRoutines::_arrayof_jbyte_disjoint_arraycopy = | |
154 StubRoutines::_jbyte_disjoint_arraycopy; | |
155 StubRoutines::_arrayof_jbyte_arraycopy = | |
156 StubRoutines::_jbyte_arraycopy; | |
157 | |
158 StubRoutines::_arrayof_jshort_disjoint_arraycopy = | |
159 StubRoutines::_jshort_disjoint_arraycopy; | |
160 StubRoutines::_arrayof_jshort_arraycopy = | |
161 StubRoutines::_jshort_arraycopy; | |
162 | |
163 StubRoutines::_arrayof_jint_disjoint_arraycopy = | |
164 StubRoutines::_jint_disjoint_arraycopy; | |
165 StubRoutines::_arrayof_jint_arraycopy = | |
166 StubRoutines::_jint_arraycopy; | |
167 | |
168 StubRoutines::_arrayof_jlong_disjoint_arraycopy = | |
169 StubRoutines::_jlong_disjoint_arraycopy; | |
170 StubRoutines::_arrayof_jlong_arraycopy = | |
171 StubRoutines::_jlong_arraycopy; | |
172 | |
173 StubRoutines::_arrayof_oop_disjoint_arraycopy = | |
174 StubRoutines::_oop_disjoint_arraycopy; | |
175 StubRoutines::_arrayof_oop_arraycopy = | |
176 StubRoutines::_oop_arraycopy; | |
177 } | |
178 | |
12011
c54a3122f9c8
8022188: Make zero compile after 8016131 and 8016697
omajid
parents:
7180
diff
changeset
|
179 static int SafeFetch32(int *adr, int errValue) { |
c54a3122f9c8
8022188: Make zero compile after 8016131 and 8016697
omajid
parents:
7180
diff
changeset
|
180 int value = errValue; |
c54a3122f9c8
8022188: Make zero compile after 8016131 and 8016697
omajid
parents:
7180
diff
changeset
|
181 value = *adr; |
c54a3122f9c8
8022188: Make zero compile after 8016131 and 8016697
omajid
parents:
7180
diff
changeset
|
182 return value; |
c54a3122f9c8
8022188: Make zero compile after 8016131 and 8016697
omajid
parents:
7180
diff
changeset
|
183 } |
c54a3122f9c8
8022188: Make zero compile after 8016131 and 8016697
omajid
parents:
7180
diff
changeset
|
184 |
c54a3122f9c8
8022188: Make zero compile after 8016131 and 8016697
omajid
parents:
7180
diff
changeset
|
185 static intptr_t SafeFetchN(intptr_t *adr, intptr_t errValue) { |
c54a3122f9c8
8022188: Make zero compile after 8016131 and 8016697
omajid
parents:
7180
diff
changeset
|
186 intptr_t value = errValue; |
c54a3122f9c8
8022188: Make zero compile after 8016131 and 8016697
omajid
parents:
7180
diff
changeset
|
187 value = *adr; |
c54a3122f9c8
8022188: Make zero compile after 8016131 and 8016697
omajid
parents:
7180
diff
changeset
|
188 return value; |
c54a3122f9c8
8022188: Make zero compile after 8016131 and 8016697
omajid
parents:
7180
diff
changeset
|
189 } |
c54a3122f9c8
8022188: Make zero compile after 8016131 and 8016697
omajid
parents:
7180
diff
changeset
|
190 |
c54a3122f9c8
8022188: Make zero compile after 8016131 and 8016697
omajid
parents:
7180
diff
changeset
|
191 |
1010 | 192 void generate_initial() { |
193 // Generates all stubs and initializes the entry points | |
194 | |
195 // entry points that exist in all platforms Note: This is code | |
196 // that could be shared among different platforms - however the | |
197 // benefit seems to be smaller than the disadvantage of having a | |
198 // much more complicated generator structure. See also comment in | |
199 // stubRoutines.hpp. | |
200 | |
201 StubRoutines::_forward_exception_entry = ShouldNotCallThisStub(); | |
202 StubRoutines::_call_stub_entry = (address) call_stub; | |
203 StubRoutines::_catch_exception_entry = ShouldNotCallThisStub(); | |
204 | |
205 // atomic calls | |
206 StubRoutines::_atomic_xchg_entry = ShouldNotCallThisStub(); | |
207 StubRoutines::_atomic_xchg_ptr_entry = ShouldNotCallThisStub(); | |
208 StubRoutines::_atomic_cmpxchg_entry = ShouldNotCallThisStub(); | |
209 StubRoutines::_atomic_cmpxchg_ptr_entry = ShouldNotCallThisStub(); | |
210 StubRoutines::_atomic_cmpxchg_long_entry = ShouldNotCallThisStub(); | |
211 StubRoutines::_atomic_add_entry = ShouldNotCallThisStub(); | |
212 StubRoutines::_atomic_add_ptr_entry = ShouldNotCallThisStub(); | |
213 StubRoutines::_fence_entry = ShouldNotCallThisStub(); | |
214 | |
215 // amd64 does this here, sparc does it in generate_all() | |
216 StubRoutines::_handler_for_unsafe_access_entry = | |
217 ShouldNotCallThisStub(); | |
218 } | |
219 | |
220 void generate_all() { | |
221 // Generates all stubs and initializes the entry points | |
222 | |
223 // These entry points require SharedInfo::stack0 to be set up in | |
224 // non-core builds and need to be relocatable, so they each | |
225 // fabricate a RuntimeStub internally. | |
226 StubRoutines::_throw_AbstractMethodError_entry = | |
227 ShouldNotCallThisStub(); | |
228 | |
229 StubRoutines::_throw_NullPointerException_at_call_entry = | |
230 ShouldNotCallThisStub(); | |
231 | |
232 StubRoutines::_throw_StackOverflowError_entry = | |
233 ShouldNotCallThisStub(); | |
234 | |
235 // support for verify_oop (must happen after universe_init) | |
236 StubRoutines::_verify_oop_subroutine_entry = | |
237 ShouldNotCallThisStub(); | |
238 | |
239 // arraycopy stubs used by compilers | |
240 generate_arraycopy_stubs(); | |
12011
c54a3122f9c8
8022188: Make zero compile after 8016131 and 8016697
omajid
parents:
7180
diff
changeset
|
241 |
c54a3122f9c8
8022188: Make zero compile after 8016131 and 8016697
omajid
parents:
7180
diff
changeset
|
242 // Safefetch stubs. |
c54a3122f9c8
8022188: Make zero compile after 8016131 and 8016697
omajid
parents:
7180
diff
changeset
|
243 StubRoutines::_safefetch32_entry = CAST_FROM_FN_PTR(address, StubGenerator::SafeFetch32); |
c54a3122f9c8
8022188: Make zero compile after 8016131 and 8016697
omajid
parents:
7180
diff
changeset
|
244 StubRoutines::_safefetch32_fault_pc = NULL; |
c54a3122f9c8
8022188: Make zero compile after 8016131 and 8016697
omajid
parents:
7180
diff
changeset
|
245 StubRoutines::_safefetch32_continuation_pc = NULL; |
c54a3122f9c8
8022188: Make zero compile after 8016131 and 8016697
omajid
parents:
7180
diff
changeset
|
246 |
c54a3122f9c8
8022188: Make zero compile after 8016131 and 8016697
omajid
parents:
7180
diff
changeset
|
247 StubRoutines::_safefetchN_entry = CAST_FROM_FN_PTR(address, StubGenerator::SafeFetchN); |
c54a3122f9c8
8022188: Make zero compile after 8016131 and 8016697
omajid
parents:
7180
diff
changeset
|
248 StubRoutines::_safefetchN_fault_pc = NULL; |
c54a3122f9c8
8022188: Make zero compile after 8016131 and 8016697
omajid
parents:
7180
diff
changeset
|
249 StubRoutines::_safefetchN_continuation_pc = NULL; |
1010 | 250 } |
251 | |
252 public: | |
253 StubGenerator(CodeBuffer* code, bool all) : StubCodeGenerator(code) { | |
254 if (all) { | |
255 generate_all(); | |
256 } else { | |
257 generate_initial(); | |
258 } | |
259 } | |
260 }; | |
261 | |
262 void StubGenerator_generate(CodeBuffer* code, bool all) { | |
263 StubGenerator g(code, all); | |
264 } | |
265 | |
1379 | 266 EntryFrame *EntryFrame::build(const intptr_t* parameters, |
1010 | 267 int parameter_words, |
1379 | 268 JavaCallWrapper* call_wrapper, |
269 TRAPS) { | |
270 | |
271 ZeroStack *stack = ((JavaThread *) THREAD)->zero_stack(); | |
272 stack->overflow_check(header_words + parameter_words, CHECK_NULL); | |
1010 | 273 |
274 stack->push(0); // next_frame, filled in later | |
275 intptr_t *fp = stack->sp(); | |
276 assert(fp - stack->sp() == next_frame_off, "should be"); | |
277 | |
278 stack->push(ENTRY_FRAME); | |
279 assert(fp - stack->sp() == frame_type_off, "should be"); | |
280 | |
281 stack->push((intptr_t) call_wrapper); | |
282 assert(fp - stack->sp() == call_wrapper_off, "should be"); | |
283 | |
284 for (int i = 0; i < parameter_words; i++) | |
285 stack->push(parameters[i]); | |
286 | |
287 return (EntryFrame *) fp; | |
288 } |