77
78 DeoptimizationBlob* SharedRuntime::_deopt_blob;
79 SafepointBlob* SharedRuntime::_polling_page_vectors_safepoint_handler_blob;
80 SafepointBlob* SharedRuntime::_polling_page_safepoint_handler_blob;
81 SafepointBlob* SharedRuntime::_polling_page_return_handler_blob;
82
83 #ifdef COMPILER2
84 UncommonTrapBlob* SharedRuntime::_uncommon_trap_blob;
85 #endif // COMPILER2
86
87
88 //----------------------------generate_stubs-----------------------------------
89 void SharedRuntime::generate_stubs() {
90 _wrong_method_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::handle_wrong_method), "wrong_method_stub");
91 _wrong_method_abstract_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::handle_wrong_method_abstract), "wrong_method_abstract_stub");
92 _ic_miss_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::handle_wrong_method_ic_miss), "ic_miss_stub");
93 _resolve_opt_virtual_call_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::resolve_opt_virtual_call_C), "resolve_opt_virtual_call");
94 _resolve_virtual_call_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::resolve_virtual_call_C), "resolve_virtual_call");
95 _resolve_static_call_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::resolve_static_call_C), "resolve_static_call");
96
97 #ifdef COMPILER2
98 // Vectors are generated only by C2.
99 if (is_wide_vector(MaxVectorSize)) {
100 _polling_page_vectors_safepoint_handler_blob = generate_handler_blob(CAST_FROM_FN_PTR(address, SafepointSynchronize::handle_polling_page_exception), POLL_AT_VECTOR_LOOP);
101 }
102 #endif // COMPILER2
103 _polling_page_safepoint_handler_blob = generate_handler_blob(CAST_FROM_FN_PTR(address, SafepointSynchronize::handle_polling_page_exception), POLL_AT_LOOP);
104 _polling_page_return_handler_blob = generate_handler_blob(CAST_FROM_FN_PTR(address, SafepointSynchronize::handle_polling_page_exception), POLL_AT_RETURN);
105
106 generate_deopt_blob();
107
108 #ifdef COMPILER2
109 generate_uncommon_trap_blob();
110 #endif // COMPILER2
111 }
112
113 #include <math.h>
114
115 // Implementation of SharedRuntime
116
117 #ifndef PRODUCT
118 // For statistics
119 int SharedRuntime::_ic_miss_ctr = 0;
120 int SharedRuntime::_wrong_method_ctr = 0;
121 int SharedRuntime::_resolve_static_ctr = 0;
122 int SharedRuntime::_resolve_virtual_ctr = 0;
123 int SharedRuntime::_resolve_opt_virtual_ctr = 0;
124 int SharedRuntime::_implicit_null_throws = 0;
125 int SharedRuntime::_implicit_div0_throws = 0;
126 int SharedRuntime::_throw_null_ctr = 0;
127
128 int SharedRuntime::_nof_normal_calls = 0;
129 int SharedRuntime::_nof_optimized_calls = 0;
130 int SharedRuntime::_nof_inlined_calls = 0;
131 int SharedRuntime::_nof_megamorphic_calls = 0;
132 int SharedRuntime::_nof_static_calls = 0;
179 _ICmiss_count[index] = 1;
180 }
181
182 void SharedRuntime::print_ic_miss_histogram() {
183 if (ICMissHistogram) {
184 tty->print_cr("IC Miss Histogram:");
185 int tot_misses = 0;
186 for (int i = 0; i < _ICmiss_index; i++) {
187 tty->print_cr(" at: " INTPTR_FORMAT " nof: %d", _ICmiss_at[i], _ICmiss_count[i]);
188 tot_misses += _ICmiss_count[i];
189 }
190 tty->print_cr("Total IC misses: %7d", tot_misses);
191 }
192 }
193 #endif // PRODUCT
194
195 #if INCLUDE_ALL_GCS
196
197 // G1 write-barrier pre: executed before a pointer store.
198 JRT_LEAF(void, SharedRuntime::g1_wb_pre(oopDesc* orig, JavaThread *thread))
199 if (orig == NULL) {
200 assert(false, "should be optimized out");
201 return;
202 }
203 assert(orig->is_oop(true /* ignore mark word */), "Error");
204 // store the original value that was in the field reference
205 thread->satb_mark_queue().enqueue(orig);
206 JRT_END
207
208 // G1 write-barrier post: executed after a pointer store.
209 JRT_LEAF(void, SharedRuntime::g1_wb_post(void* card_addr, JavaThread* thread))
210 thread->dirty_card_queue().enqueue(card_addr);
211 JRT_END
212
213 #endif // INCLUDE_ALL_GCS
214
215
216 JRT_LEAF(jlong, SharedRuntime::lmul(jlong y, jlong x))
217 return x * y;
218 JRT_END
219
220
221 JRT_LEAF(jlong, SharedRuntime::ldiv(jlong y, jlong x))
222 if (x == min_jlong && y == CONST64(-1)) {
223 return x;
224 } else {
225 return x / y;
226 }
227 JRT_END
228
229
503 tty->print_cr("a) exception happened in (new?) code stubs/buffers that is not handled here");
504 tty->print_cr("b) other problem");
505 }
506 #endif // PRODUCT
507
508 ShouldNotReachHere();
509 return NULL;
510 }
511
512
513 JRT_LEAF(address, SharedRuntime::exception_handler_for_return_address(JavaThread* thread, address return_address))
514 return raw_exception_handler_for_return_address(thread, return_address);
515 JRT_END
516
517
518 address SharedRuntime::get_poll_stub(address pc) {
519 address stub;
520 // Look up the code blob
521 CodeBlob *cb = CodeCache::find_blob(pc);
522
523 // Should be an nmethod
524 assert(cb && cb->is_nmethod(), "safepoint polling: pc must refer to an nmethod");
525
526 // Look up the relocation information
527 assert(((nmethod*)cb)->is_at_poll_or_poll_return(pc),
528 "safepoint polling: type must be poll");
529
530 assert(((NativeInstruction*)pc)->is_safepoint_poll(),
531 "Only polling locations are used for safepoint");
532
533 bool at_poll_return = ((nmethod*)cb)->is_at_poll_return(pc);
534 bool has_wide_vectors = ((nmethod*)cb)->has_wide_vectors();
535 if (at_poll_return) {
536 assert(SharedRuntime::polling_page_return_handler_blob() != NULL,
537 "polling page return stub not created yet");
538 stub = SharedRuntime::polling_page_return_handler_blob()->entry_point();
539 } else if (has_wide_vectors) {
540 assert(SharedRuntime::polling_page_vectors_safepoint_handler_blob() != NULL,
541 "polling page vectors safepoint stub not created yet");
542 stub = SharedRuntime::polling_page_vectors_safepoint_handler_blob()->entry_point();
543 } else {
544 assert(SharedRuntime::polling_page_safepoint_handler_blob() != NULL,
545 "polling page safepoint stub not created yet");
546 stub = SharedRuntime::polling_page_safepoint_handler_blob()->entry_point();
547 }
548 #ifndef PRODUCT
549 if (TraceSafepoint) {
|
77
78 DeoptimizationBlob* SharedRuntime::_deopt_blob;
79 SafepointBlob* SharedRuntime::_polling_page_vectors_safepoint_handler_blob;
80 SafepointBlob* SharedRuntime::_polling_page_safepoint_handler_blob;
81 SafepointBlob* SharedRuntime::_polling_page_return_handler_blob;
82
83 #ifdef COMPILER2
84 UncommonTrapBlob* SharedRuntime::_uncommon_trap_blob;
85 #endif // COMPILER2
86
87
88 //----------------------------generate_stubs-----------------------------------
89 void SharedRuntime::generate_stubs() {
90 _wrong_method_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::handle_wrong_method), "wrong_method_stub");
91 _wrong_method_abstract_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::handle_wrong_method_abstract), "wrong_method_abstract_stub");
92 _ic_miss_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::handle_wrong_method_ic_miss), "ic_miss_stub");
93 _resolve_opt_virtual_call_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::resolve_opt_virtual_call_C), "resolve_opt_virtual_call");
94 _resolve_virtual_call_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::resolve_virtual_call_C), "resolve_virtual_call");
95 _resolve_static_call_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::resolve_static_call_C), "resolve_static_call");
96
97 address runtime_exception_handler;
98
99 if (ThreadLocalSafepoints) {
100 runtime_exception_handler = CAST_FROM_FN_PTR(address, SharedRuntime::thread_local_safepoint);
101 } else {
102 runtime_exception_handler = CAST_FROM_FN_PTR(address, SafepointSynchronize::handle_polling_page_exception);
103 }
104
105 #ifdef COMPILER2
106 // Vectors are generated only by C2.
107 if (is_wide_vector(MaxVectorSize)) {
108 _polling_page_vectors_safepoint_handler_blob = generate_handler_blob(runtime_exception_handler, POLL_AT_VECTOR_LOOP);
109 }
110 #endif // COMPILER2
111 _polling_page_safepoint_handler_blob = generate_handler_blob(runtime_exception_handler, POLL_AT_LOOP);
112 _polling_page_return_handler_blob = generate_handler_blob(runtime_exception_handler, POLL_AT_RETURN);
113
114 generate_deopt_blob();
115
116 #ifdef COMPILER2
117 generate_uncommon_trap_blob();
118 #endif // COMPILER2
119 }
120
121 void SharedRuntime::thread_local_safepoint(JavaThread *thread) {
122 thread->set_yieldpoint(false);
123 thread->update_serialized_memory_version();
124 if (SafepointSynchronize::is_synchronizing()) {
125 SafepointSynchronize::handle_polling_page_exception(thread);
126 }
127 }
128
129 #include <math.h>
130
131 // Implementation of SharedRuntime
132
133 #ifndef PRODUCT
134 // For statistics
135 int SharedRuntime::_ic_miss_ctr = 0;
136 int SharedRuntime::_wrong_method_ctr = 0;
137 int SharedRuntime::_resolve_static_ctr = 0;
138 int SharedRuntime::_resolve_virtual_ctr = 0;
139 int SharedRuntime::_resolve_opt_virtual_ctr = 0;
140 int SharedRuntime::_implicit_null_throws = 0;
141 int SharedRuntime::_implicit_div0_throws = 0;
142 int SharedRuntime::_throw_null_ctr = 0;
143
144 int SharedRuntime::_nof_normal_calls = 0;
145 int SharedRuntime::_nof_optimized_calls = 0;
146 int SharedRuntime::_nof_inlined_calls = 0;
147 int SharedRuntime::_nof_megamorphic_calls = 0;
148 int SharedRuntime::_nof_static_calls = 0;
195 _ICmiss_count[index] = 1;
196 }
197
198 void SharedRuntime::print_ic_miss_histogram() {
199 if (ICMissHistogram) {
200 tty->print_cr("IC Miss Histogram:");
201 int tot_misses = 0;
202 for (int i = 0; i < _ICmiss_index; i++) {
203 tty->print_cr(" at: " INTPTR_FORMAT " nof: %d", _ICmiss_at[i], _ICmiss_count[i]);
204 tot_misses += _ICmiss_count[i];
205 }
206 tty->print_cr("Total IC misses: %7d", tot_misses);
207 }
208 }
209 #endif // PRODUCT
210
211 #if INCLUDE_ALL_GCS
212
213 // G1 write-barrier pre: executed before a pointer store.
214 JRT_LEAF(void, SharedRuntime::g1_wb_pre(oopDesc* orig, JavaThread *thread))
215 thread->update_serialized_memory_version();
216 if (orig == NULL) {
217 assert(false, "should be optimized out");
218 return;
219 }
220 assert(orig->is_oop(true /* ignore mark word */), "Error");
221 // store the original value that was in the field reference
222 thread->satb_mark_queue().enqueue(orig);
223 JRT_END
224
225 // G1 write-barrier post: executed after a pointer store.
226 JRT_LEAF(void, SharedRuntime::g1_wb_post(void* card_addr, JavaThread* thread))
227 thread->update_serialized_memory_version();
228 thread->dirty_card_queue().enqueue(card_addr);
229 JRT_END
230
231 #endif // INCLUDE_ALL_GCS
232
233
234 JRT_LEAF(jlong, SharedRuntime::lmul(jlong y, jlong x))
235 return x * y;
236 JRT_END
237
238
239 JRT_LEAF(jlong, SharedRuntime::ldiv(jlong y, jlong x))
240 if (x == min_jlong && y == CONST64(-1)) {
241 return x;
242 } else {
243 return x / y;
244 }
245 JRT_END
246
247
521 tty->print_cr("a) exception happened in (new?) code stubs/buffers that is not handled here");
522 tty->print_cr("b) other problem");
523 }
524 #endif // PRODUCT
525
526 ShouldNotReachHere();
527 return NULL;
528 }
529
530
531 JRT_LEAF(address, SharedRuntime::exception_handler_for_return_address(JavaThread* thread, address return_address))
532 return raw_exception_handler_for_return_address(thread, return_address);
533 JRT_END
534
535
536 address SharedRuntime::get_poll_stub(address pc) {
537 address stub;
538 // Look up the code blob
539 CodeBlob *cb = CodeCache::find_blob(pc);
540
541 assert(((NativeInstruction*)pc)->is_safepoint_poll(),
542 "Only polling locations are used for safepoint");
543
544 bool at_poll_return = ((nmethod*)cb)->is_at_poll_return(pc);
545 bool has_wide_vectors = ((nmethod*)cb)->has_wide_vectors();
546 if (at_poll_return) {
547 assert(SharedRuntime::polling_page_return_handler_blob() != NULL,
548 "polling page return stub not created yet");
549 stub = SharedRuntime::polling_page_return_handler_blob()->entry_point();
550 } else if (has_wide_vectors) {
551 assert(SharedRuntime::polling_page_vectors_safepoint_handler_blob() != NULL,
552 "polling page vectors safepoint stub not created yet");
553 stub = SharedRuntime::polling_page_vectors_safepoint_handler_blob()->entry_point();
554 } else {
555 assert(SharedRuntime::polling_page_safepoint_handler_blob() != NULL,
556 "polling page safepoint stub not created yet");
557 stub = SharedRuntime::polling_page_safepoint_handler_blob()->entry_point();
558 }
559 #ifndef PRODUCT
560 if (TraceSafepoint) {
|