Mercurial > hg > graal-compiler
annotate src/os_cpu/linux_zero/vm/os_linux_zero.cpp @ 2011:dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
Reviewed-by: twisti
author | jrose |
---|---|
date | Fri, 03 Dec 2010 15:53:57 -0800 |
parents | f95d63e2154a |
children | 828eafbd85cc |
rev | line source |
---|---|
1010 | 1 /* |
1972 | 2 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. |
1176
d11ce1551e8d
6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents:
1010
diff
changeset
|
3 * Copyright 2007, 2008, 2009, 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:
1522
diff
changeset
|
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1522
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:
1522
diff
changeset
|
22 * questions. |
1010 | 23 * |
24 */ | |
25 | |
1972 | 26 // no precompiled headers |
27 #include "assembler_zero.inline.hpp" | |
28 #include "classfile/classLoader.hpp" | |
29 #include "classfile/systemDictionary.hpp" | |
30 #include "classfile/vmSymbols.hpp" | |
31 #include "code/icBuffer.hpp" | |
32 #include "code/vtableStubs.hpp" | |
33 #include "interpreter/interpreter.hpp" | |
34 #include "jvm_linux.h" | |
35 #include "memory/allocation.inline.hpp" | |
36 #include "mutex_linux.inline.hpp" | |
37 #include "nativeInst_zero.hpp" | |
38 #include "os_share_linux.hpp" | |
39 #include "prims/jniFastGetField.hpp" | |
40 #include "prims/jvm.h" | |
41 #include "prims/jvm_misc.hpp" | |
42 #include "runtime/arguments.hpp" | |
43 #include "runtime/extendedPC.hpp" | |
44 #include "runtime/frame.inline.hpp" | |
45 #include "runtime/hpi.hpp" | |
46 #include "runtime/interfaceSupport.hpp" | |
47 #include "runtime/java.hpp" | |
48 #include "runtime/javaCalls.hpp" | |
49 #include "runtime/mutexLocker.hpp" | |
50 #include "runtime/osThread.hpp" | |
51 #include "runtime/sharedRuntime.hpp" | |
52 #include "runtime/stubRoutines.hpp" | |
53 #include "runtime/timer.hpp" | |
54 #include "thread_linux.inline.hpp" | |
55 #include "utilities/events.hpp" | |
56 #include "utilities/vmError.hpp" | |
57 #ifdef COMPILER1 | |
58 #include "c1/c1_Runtime1.hpp" | |
59 #endif | |
60 #ifdef COMPILER2 | |
61 #include "opto/runtime.hpp" | |
62 #endif | |
1010 | 63 |
64 address os::current_stack_pointer() { | |
65 address dummy = (address) &dummy; | |
66 return dummy; | |
67 } | |
68 | |
69 frame os::get_sender_for_C_frame(frame* fr) { | |
70 ShouldNotCallThis(); | |
71 } | |
72 | |
73 frame os::current_frame() { | |
74 // The only thing that calls this is the stack printing code in | |
75 // VMError::report: | |
76 // - Step 110 (printing stack bounds) uses the sp in the frame | |
77 // to determine the amount of free space on the stack. We | |
78 // set the sp to a close approximation of the real value in | |
79 // order to allow this step to complete. | |
80 // - Step 120 (printing native stack) tries to walk the stack. | |
81 // The frame we create has a NULL pc, which is ignored as an | |
82 // invalid frame. | |
83 frame dummy = frame(); | |
84 dummy.set_sp((intptr_t *) current_stack_pointer()); | |
85 return dummy; | |
86 } | |
87 | |
88 char* os::non_memory_address_word() { | |
89 // Must never look like an address returned by reserve_memory, | |
90 // even in its subfields (as defined by the CPU immediate fields, | |
91 // if the CPU splits constants across multiple instructions). | |
92 #ifdef SPARC | |
93 // On SPARC, 0 != %hi(any real address), because there is no | |
94 // allocation in the first 1Kb of the virtual address space. | |
95 return (char *) 0; | |
96 #else | |
97 // This is the value for x86; works pretty well for PPC too. | |
98 return (char *) -1; | |
99 #endif // SPARC | |
100 } | |
101 | |
102 void os::initialize_thread() { | |
103 // Nothing to do. | |
104 } | |
105 | |
106 address os::Linux::ucontext_get_pc(ucontext_t* uc) { | |
107 ShouldNotCallThis(); | |
108 } | |
109 | |
110 ExtendedPC os::fetch_frame_from_context(void* ucVoid, | |
111 intptr_t** ret_sp, | |
112 intptr_t** ret_fp) { | |
113 ShouldNotCallThis(); | |
114 } | |
115 | |
116 frame os::fetch_frame_from_context(void* ucVoid) { | |
117 ShouldNotCallThis(); | |
118 } | |
119 | |
120 extern "C" int | |
121 JVM_handle_linux_signal(int sig, | |
122 siginfo_t* info, | |
123 void* ucVoid, | |
124 int abort_if_unrecognized) { | |
125 ucontext_t* uc = (ucontext_t*) ucVoid; | |
126 | |
127 Thread* t = ThreadLocalStorage::get_thread_slow(); | |
128 | |
129 SignalHandlerMark shm(t); | |
130 | |
131 // Note: it's not uncommon that JNI code uses signal/sigset to | |
132 // install then restore certain signal handler (e.g. to temporarily | |
133 // block SIGPIPE, or have a SIGILL handler when detecting CPU | |
134 // type). When that happens, JVM_handle_linux_signal() might be | |
135 // invoked with junk info/ucVoid. To avoid unnecessary crash when | |
136 // libjsig is not preloaded, try handle signals that do not require | |
137 // siginfo/ucontext first. | |
138 | |
139 if (sig == SIGPIPE || sig == SIGXFSZ) { | |
140 // allow chained handler to go first | |
141 if (os::Linux::chained_handler(sig, info, ucVoid)) { | |
142 return true; | |
143 } else { | |
144 if (PrintMiscellaneous && (WizardMode || Verbose)) { | |
145 char buf[64]; | |
146 warning("Ignoring %s - see bugs 4229104 or 646499219", | |
147 os::exception_name(sig, buf, sizeof(buf))); | |
148 } | |
149 return true; | |
150 } | |
151 } | |
152 | |
153 JavaThread* thread = NULL; | |
154 VMThread* vmthread = NULL; | |
155 if (os::Linux::signal_handlers_are_installed) { | |
156 if (t != NULL ){ | |
157 if(t->is_Java_thread()) { | |
158 thread = (JavaThread*)t; | |
159 } | |
160 else if(t->is_VM_thread()){ | |
161 vmthread = (VMThread *)t; | |
162 } | |
163 } | |
164 } | |
165 | |
166 if (info != NULL && thread != NULL) { | |
167 // Handle ALL stack overflow variations here | |
168 if (sig == SIGSEGV) { | |
169 address addr = (address) info->si_addr; | |
170 | |
171 // check if fault address is within thread stack | |
172 if (addr < thread->stack_base() && | |
173 addr >= thread->stack_base() - thread->stack_size()) { | |
174 // stack overflow | |
175 if (thread->in_stack_yellow_zone(addr)) { | |
176 thread->disable_stack_yellow_zone(); | |
177 ShouldNotCallThis(); | |
178 } | |
179 else if (thread->in_stack_red_zone(addr)) { | |
180 thread->disable_stack_red_zone(); | |
181 ShouldNotCallThis(); | |
182 } | |
183 else { | |
184 // Accessing stack address below sp may cause SEGV if | |
185 // current thread has MAP_GROWSDOWN stack. This should | |
186 // only happen when current thread was created by user | |
187 // code with MAP_GROWSDOWN flag and then attached to VM. | |
188 // See notes in os_linux.cpp. | |
189 if (thread->osthread()->expanding_stack() == 0) { | |
190 thread->osthread()->set_expanding_stack(); | |
191 if (os::Linux::manually_expand_stack(thread, addr)) { | |
192 thread->osthread()->clear_expanding_stack(); | |
193 return true; | |
194 } | |
195 thread->osthread()->clear_expanding_stack(); | |
196 } | |
197 else { | |
198 fatal("recursive segv. expanding stack."); | |
199 } | |
200 } | |
201 } | |
202 } | |
203 | |
204 /*if (thread->thread_state() == _thread_in_Java) { | |
205 ShouldNotCallThis(); | |
206 } | |
207 else*/ if (thread->thread_state() == _thread_in_vm && | |
208 sig == SIGBUS && thread->doing_unsafe_access()) { | |
209 ShouldNotCallThis(); | |
210 } | |
211 | |
212 // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC | |
213 // kicks in and the heap gets shrunk before the field access. | |
214 /*if (sig == SIGSEGV || sig == SIGBUS) { | |
215 address addr = JNI_FastGetField::find_slowcase_pc(pc); | |
216 if (addr != (address)-1) { | |
217 stub = addr; | |
218 } | |
219 }*/ | |
220 | |
221 // Check to see if we caught the safepoint code in the process | |
222 // of write protecting the memory serialization page. It write | |
223 // enables the page immediately after protecting it so we can | |
224 // just return to retry the write. | |
225 if (sig == SIGSEGV && | |
226 os::is_memory_serialize_page(thread, (address) info->si_addr)) { | |
227 // Block current thread until permission is restored. | |
228 os::block_on_serialize_page_trap(); | |
229 return true; | |
230 } | |
231 } | |
232 | |
233 // signal-chaining | |
234 if (os::Linux::chained_handler(sig, info, ucVoid)) { | |
235 return true; | |
236 } | |
237 | |
238 if (!abort_if_unrecognized) { | |
239 // caller wants another chance, so give it to him | |
240 return false; | |
241 } | |
242 | |
243 #ifndef PRODUCT | |
244 if (sig == SIGSEGV) { | |
245 fatal("\n#" | |
246 "\n# /--------------------\\" | |
247 "\n# | segmentation fault |" | |
248 "\n# \\---\\ /--------------/" | |
249 "\n# /" | |
250 "\n# [-] |\\_/| " | |
251 "\n# (+)=C |o o|__ " | |
252 "\n# | | =-*-=__\\ " | |
253 "\n# OOO c_c_(___)"); | |
254 } | |
255 #endif // !PRODUCT | |
256 | |
257 const char *fmt = "caught unhandled signal %d"; | |
258 char buf[64]; | |
259 | |
260 sprintf(buf, fmt, sig); | |
261 fatal(buf); | |
262 } | |
263 | |
264 void os::Linux::init_thread_fpu_state(void) { | |
265 // Nothing to do | |
266 } | |
267 | |
268 int os::Linux::get_fpu_control_word() { | |
269 ShouldNotCallThis(); | |
270 } | |
271 | |
272 void os::Linux::set_fpu_control_word(int fpu) { | |
273 ShouldNotCallThis(); | |
274 } | |
275 | |
276 bool os::is_allocatable(size_t bytes) { | |
1176
d11ce1551e8d
6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents:
1010
diff
changeset
|
277 #ifdef _LP64 |
d11ce1551e8d
6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents:
1010
diff
changeset
|
278 return true; |
d11ce1551e8d
6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents:
1010
diff
changeset
|
279 #else |
d11ce1551e8d
6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents:
1010
diff
changeset
|
280 if (bytes < 2 * G) { |
d11ce1551e8d
6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents:
1010
diff
changeset
|
281 return true; |
d11ce1551e8d
6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents:
1010
diff
changeset
|
282 } |
d11ce1551e8d
6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents:
1010
diff
changeset
|
283 |
d11ce1551e8d
6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents:
1010
diff
changeset
|
284 char* addr = reserve_memory(bytes, NULL); |
d11ce1551e8d
6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents:
1010
diff
changeset
|
285 |
d11ce1551e8d
6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents:
1010
diff
changeset
|
286 if (addr != NULL) { |
d11ce1551e8d
6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents:
1010
diff
changeset
|
287 release_memory(addr, bytes); |
d11ce1551e8d
6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents:
1010
diff
changeset
|
288 } |
d11ce1551e8d
6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents:
1010
diff
changeset
|
289 |
d11ce1551e8d
6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents:
1010
diff
changeset
|
290 return addr != NULL; |
d11ce1551e8d
6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents:
1010
diff
changeset
|
291 #endif // _LP64 |
1010 | 292 } |
293 | |
294 /////////////////////////////////////////////////////////////////////////////// | |
295 // thread stack | |
296 | |
297 size_t os::Linux::min_stack_allowed = 64 * K; | |
298 | |
299 bool os::Linux::supports_variable_stack_size() { | |
300 return true; | |
301 } | |
302 | |
303 size_t os::Linux::default_stack_size(os::ThreadType thr_type) { | |
304 #ifdef _LP64 | |
305 size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M); | |
306 #else | |
307 size_t s = (thr_type == os::compiler_thread ? 2 * M : 512 * K); | |
308 #endif // _LP64 | |
309 return s; | |
310 } | |
311 | |
312 size_t os::Linux::default_guard_size(os::ThreadType thr_type) { | |
313 // Only enable glibc guard pages for non-Java threads | |
314 // (Java threads have HotSpot guard pages) | |
315 return (thr_type == java_thread ? 0 : page_size()); | |
316 } | |
317 | |
318 static void current_stack_region(address *bottom, size_t *size) { | |
319 pthread_attr_t attr; | |
320 int res = pthread_getattr_np(pthread_self(), &attr); | |
321 if (res != 0) { | |
322 if (res == ENOMEM) { | |
323 vm_exit_out_of_memory(0, "pthread_getattr_np"); | |
324 } | |
325 else { | |
1522
67d74f7a15d9
6951923: some uses of fatal1 were missed by 6888954
jcoomes
parents:
1176
diff
changeset
|
326 fatal(err_msg("pthread_getattr_np failed with errno = %d", res)); |
1010 | 327 } |
328 } | |
329 | |
330 address stack_bottom; | |
331 size_t stack_bytes; | |
332 res = pthread_attr_getstack(&attr, (void **) &stack_bottom, &stack_bytes); | |
333 if (res != 0) { | |
1522
67d74f7a15d9
6951923: some uses of fatal1 were missed by 6888954
jcoomes
parents:
1176
diff
changeset
|
334 fatal(err_msg("pthread_attr_getstack failed with errno = %d", res)); |
1010 | 335 } |
336 address stack_top = stack_bottom + stack_bytes; | |
337 | |
338 // The block of memory returned by pthread_attr_getstack() includes | |
339 // guard pages where present. We need to trim these off. | |
340 size_t page_bytes = os::Linux::page_size(); | |
341 assert(((intptr_t) stack_bottom & (page_bytes - 1)) == 0, "unaligned stack"); | |
342 | |
343 size_t guard_bytes; | |
344 res = pthread_attr_getguardsize(&attr, &guard_bytes); | |
345 if (res != 0) { | |
1522
67d74f7a15d9
6951923: some uses of fatal1 were missed by 6888954
jcoomes
parents:
1176
diff
changeset
|
346 fatal(err_msg("pthread_attr_getguardsize failed with errno = %d", res)); |
1010 | 347 } |
348 int guard_pages = align_size_up(guard_bytes, page_bytes) / page_bytes; | |
349 assert(guard_bytes == guard_pages * page_bytes, "unaligned guard"); | |
350 | |
351 #ifdef IA64 | |
352 // IA64 has two stacks sharing the same area of memory, a normal | |
353 // stack growing downwards and a register stack growing upwards. | |
354 // Guard pages, if present, are in the centre. This code splits | |
355 // the stack in two even without guard pages, though in theory | |
356 // there's nothing to stop us allocating more to the normal stack | |
357 // or more to the register stack if one or the other were found | |
358 // to grow faster. | |
359 int total_pages = align_size_down(stack_bytes, page_bytes) / page_bytes; | |
360 stack_bottom += (total_pages - guard_pages) / 2 * page_bytes; | |
361 #endif // IA64 | |
362 | |
363 stack_bottom += guard_bytes; | |
364 | |
365 pthread_attr_destroy(&attr); | |
366 | |
367 // The initial thread has a growable stack, and the size reported | |
368 // by pthread_attr_getstack is the maximum size it could possibly | |
369 // be given what currently mapped. This can be huge, so we cap it. | |
370 if (os::Linux::is_initial_thread()) { | |
371 stack_bytes = stack_top - stack_bottom; | |
372 | |
373 if (stack_bytes > JavaThread::stack_size_at_create()) | |
374 stack_bytes = JavaThread::stack_size_at_create(); | |
375 | |
376 stack_bottom = stack_top - stack_bytes; | |
377 } | |
378 | |
379 assert(os::current_stack_pointer() >= stack_bottom, "should do"); | |
380 assert(os::current_stack_pointer() < stack_top, "should do"); | |
381 | |
382 *bottom = stack_bottom; | |
383 *size = stack_top - stack_bottom; | |
384 } | |
385 | |
386 address os::current_stack_base() { | |
387 address bottom; | |
388 size_t size; | |
389 current_stack_region(&bottom, &size); | |
390 return bottom + size; | |
391 } | |
392 | |
393 size_t os::current_stack_size() { | |
394 // stack size includes normal stack and HotSpot guard pages | |
395 address bottom; | |
396 size_t size; | |
397 current_stack_region(&bottom, &size); | |
398 return size; | |
399 } | |
400 | |
401 ///////////////////////////////////////////////////////////////////////////// | |
402 // helper functions for fatal error handler | |
403 | |
404 void os::print_context(outputStream* st, void* context) { | |
405 ShouldNotCallThis(); | |
406 } | |
407 | |
1970 | 408 void os::print_register_info(outputStream *st, void *context) { |
409 ShouldNotCallThis(); | |
410 } | |
411 | |
1010 | 412 ///////////////////////////////////////////////////////////////////////////// |
413 // Stubs for things that would be in linux_zero.s if it existed. | |
414 // You probably want to disassemble these monkeys to check they're ok. | |
415 | |
416 extern "C" { | |
417 int SpinPause() { | |
418 } | |
419 | |
420 int SafeFetch32(int *adr, int errValue) { | |
421 int value = errValue; | |
422 value = *adr; | |
423 return value; | |
424 } | |
425 intptr_t SafeFetchN(intptr_t *adr, intptr_t errValue) { | |
426 intptr_t value = errValue; | |
427 value = *adr; | |
428 return value; | |
429 } | |
430 | |
431 void _Copy_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) { | |
432 if (from > to) { | |
433 jshort *end = from + count; | |
434 while (from < end) | |
435 *(to++) = *(from++); | |
436 } | |
437 else if (from < to) { | |
438 jshort *end = from; | |
439 from += count - 1; | |
440 to += count - 1; | |
441 while (from >= end) | |
442 *(to--) = *(from--); | |
443 } | |
444 } | |
445 void _Copy_conjoint_jints_atomic(jint* from, jint* to, size_t count) { | |
446 if (from > to) { | |
447 jint *end = from + count; | |
448 while (from < end) | |
449 *(to++) = *(from++); | |
450 } | |
451 else if (from < to) { | |
452 jint *end = from; | |
453 from += count - 1; | |
454 to += count - 1; | |
455 while (from >= end) | |
456 *(to--) = *(from--); | |
457 } | |
458 } | |
459 void _Copy_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) { | |
460 if (from > to) { | |
461 jlong *end = from + count; | |
462 while (from < end) | |
463 os::atomic_copy64(from++, to++); | |
464 } | |
465 else if (from < to) { | |
466 jlong *end = from; | |
467 from += count - 1; | |
468 to += count - 1; | |
469 while (from >= end) | |
470 os::atomic_copy64(from--, to--); | |
471 } | |
472 } | |
473 | |
474 void _Copy_arrayof_conjoint_bytes(HeapWord* from, | |
475 HeapWord* to, | |
476 size_t count) { | |
1729 | 477 memmove(to, from, count); |
1010 | 478 } |
479 void _Copy_arrayof_conjoint_jshorts(HeapWord* from, | |
480 HeapWord* to, | |
481 size_t count) { | |
1729 | 482 memmove(to, from, count * 2); |
1010 | 483 } |
484 void _Copy_arrayof_conjoint_jints(HeapWord* from, | |
485 HeapWord* to, | |
486 size_t count) { | |
1729 | 487 memmove(to, from, count * 4); |
1010 | 488 } |
489 void _Copy_arrayof_conjoint_jlongs(HeapWord* from, | |
490 HeapWord* to, | |
491 size_t count) { | |
1729 | 492 memmove(to, from, count * 8); |
1010 | 493 } |
494 }; | |
495 | |
496 ///////////////////////////////////////////////////////////////////////////// | |
497 // Implementations of atomic operations not supported by processors. | |
498 // -- http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Atomic-Builtins.html | |
499 | |
500 #ifndef _LP64 | |
501 extern "C" { | |
502 long long unsigned int __sync_val_compare_and_swap_8( | |
503 volatile void *ptr, | |
504 long long unsigned int oldval, | |
505 long long unsigned int newval) { | |
506 ShouldNotCallThis(); | |
507 } | |
508 }; | |
509 #endif // !_LP64 |