Mercurial > hg > truffle
annotate src/share/vm/graal/graalRuntime.cpp @ 9093:cd22923e7ca7
removed unnecessary code
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 12 Apr 2013 21:35:27 +0200 |
parents | c3657d00e343 |
children | bb2447c64055 |
rev | line source |
---|---|
7221 | 1 /* |
2 * Copyright (c) 2012, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 | |
24 #include "precompiled.hpp" | |
7735 | 25 #include "asm/codeBuffer.hpp" |
7221 | 26 #include "graal/graalRuntime.hpp" |
27 #include "graal/graalVMToCompiler.hpp" | |
7735 | 28 #include "memory/oopFactory.hpp" |
29 #include "prims/jvm.h" | |
7221 | 30 #include "runtime/biasedLocking.hpp" |
7735 | 31 #include "runtime/interfaceSupport.hpp" |
8499
96a337d307bd
-More progress in G1 WBs
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
8496
diff
changeset
|
32 #include "utilities/debug.hpp" |
7221 | 33 // Implementation of GraalStubAssembler |
34 | |
35 GraalStubAssembler::GraalStubAssembler(CodeBuffer* code, const char * name, int stub_id) : MacroAssembler(code) { | |
36 _name = name; | |
37 _must_gc_arguments = false; | |
38 _frame_size = no_frame_size; | |
39 _num_rt_args = 0; | |
40 _stub_id = stub_id; | |
41 } | |
42 | |
43 | |
44 void GraalStubAssembler::set_info(const char* name, bool must_gc_arguments) { | |
45 _name = name; | |
46 _must_gc_arguments = must_gc_arguments; | |
47 } | |
48 | |
49 | |
50 void GraalStubAssembler::set_frame_size(int size) { | |
51 if (_frame_size == no_frame_size) { | |
52 _frame_size = size; | |
53 } | |
54 assert(_frame_size == size, "can't change the frame size"); | |
55 } | |
56 | |
57 | |
58 void GraalStubAssembler::set_num_rt_args(int args) { | |
59 if (_num_rt_args == 0) { | |
60 _num_rt_args = args; | |
61 } | |
62 assert(_num_rt_args == args, "can't change the number of args"); | |
63 } | |
64 | |
65 // Implementation of GraalRuntime | |
66 | |
67 CodeBlob* GraalRuntime::_blobs[GraalRuntime::number_of_ids]; | |
68 const char *GraalRuntime::_blob_names[] = { | |
69 GRAAL_STUBS(STUB_NAME, LAST_STUB_NAME) | |
70 }; | |
71 | |
72 // Simple helper to see if the caller of a runtime stub which | |
73 // entered the VM has been deoptimized | |
74 | |
75 static bool caller_is_deopted() { | |
76 JavaThread* thread = JavaThread::current(); | |
77 RegisterMap reg_map(thread, false); | |
78 frame runtime_frame = thread->last_frame(); | |
79 frame caller_frame = runtime_frame.sender(®_map); | |
80 assert(caller_frame.is_compiled_frame(), "must be compiled"); | |
81 return caller_frame.is_deoptimized_frame(); | |
82 } | |
83 | |
84 // Stress deoptimization | |
85 static void deopt_caller() { | |
86 if ( !caller_is_deopted()) { | |
87 JavaThread* thread = JavaThread::current(); | |
88 RegisterMap reg_map(thread, false); | |
89 frame runtime_frame = thread->last_frame(); | |
90 frame caller_frame = runtime_frame.sender(®_map); | |
91 Deoptimization::deoptimize_frame(thread, caller_frame.id(), Deoptimization::Reason_constraint); | |
92 assert(caller_is_deopted(), "Must be deoptimized"); | |
93 } | |
94 } | |
95 | |
96 static bool setup_code_buffer(CodeBuffer* code) { | |
97 // Preinitialize the consts section to some large size: | |
98 int locs_buffer_size = 1 * (relocInfo::length_limit + sizeof(relocInfo)); | |
99 char* locs_buffer = NEW_RESOURCE_ARRAY(char, locs_buffer_size); | |
100 code->insts()->initialize_shared_locs((relocInfo*)locs_buffer, | |
101 locs_buffer_size / sizeof(relocInfo)); | |
102 | |
103 // Global stubs have neither constants nor local stubs | |
104 code->initialize_consts_size(0); | |
105 code->initialize_stubs_size(0); | |
106 | |
107 return true; | |
108 } | |
109 | |
110 void GraalRuntime::generate_blob_for(BufferBlob* buffer_blob, StubID id) { | |
111 assert(0 <= id && id < number_of_ids, "illegal stub id"); | |
112 ResourceMark rm; | |
113 // create code buffer for code storage | |
114 CodeBuffer code(buffer_blob); | |
115 | |
116 setup_code_buffer(&code); | |
117 | |
118 // create assembler for code generation | |
119 GraalStubAssembler* sasm = new GraalStubAssembler(&code, name_for(id), id); | |
120 // generate code for runtime stub | |
121 OopMapSet* oop_maps; | |
122 oop_maps = generate_code_for(id, sasm); | |
7226 | 123 assert(oop_maps == NULL || sasm->frame_size() != GraalStubAssembler::no_frame_size, |
7221 | 124 "if stub has an oop map it must have a valid frame size"); |
125 | |
126 #ifdef ASSERT | |
127 // Make sure that stubs that need oopmaps have them | |
128 switch (id) { | |
129 // These stubs don't need to have an oopmap | |
130 #if defined(SPARC) || defined(PPC) | |
7911
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
131 case handle_exception_nofpu_id: // Unused on sparc |
7221 | 132 #endif |
7911
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
133 case verify_oop_id: |
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
134 case unwind_exception_call_id: |
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
135 case OSR_migration_end_id: |
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
136 case arithmetic_frem_id: |
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
137 case arithmetic_drem_id: |
7221 | 138 break; |
139 // All other stubs should have oopmaps | |
140 default: | |
141 assert(oop_maps != NULL, "must have an oopmap"); | |
142 } | |
143 #endif | |
144 | |
145 // align so printing shows nop's instead of random code at the end (SimpleStubs are aligned) | |
146 sasm->align(BytesPerWord); | |
147 // make sure all code is in code buffer | |
148 sasm->flush(); | |
149 // create blob - distinguish a few special cases | |
150 CodeBlob* blob = RuntimeStub::new_runtime_stub(name_for(id), | |
151 &code, | |
152 CodeOffsets::frame_never_safe, | |
153 sasm->frame_size(), | |
154 oop_maps, | |
155 sasm->must_gc_arguments()); | |
156 // install blob | |
157 assert(blob != NULL, "blob must exist"); | |
158 _blobs[id] = blob; | |
159 } | |
160 | |
161 | |
162 void GraalRuntime::initialize(BufferBlob* blob) { | |
163 // generate stubs | |
164 for (int id = 0; id < number_of_ids; id++) generate_blob_for(blob, (StubID)id); | |
165 // printing | |
166 #ifndef PRODUCT | |
7226 | 167 if (GraalPrintSimpleStubs) { |
7221 | 168 ResourceMark rm; |
169 for (int id = 0; id < number_of_ids; id++) { | |
170 _blobs[id]->print(); | |
171 if (_blobs[id]->oop_maps() != NULL) { | |
172 _blobs[id]->oop_maps()->print(); | |
173 } | |
174 } | |
175 } | |
176 #endif | |
177 } | |
178 | |
179 | |
180 CodeBlob* GraalRuntime::blob_for(StubID id) { | |
181 assert(0 <= id && id < number_of_ids, "illegal stub id"); | |
182 return _blobs[id]; | |
183 } | |
184 | |
185 | |
186 const char* GraalRuntime::name_for(StubID id) { | |
187 assert(0 <= id && id < number_of_ids, "illegal stub id"); | |
188 return _blob_names[id]; | |
189 } | |
190 | |
191 const char* GraalRuntime::name_for_address(address entry) { | |
192 for (int id = 0; id < number_of_ids; id++) { | |
193 if (entry == entry_for((StubID)id)) return name_for((StubID)id); | |
194 } | |
195 | |
196 #define FUNCTION_CASE(a, f) \ | |
197 if ((intptr_t)a == CAST_FROM_FN_PTR(intptr_t, f)) return #f | |
198 | |
199 FUNCTION_CASE(entry, os::javaTimeMillis); | |
200 FUNCTION_CASE(entry, os::javaTimeNanos); | |
201 FUNCTION_CASE(entry, SharedRuntime::OSR_migration_end); | |
202 FUNCTION_CASE(entry, SharedRuntime::d2f); | |
203 FUNCTION_CASE(entry, SharedRuntime::d2i); | |
204 FUNCTION_CASE(entry, SharedRuntime::d2l); | |
205 FUNCTION_CASE(entry, SharedRuntime::dcos); | |
206 FUNCTION_CASE(entry, SharedRuntime::dexp); | |
207 FUNCTION_CASE(entry, SharedRuntime::dlog); | |
208 FUNCTION_CASE(entry, SharedRuntime::dlog10); | |
209 FUNCTION_CASE(entry, SharedRuntime::dpow); | |
210 FUNCTION_CASE(entry, SharedRuntime::drem); | |
211 FUNCTION_CASE(entry, SharedRuntime::dsin); | |
212 FUNCTION_CASE(entry, SharedRuntime::dtan); | |
213 FUNCTION_CASE(entry, SharedRuntime::f2i); | |
214 FUNCTION_CASE(entry, SharedRuntime::f2l); | |
215 FUNCTION_CASE(entry, SharedRuntime::frem); | |
216 FUNCTION_CASE(entry, SharedRuntime::l2d); | |
217 FUNCTION_CASE(entry, SharedRuntime::l2f); | |
218 FUNCTION_CASE(entry, SharedRuntime::ldiv); | |
219 FUNCTION_CASE(entry, SharedRuntime::lmul); | |
220 FUNCTION_CASE(entry, SharedRuntime::lrem); | |
221 FUNCTION_CASE(entry, SharedRuntime::lrem); | |
222 FUNCTION_CASE(entry, SharedRuntime::dtrace_method_entry); | |
223 FUNCTION_CASE(entry, SharedRuntime::dtrace_method_exit); | |
224 #ifdef TRACE_HAVE_INTRINSICS | |
225 FUNCTION_CASE(entry, TRACE_TIME_METHOD); | |
226 #endif | |
227 | |
228 ShouldNotReachHere(); | |
229 return NULL; | |
230 | |
231 #undef FUNCTION_CASE | |
232 } | |
233 | |
234 | |
235 JRT_ENTRY(void, GraalRuntime::new_instance(JavaThread* thread, Klass* klass)) | |
236 assert(klass->is_klass(), "not a class"); | |
237 instanceKlassHandle h(thread, klass); | |
238 h->check_valid_for_instantiation(true, CHECK); | |
239 // make sure klass is initialized | |
240 h->initialize(CHECK); | |
241 // allocate instance and return via TLS | |
242 oop obj = h->allocate_instance(CHECK); | |
243 thread->set_vm_result(obj); | |
244 JRT_END | |
245 | |
246 JRT_ENTRY(void, GraalRuntime::new_array(JavaThread* thread, Klass* array_klass, jint length)) | |
247 // Note: no handle for klass needed since they are not used | |
248 // anymore after new_objArray() and no GC can happen before. | |
249 // (This may have to change if this code changes!) | |
250 assert(array_klass->is_klass(), "not a class"); | |
251 oop obj; | |
252 if (array_klass->oop_is_typeArray()) { | |
253 BasicType elt_type = TypeArrayKlass::cast(array_klass)->element_type(); | |
254 obj = oopFactory::new_typeArray(elt_type, length, CHECK); | |
255 } else { | |
256 Klass* elem_klass = ObjArrayKlass::cast(array_klass)->element_klass(); | |
257 obj = oopFactory::new_objArray(elem_klass, length, CHECK); | |
258 } | |
259 thread->set_vm_result(obj); | |
260 // This is pretty rare but this runtime patch is stressful to deoptimization | |
261 // if we deoptimize here so force a deopt to stress the path. | |
262 if (DeoptimizeALot) { | |
263 deopt_caller(); | |
264 } | |
8502
ff4fa8b0516e
-Create push patch
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
8501
diff
changeset
|
265 JRT_END |
ff4fa8b0516e
-Create push patch
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
8501
diff
changeset
|
266 |
7221 | 267 |
268 | |
269 JRT_ENTRY(void, GraalRuntime::new_multi_array(JavaThread* thread, Klass* klass, int rank, jint* dims)) | |
270 assert(klass->is_klass(), "not a class"); | |
271 assert(rank >= 1, "rank must be nonzero"); | |
272 oop obj = ArrayKlass::cast(klass)->multi_allocate(rank, dims, CHECK); | |
273 thread->set_vm_result(obj); | |
274 JRT_END | |
275 | |
276 JRT_ENTRY(void, GraalRuntime::unimplemented_entry(JavaThread* thread, StubID id)) | |
277 tty->print_cr("GraalRuntime::entry_for(%d) returned unimplemented entry point", id); | |
278 JRT_END | |
279 | |
280 extern void vm_exit(int code); | |
281 | |
282 // Enter this method from compiled code handler below. This is where we transition | |
283 // to VM mode. This is done as a helper routine so that the method called directly | |
284 // from compiled code does not have to transition to VM. This allows the entry | |
285 // method to see if the nmethod that we have just looked up a handler for has | |
286 // been deoptimized while we were in the vm. This simplifies the assembly code | |
287 // cpu directories. | |
288 // | |
289 // We are entering here from exception stub (via the entry method below) | |
290 // If there is a compiled exception handler in this method, we will continue there; | |
291 // otherwise we will unwind the stack and continue at the caller of top frame method | |
292 // Note: we enter in Java using a special JRT wrapper. This wrapper allows us to | |
293 // control the area where we can allow a safepoint. After we exit the safepoint area we can | |
294 // check to see if the handler we are going to return is now in a nmethod that has | |
295 // been deoptimized. If that is the case we return the deopt blob | |
296 // unpack_with_exception entry instead. This makes life for the exception blob easier | |
297 // because making that same check and diverting is painful from assembly language. | |
298 JRT_ENTRY_NO_ASYNC(static address, exception_handler_for_pc_helper(JavaThread* thread, oopDesc* ex, address pc, nmethod*& nm)) | |
299 // Reset method handle flag. | |
300 thread->set_is_method_handle_return(false); | |
301 | |
302 Handle exception(thread, ex); | |
303 nm = CodeCache::find_nmethod(pc); | |
304 assert(nm != NULL, "this is not an nmethod"); | |
305 // Adjust the pc as needed/ | |
306 if (nm->is_deopt_pc(pc)) { | |
307 RegisterMap map(thread, false); | |
308 frame exception_frame = thread->last_frame().sender(&map); | |
309 // if the frame isn't deopted then pc must not correspond to the caller of last_frame | |
310 assert(exception_frame.is_deoptimized_frame(), "must be deopted"); | |
311 pc = exception_frame.pc(); | |
312 } | |
313 #ifdef ASSERT | |
314 assert(exception.not_null(), "NULL exceptions should be handled by throw_exception"); | |
315 assert(exception->is_oop(), "just checking"); | |
316 // Check that exception is a subclass of Throwable, otherwise we have a VerifyError | |
317 if (!(exception->is_a(SystemDictionary::Throwable_klass()))) { | |
318 if (ExitVMOnVerifyError) vm_exit(-1); | |
319 ShouldNotReachHere(); | |
320 } | |
321 #endif | |
322 | |
323 // Check the stack guard pages and reenable them if necessary and there is | |
324 // enough space on the stack to do so. Use fast exceptions only if the guard | |
325 // pages are enabled. | |
326 bool guard_pages_enabled = thread->stack_yellow_zone_enabled(); | |
327 if (!guard_pages_enabled) guard_pages_enabled = thread->reguard_stack(); | |
328 | |
329 if (JvmtiExport::can_post_on_exceptions()) { | |
330 // To ensure correct notification of exception catches and throws | |
331 // we have to deoptimize here. If we attempted to notify the | |
332 // catches and throws during this exception lookup it's possible | |
333 // we could deoptimize on the way out of the VM and end back in | |
334 // the interpreter at the throw site. This would result in double | |
335 // notifications since the interpreter would also notify about | |
336 // these same catches and throws as it unwound the frame. | |
337 | |
338 RegisterMap reg_map(thread); | |
339 frame stub_frame = thread->last_frame(); | |
340 frame caller_frame = stub_frame.sender(®_map); | |
341 | |
342 // We don't really want to deoptimize the nmethod itself since we | |
343 // can actually continue in the exception handler ourselves but I | |
344 // don't see an easy way to have the desired effect. | |
345 Deoptimization::deoptimize_frame(thread, caller_frame.id(), Deoptimization::Reason_constraint); | |
346 assert(caller_is_deopted(), "Must be deoptimized"); | |
347 | |
348 return SharedRuntime::deopt_blob()->unpack_with_exception_in_tls(); | |
349 } | |
350 | |
351 // ExceptionCache is used only for exceptions at call sites and not for implicit exceptions | |
352 if (guard_pages_enabled) { | |
353 address fast_continuation = nm->handler_for_exception_and_pc(exception, pc); | |
354 if (fast_continuation != NULL) { | |
355 // Set flag if return address is a method handle call site. | |
356 thread->set_is_method_handle_return(nm->is_method_handle_return(pc)); | |
357 return fast_continuation; | |
358 } | |
359 } | |
360 | |
361 // If the stack guard pages are enabled, check whether there is a handler in | |
362 // the current method. Otherwise (guard pages disabled), force an unwind and | |
363 // skip the exception cache update (i.e., just leave continuation==NULL). | |
364 address continuation = NULL; | |
365 if (guard_pages_enabled) { | |
366 | |
367 // New exception handling mechanism can support inlined methods | |
368 // with exception handlers since the mappings are from PC to PC | |
369 | |
370 // debugging support | |
371 // tracing | |
372 if (TraceExceptions) { | |
373 ttyLocker ttyl; | |
374 ResourceMark rm; | |
375 int offset = pc - nm->code_begin(); | |
376 tty->print_cr("Exception <%s> (0x%x) thrown in compiled method <%s> at PC " PTR_FORMAT " [" PTR_FORMAT "+%d] for thread 0x%x", | |
377 exception->print_value_string(), (address)exception(), nm->method()->print_value_string(), pc, nm->code_begin(), offset, thread); | |
378 } | |
379 // for AbortVMOnException flag | |
380 NOT_PRODUCT(Exceptions::debug_check_abort(exception)); | |
381 | |
382 // Clear out the exception oop and pc since looking up an | |
383 // exception handler can cause class loading, which might throw an | |
384 // exception and those fields are expected to be clear during | |
385 // normal bytecode execution. | |
386 thread->set_exception_oop(NULL); | |
387 thread->set_exception_pc(NULL); | |
388 | |
389 continuation = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, false, false); | |
390 // If an exception was thrown during exception dispatch, the exception oop may have changed | |
391 thread->set_exception_oop(exception()); | |
392 thread->set_exception_pc(pc); | |
393 | |
394 // the exception cache is used only by non-implicit exceptions | |
395 if (continuation != NULL && !SharedRuntime::deopt_blob()->contains(continuation)) { | |
396 nm->add_handler_for_exception_and_pc(exception, pc, continuation); | |
397 } | |
398 } | |
399 | |
400 thread->set_vm_result(exception()); | |
401 // Set flag if return address is a method handle call site. | |
402 thread->set_is_method_handle_return(nm->is_method_handle_return(pc)); | |
403 | |
404 if (TraceExceptions) { | |
405 ttyLocker ttyl; | |
406 ResourceMark rm; | |
407 tty->print_cr("Thread " PTR_FORMAT " continuing at PC " PTR_FORMAT " for exception thrown at PC " PTR_FORMAT, | |
408 thread, continuation, pc); | |
409 } | |
410 | |
411 return continuation; | |
412 JRT_END | |
413 | |
414 // Enter this method from compiled code only if there is a Java exception handler | |
415 // in the method handling the exception. | |
416 // We are entering here from exception stub. We don't do a normal VM transition here. | |
417 // We do it in a helper. This is so we can check to see if the nmethod we have just | |
418 // searched for an exception handler has been deoptimized in the meantime. | |
419 address GraalRuntime::exception_handler_for_pc(JavaThread* thread) { | |
420 oop exception = thread->exception_oop(); | |
421 address pc = thread->exception_pc(); | |
422 // Still in Java mode | |
423 DEBUG_ONLY(ResetNoHandleMark rnhm); | |
424 nmethod* nm = NULL; | |
425 address continuation = NULL; | |
426 { | |
427 // Enter VM mode by calling the helper | |
428 ResetNoHandleMark rnhm; | |
429 continuation = exception_handler_for_pc_helper(thread, exception, pc, nm); | |
430 } | |
431 // Back in JAVA, use no oops DON'T safepoint | |
432 | |
433 // Now check to see if the nmethod we were called from is now deoptimized. | |
434 // If so we must return to the deopt blob and deoptimize the nmethod | |
435 if (nm != NULL && caller_is_deopted()) { | |
436 continuation = SharedRuntime::deopt_blob()->unpack_with_exception_in_tls(); | |
437 } | |
438 | |
439 assert(continuation != NULL, "no handler found"); | |
440 return continuation; | |
441 } | |
442 | |
7911
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
443 JRT_ENTRY(void, GraalRuntime::create_null_exception(JavaThread* thread)) |
7221 | 444 thread->set_vm_result(Exceptions::new_exception(thread, vmSymbols::java_lang_NullPointerException(), NULL)()); |
445 JRT_END | |
446 | |
7911
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
447 JRT_ENTRY(void, GraalRuntime::create_out_of_bounds_exception(JavaThread* thread, jint index)) |
7221 | 448 char message[jintAsStringSize]; |
449 sprintf(message, "%d", index); | |
450 thread->set_vm_result(Exceptions::new_exception(thread, vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), message)()); | |
451 JRT_END | |
452 | |
7911
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
453 JRT_ENTRY_NO_ASYNC(void, GraalRuntime::monitorenter(JavaThread* thread, oopDesc* obj, BasicLock* lock)) |
7221 | 454 if (TraceGraal >= 3) { |
455 char type[O_BUFLEN]; | |
456 obj->klass()->name()->as_C_string(type, O_BUFLEN); | |
457 markOop mark = obj->mark(); | |
458 tty->print_cr("%s: entered locking slow case with obj=" INTPTR_FORMAT ", type=%s, mark=" INTPTR_FORMAT ", lock=" INTPTR_FORMAT, thread->name(), obj, type, mark, lock); | |
459 tty->flush(); | |
460 } | |
461 #ifdef ASSERT | |
462 if (PrintBiasedLockingStatistics) { | |
463 Atomic::inc(BiasedLocking::slow_path_entry_count_addr()); | |
464 } | |
465 #endif | |
466 Handle h_obj(thread, obj); | |
467 assert(h_obj()->is_oop(), "must be NULL or an object"); | |
468 if (UseBiasedLocking) { | |
469 // Retry fast entry if bias is revoked to avoid unnecessary inflation | |
470 ObjectSynchronizer::fast_enter(h_obj, lock, true, CHECK); | |
471 } else { | |
7226 | 472 if (GraalUseFastLocking) { |
7221 | 473 // When using fast locking, the compiled code has already tried the fast case |
474 ObjectSynchronizer::slow_enter(h_obj, lock, THREAD); | |
475 } else { | |
476 ObjectSynchronizer::fast_enter(h_obj, lock, false, THREAD); | |
477 } | |
478 } | |
479 if (TraceGraal >= 3) { | |
480 tty->print_cr("%s: exiting locking slow with obj=" INTPTR_FORMAT, thread->name(), obj); | |
481 } | |
482 JRT_END | |
483 | |
8506 | 484 JRT_LEAF(void, GraalRuntime::wb_pre_call(JavaThread* thread, oopDesc* obj)) |
8502
ff4fa8b0516e
-Create push patch
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
8501
diff
changeset
|
485 thread->satb_mark_queue().enqueue(obj); |
8490
1567c6cc6561
Towards porting G1 WBs
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
8489
diff
changeset
|
486 JRT_END |
1567c6cc6561
Towards porting G1 WBs
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
8489
diff
changeset
|
487 |
8506 | 488 JRT_LEAF(void, GraalRuntime::wb_post_call(JavaThread* thread, oopDesc* obj, void* card_addr)) |
8495
9131c075be7b
-More porting to G1 WBs
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
8492
diff
changeset
|
489 thread->dirty_card_queue().enqueue(card_addr); |
8489
92d21814cf7b
-Implement WB primitive stub call for G1's slow path later
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
7735
diff
changeset
|
490 JRT_END |
7221 | 491 |
7911
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
492 JRT_LEAF(void, GraalRuntime::monitorexit(JavaThread* thread, oopDesc* obj, BasicLock* lock)) |
7221 | 493 assert(thread == JavaThread::current(), "threads must correspond"); |
494 assert(thread->last_Java_sp(), "last_Java_sp must be set"); | |
495 // monitorexit is non-blocking (leaf routine) => no exceptions can be thrown | |
496 EXCEPTION_MARK; | |
497 | |
498 #ifdef DEBUG | |
499 if (!obj->is_oop()) { | |
500 ResetNoHandleMark rhm; | |
501 nmethod* method = thread->last_frame().cb()->as_nmethod_or_null(); | |
502 if (method != NULL) { | |
503 tty->print_cr("ERROR in monitorexit in method %s wrong obj " INTPTR_FORMAT, method->name(), obj); | |
504 } | |
505 thread->print_stack_on(tty); | |
506 assert(false, "invalid lock object pointer dected"); | |
507 } | |
508 #endif | |
509 | |
7226 | 510 if (GraalUseFastLocking) { |
7221 | 511 // When using fast locking, the compiled code has already tried the fast case |
512 ObjectSynchronizer::slow_exit(obj, lock, THREAD); | |
513 } else { | |
514 ObjectSynchronizer::fast_exit(obj, lock, THREAD); | |
515 } | |
516 if (TraceGraal >= 3) { | |
517 char type[O_BUFLEN]; | |
518 obj->klass()->name()->as_C_string(type, O_BUFLEN); | |
519 tty->print_cr("%s: exited locking slow case with obj=" INTPTR_FORMAT ", type=%s, mark=" INTPTR_FORMAT ", lock=" INTPTR_FORMAT, thread->name(), obj, type, obj->mark(), lock); | |
520 tty->flush(); | |
521 } | |
522 JRT_END | |
523 | |
7911
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
524 JRT_ENTRY(void, GraalRuntime::log_object(JavaThread* thread, oop obj, jint flags)) |
7221 | 525 bool string = mask_bits_are_true(flags, LOG_OBJECT_STRING); |
526 bool address = mask_bits_are_true(flags, LOG_OBJECT_ADDRESS); | |
527 bool newline = mask_bits_are_true(flags, LOG_OBJECT_NEWLINE); | |
528 if (!string) { | |
529 if (!address && obj->is_oop_or_null(true)) { | |
530 char buf[O_BUFLEN]; | |
531 tty->print("%s@%p", obj->klass()->name()->as_C_string(buf, O_BUFLEN), obj); | |
532 } else { | |
533 tty->print("%p", obj); | |
534 } | |
535 } else { | |
536 ResourceMark rm; | |
537 assert(obj != NULL && java_lang_String::is_instance(obj), "must be"); | |
538 char *buf = java_lang_String::as_utf8_string(obj); | |
539 tty->print(buf); | |
540 } | |
541 if (newline) { | |
542 tty->cr(); | |
543 } | |
544 JRT_END | |
545 | |
7911
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
546 JRT_ENTRY(void, GraalRuntime::vm_error(JavaThread* thread, oop where, oop format, jlong value)) |
7221 | 547 ResourceMark rm; |
548 assert(where == NULL || java_lang_String::is_instance(where), "must be"); | |
549 const char *error_msg = where == NULL ? "<internal Graal error>" : java_lang_String::as_utf8_string(where); | |
550 char *detail_msg = NULL; | |
551 if (format != NULL) { | |
552 const char* buf = java_lang_String::as_utf8_string(format); | |
553 size_t detail_msg_length = strlen(buf) * 2; | |
554 detail_msg = (char *) NEW_RESOURCE_ARRAY(u_char, detail_msg_length); | |
555 jio_snprintf(detail_msg, detail_msg_length, buf, value); | |
556 } | |
557 report_vm_error(__FILE__, __LINE__, error_msg, detail_msg); | |
558 JRT_END | |
559 | |
8506 | 560 |
561 JRT_LEAF(void, GraalRuntime::log_printf(JavaThread* thread, oop format, jlong v1, jlong v2, jlong v3)) | |
7221 | 562 ResourceMark rm; |
563 assert(format != NULL && java_lang_String::is_instance(format), "must be"); | |
564 char *buf = java_lang_String::as_utf8_string(format); | |
7235
a6bd253a770f
expanded LOG_PRINTF stub to handle up to 3 arguments in addition to the format string
Doug Simon <doug.simon@oracle.com>
parents:
7226
diff
changeset
|
565 tty->print(buf, v1, v2, v3); |
7221 | 566 JRT_END |
567 | |
7911
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
568 JRT_ENTRY(void, GraalRuntime::log_primitive(JavaThread* thread, jchar typeChar, jlong value, jboolean newline)) |
7221 | 569 union { |
570 jlong l; | |
571 jdouble d; | |
572 jfloat f; | |
573 } uu; | |
574 uu.l = value; | |
575 switch (typeChar) { | |
576 case 'z': tty->print(value == 0 ? "false" : "true"); break; | |
577 case 'b': tty->print("%d", (jbyte) value); break; | |
578 case 'c': tty->print("%c", (jchar) value); break; | |
579 case 's': tty->print("%d", (jshort) value); break; | |
580 case 'i': tty->print("%d", (jint) value); break; | |
581 case 'f': tty->print("%f", uu.f); break; | |
582 case 'j': tty->print(INT64_FORMAT, value); break; | |
583 case 'd': tty->print("%lf", uu.d); break; | |
584 default: assert(false, "unknown typeChar"); break; | |
585 } | |
586 if (newline) { | |
587 tty->cr(); | |
588 } | |
589 JRT_END | |
590 | |
7911
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
591 JRT_ENTRY(jint, GraalRuntime::identity_hash_code(JavaThread* thread, oop obj)) |
7221 | 592 return (jint) obj->identity_hash(); |
593 JRT_END | |
594 | |
7911
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
595 JRT_ENTRY(jboolean, GraalRuntime::thread_is_interrupted(JavaThread* thread, oop receiver, jboolean clear_interrupted)) |
7220
fcae6d960acd
added more compiler intrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents:
7216
diff
changeset
|
596 // Ensure that the C++ Thread and OSThread structures aren't freed before we operate |
fcae6d960acd
added more compiler intrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents:
7216
diff
changeset
|
597 Handle receiverHandle(thread, receiver); |
7386
707e9cca11de
fixed HotSpot windows build
Christian Haeubl <haeubl@ssw.jku.at>
parents:
7235
diff
changeset
|
598 MutexLockerEx ml(thread->threadObj() == receiver ? NULL : Threads_lock); |
707e9cca11de
fixed HotSpot windows build
Christian Haeubl <haeubl@ssw.jku.at>
parents:
7235
diff
changeset
|
599 JavaThread* receiverThread = java_lang_Thread::thread(receiverHandle()); |
707e9cca11de
fixed HotSpot windows build
Christian Haeubl <haeubl@ssw.jku.at>
parents:
7235
diff
changeset
|
600 return (jint) Thread::is_interrupted(receiverThread, clear_interrupted != 0); |
7221 | 601 JRT_END |
602 | |
603 // JVM_InitializeGraalRuntime | |
604 JVM_ENTRY(jobject, JVM_InitializeGraalRuntime(JNIEnv *env, jclass graalclass)) | |
605 return VMToCompiler::graalRuntimePermObject(); | |
606 JVM_END |