402 }
403
404 // Load java dll
405 if (dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(),
406 "java")) {
407 _native_java_library = dll_load(buffer, ebuf, sizeof(ebuf));
408 }
409 if (_native_java_library == NULL) {
410 vm_exit_during_initialization("Unable to load native library", ebuf);
411 }
412
413 #if defined(__OpenBSD__)
414 // Work-around OpenBSD's lack of $ORIGIN support by pre-loading libnet.so
415 // ignore errors
416 if (dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(),
417 "net")) {
418 dll_load(buffer, ebuf, sizeof(ebuf));
419 }
420 #endif
421 }
422 static jboolean onLoaded = JNI_FALSE;
423 if (onLoaded) {
424 // We may have to wait to fire OnLoad until TLS is initialized.
425 if (ThreadLocalStorage::is_initialized()) {
426 // The JNI_OnLoad handling is normally done by method load in
427 // java.lang.ClassLoader$NativeLibrary, but the VM loads the base library
428 // explicitly so we have to check for JNI_OnLoad as well
429 const char *onLoadSymbols[] = JNI_ONLOAD_SYMBOLS;
430 JNI_OnLoad_t JNI_OnLoad = CAST_TO_FN_PTR(
431 JNI_OnLoad_t, dll_lookup(_native_java_library, onLoadSymbols[0]));
432 if (JNI_OnLoad != NULL) {
433 JavaThread* thread = JavaThread::current();
434 ThreadToNativeFromVM ttn(thread);
435 HandleMark hm(thread);
436 jint ver = (*JNI_OnLoad)(&main_vm, NULL);
437 onLoaded = JNI_TRUE;
438 if (!Threads::is_supported_jni_version_including_1_1(ver)) {
439 vm_exit_during_initialization("Unsupported JNI version");
440 }
441 }
442 }
443 }
444 return _native_java_library;
445 }
446
447 /*
448 * Support for finding Agent_On(Un)Load/Attach<_lib_name> if it exists.
449 * If check_lib == true then we are looking for an
450 * Agent_OnLoad_lib_name or Agent_OnAttach_lib_name function to determine if
451 * this library is statically linked into the image.
452 * If check_lib == false then we will look for the appropriate symbol in the
453 * executable if agent_lib->is_static_lib() == true or in the shared library
454 * referenced by 'handle'.
455 */
456 void* os::find_agent_function(AgentLibrary *agent_lib, bool check_lib,
457 const char *syms[], size_t syms_len) {
458 assert(agent_lib != NULL, "sanity check");
459 const char *lib_name;
460 void *handle = agent_lib->os_lib();
461 void *entryName = NULL;
462 char *agent_function_name;
463 size_t i;
556 }
557 return false;
558 }
559
560 void* os::malloc(size_t size, MEMFLAGS flags) {
561 return os::malloc(size, flags, CALLER_PC);
562 }
563
564 void* os::malloc(size_t size, MEMFLAGS memflags, const NativeCallStack& stack) {
565 NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1));
566 NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size));
567
568 #ifdef ASSERT
569 // checking for the WatcherThread and crash_protection first
570 // since os::malloc can be called when the libjvm.{dll,so} is
571 // first loaded and we don't have a thread yet.
572 // try to find the thread after we see that the watcher thread
573 // exists and has crash protection.
574 WatcherThread *wt = WatcherThread::watcher_thread();
575 if (wt != NULL && wt->has_crash_protection()) {
576 Thread* thread = ThreadLocalStorage::get_thread_slow();
577 if (thread == wt) {
578 assert(!wt->has_crash_protection(),
579 "Can't malloc with crash protection from WatcherThread");
580 }
581 }
582 #endif
583
584 if (size == 0) {
585 // return a valid pointer if size is zero
586 // if NULL is returned the calling functions assume out of memory.
587 size = 1;
588 }
589
590 // NMT support
591 NMT_TrackingLevel level = MemTracker::tracking_level();
592 size_t nmt_header_size = MemTracker::malloc_header_size(level);
593
594 #ifndef ASSERT
595 const size_t alloc_size = size + nmt_header_size;
596 #else
|
402 }
403
404 // Load java dll
405 if (dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(),
406 "java")) {
407 _native_java_library = dll_load(buffer, ebuf, sizeof(ebuf));
408 }
409 if (_native_java_library == NULL) {
410 vm_exit_during_initialization("Unable to load native library", ebuf);
411 }
412
413 #if defined(__OpenBSD__)
414 // Work-around OpenBSD's lack of $ORIGIN support by pre-loading libnet.so
415 // ignore errors
416 if (dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(),
417 "net")) {
418 dll_load(buffer, ebuf, sizeof(ebuf));
419 }
420 #endif
421 }
422 return _native_java_library;
423 }
424
425 /*
426 * Support for finding Agent_On(Un)Load/Attach<_lib_name> if it exists.
427 * If check_lib == true then we are looking for an
428 * Agent_OnLoad_lib_name or Agent_OnAttach_lib_name function to determine if
429 * this library is statically linked into the image.
430 * If check_lib == false then we will look for the appropriate symbol in the
431 * executable if agent_lib->is_static_lib() == true or in the shared library
432 * referenced by 'handle'.
433 */
434 void* os::find_agent_function(AgentLibrary *agent_lib, bool check_lib,
435 const char *syms[], size_t syms_len) {
436 assert(agent_lib != NULL, "sanity check");
437 const char *lib_name;
438 void *handle = agent_lib->os_lib();
439 void *entryName = NULL;
440 char *agent_function_name;
441 size_t i;
534 }
535 return false;
536 }
537
538 void* os::malloc(size_t size, MEMFLAGS flags) {
539 return os::malloc(size, flags, CALLER_PC);
540 }
541
542 void* os::malloc(size_t size, MEMFLAGS memflags, const NativeCallStack& stack) {
543 NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1));
544 NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size));
545
546 #ifdef ASSERT
547 // checking for the WatcherThread and crash_protection first
548 // since os::malloc can be called when the libjvm.{dll,so} is
549 // first loaded and we don't have a thread yet.
550 // try to find the thread after we see that the watcher thread
551 // exists and has crash protection.
552 WatcherThread *wt = WatcherThread::watcher_thread();
553 if (wt != NULL && wt->has_crash_protection()) {
554 Thread* thread = Thread::current();
555 if (thread == wt) {
556 assert(!wt->has_crash_protection(),
557 "Can't malloc with crash protection from WatcherThread");
558 }
559 }
560 #endif
561
562 if (size == 0) {
563 // return a valid pointer if size is zero
564 // if NULL is returned the calling functions assume out of memory.
565 size = 1;
566 }
567
568 // NMT support
569 NMT_TrackingLevel level = MemTracker::tracking_level();
570 size_t nmt_header_size = MemTracker::malloc_header_size(level);
571
572 #ifndef ASSERT
573 const size_t alloc_size = size + nmt_header_size;
574 #else
|