43 #include "runtime/javaCalls.hpp"
44 #include "runtime/mutexLocker.hpp"
45 #include "runtime/os.hpp"
46 #include "runtime/stubRoutines.hpp"
47 #include "services/attachListener.hpp"
48 #include "services/threadService.hpp"
49 #include "utilities/defaultStream.hpp"
50 #include "utilities/events.hpp"
51 #ifdef TARGET_OS_FAMILY_linux
52 # include "os_linux.inline.hpp"
53 # include "thread_linux.inline.hpp"
54 #endif
55 #ifdef TARGET_OS_FAMILY_solaris
56 # include "os_solaris.inline.hpp"
57 # include "thread_solaris.inline.hpp"
58 #endif
59 #ifdef TARGET_OS_FAMILY_windows
60 # include "os_windows.inline.hpp"
61 # include "thread_windows.inline.hpp"
62 #endif
63
64 # include <signal.h>
65
66 OSThread* os::_starting_thread = NULL;
67 address os::_polling_page = NULL;
68 volatile int32_t* os::_mem_serialize_page = NULL;
69 uintptr_t os::_serialize_page_mask = 0;
70 long os::_rand_seed = 1;
71 int os::_processor_count = 0;
72 size_t os::_page_sizes[os::page_sizes_max];
73
74 #ifndef PRODUCT
75 julong os::num_mallocs = 0; // # of calls to malloc/realloc
76 julong os::alloc_bytes = 0; // # of bytes allocated
77 julong os::num_frees = 0; // # of calls to free
78 julong os::free_bytes = 0; // # of bytes freed
79 #endif
80
81 // Fill in buffer with current local time as an ISO-8601 string.
82 // E.g., yyyy-mm-ddThh:mm:ss-zzzz.
99 assert(false, "NULL buffer");
100 return NULL;
101 }
102 if (buffer_length < needed_buffer) {
103 assert(false, "buffer_length too small");
104 return NULL;
105 }
106 // Get the current time
107 jlong milliseconds_since_19700101 = javaTimeMillis();
108 const int milliseconds_per_microsecond = 1000;
109 const time_t seconds_since_19700101 =
110 milliseconds_since_19700101 / milliseconds_per_microsecond;
111 const int milliseconds_after_second =
112 milliseconds_since_19700101 % milliseconds_per_microsecond;
113 // Convert the time value to a tm and timezone variable
114 struct tm time_struct;
115 if (localtime_pd(&seconds_since_19700101, &time_struct) == NULL) {
116 assert(false, "Failed localtime_pd");
117 return NULL;
118 }
119 const time_t zone = timezone;
120
121 // If daylight savings time is in effect,
122 // we are 1 hour East of our time zone
123 const time_t seconds_per_minute = 60;
124 const time_t minutes_per_hour = 60;
125 const time_t seconds_per_hour = seconds_per_minute * minutes_per_hour;
126 time_t UTC_to_local = zone;
127 if (time_struct.tm_isdst > 0) {
128 UTC_to_local = UTC_to_local - seconds_per_hour;
129 }
130 // Compute the time zone offset.
131 // localtime_pd() sets timezone to the difference (in seconds)
132 // between UTC and and local time.
133 // ISO 8601 says we need the difference between local time and UTC,
134 // we change the sign of the localtime_pd() result.
135 const time_t local_to_UTC = -(UTC_to_local);
136 // Then we have to figure out if if we are ahead (+) or behind (-) UTC.
137 char sign_local_to_UTC = '+';
138 time_t abs_local_to_UTC = local_to_UTC;
139 if (local_to_UTC < 0) {
367
368 static void* _native_java_library = NULL;
369
370 void* os::native_java_library() {
371 if (_native_java_library == NULL) {
372 char buffer[JVM_MAXPATHLEN];
373 char ebuf[1024];
374
375 // Try to load verify dll first. In 1.3 java dll depends on it and is not
376 // always able to find it when the loading executable is outside the JDK.
377 // In order to keep working with 1.2 we ignore any loading errors.
378 dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(), "verify");
379 dll_load(buffer, ebuf, sizeof(ebuf));
380
381 // Load java dll
382 dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(), "java");
383 _native_java_library = dll_load(buffer, ebuf, sizeof(ebuf));
384 if (_native_java_library == NULL) {
385 vm_exit_during_initialization("Unable to load native library", ebuf);
386 }
387 }
388 static jboolean onLoaded = JNI_FALSE;
389 if (onLoaded) {
390 // We may have to wait to fire OnLoad until TLS is initialized.
391 if (ThreadLocalStorage::is_initialized()) {
392 // The JNI_OnLoad handling is normally done by method load in
393 // java.lang.ClassLoader$NativeLibrary, but the VM loads the base library
394 // explicitly so we have to check for JNI_OnLoad as well
395 const char *onLoadSymbols[] = JNI_ONLOAD_SYMBOLS;
396 JNI_OnLoad_t JNI_OnLoad = CAST_TO_FN_PTR(
397 JNI_OnLoad_t, dll_lookup(_native_java_library, onLoadSymbols[0]));
398 if (JNI_OnLoad != NULL) {
399 JavaThread* thread = JavaThread::current();
400 ThreadToNativeFromVM ttn(thread);
401 HandleMark hm(thread);
402 jint ver = (*JNI_OnLoad)(&main_vm, NULL);
403 onLoaded = JNI_TRUE;
404 if (!Threads::is_supported_jni_version_including_1_1(ver)) {
405 vm_exit_during_initialization("Unsupported JNI version");
406 }
|
43 #include "runtime/javaCalls.hpp"
44 #include "runtime/mutexLocker.hpp"
45 #include "runtime/os.hpp"
46 #include "runtime/stubRoutines.hpp"
47 #include "services/attachListener.hpp"
48 #include "services/threadService.hpp"
49 #include "utilities/defaultStream.hpp"
50 #include "utilities/events.hpp"
51 #ifdef TARGET_OS_FAMILY_linux
52 # include "os_linux.inline.hpp"
53 # include "thread_linux.inline.hpp"
54 #endif
55 #ifdef TARGET_OS_FAMILY_solaris
56 # include "os_solaris.inline.hpp"
57 # include "thread_solaris.inline.hpp"
58 #endif
59 #ifdef TARGET_OS_FAMILY_windows
60 # include "os_windows.inline.hpp"
61 # include "thread_windows.inline.hpp"
62 #endif
63 #ifdef TARGET_OS_FAMILY_bsd
64 # include "os_bsd.inline.hpp"
65 # include "thread_bsd.inline.hpp"
66 #endif
67
68 # include <signal.h>
69
70 OSThread* os::_starting_thread = NULL;
71 address os::_polling_page = NULL;
72 volatile int32_t* os::_mem_serialize_page = NULL;
73 uintptr_t os::_serialize_page_mask = 0;
74 long os::_rand_seed = 1;
75 int os::_processor_count = 0;
76 size_t os::_page_sizes[os::page_sizes_max];
77
78 #ifndef PRODUCT
79 julong os::num_mallocs = 0; // # of calls to malloc/realloc
80 julong os::alloc_bytes = 0; // # of bytes allocated
81 julong os::num_frees = 0; // # of calls to free
82 julong os::free_bytes = 0; // # of bytes freed
83 #endif
84
85 // Fill in buffer with current local time as an ISO-8601 string.
86 // E.g., yyyy-mm-ddThh:mm:ss-zzzz.
103 assert(false, "NULL buffer");
104 return NULL;
105 }
106 if (buffer_length < needed_buffer) {
107 assert(false, "buffer_length too small");
108 return NULL;
109 }
110 // Get the current time
111 jlong milliseconds_since_19700101 = javaTimeMillis();
112 const int milliseconds_per_microsecond = 1000;
113 const time_t seconds_since_19700101 =
114 milliseconds_since_19700101 / milliseconds_per_microsecond;
115 const int milliseconds_after_second =
116 milliseconds_since_19700101 % milliseconds_per_microsecond;
117 // Convert the time value to a tm and timezone variable
118 struct tm time_struct;
119 if (localtime_pd(&seconds_since_19700101, &time_struct) == NULL) {
120 assert(false, "Failed localtime_pd");
121 return NULL;
122 }
123 #if defined(_ALLBSD_SOURCE)
124 const time_t zone = (time_t) time_struct.tm_gmtoff;
125 #else
126 const time_t zone = timezone;
127 #endif
128
129 // If daylight savings time is in effect,
130 // we are 1 hour East of our time zone
131 const time_t seconds_per_minute = 60;
132 const time_t minutes_per_hour = 60;
133 const time_t seconds_per_hour = seconds_per_minute * minutes_per_hour;
134 time_t UTC_to_local = zone;
135 if (time_struct.tm_isdst > 0) {
136 UTC_to_local = UTC_to_local - seconds_per_hour;
137 }
138 // Compute the time zone offset.
139 // localtime_pd() sets timezone to the difference (in seconds)
140 // between UTC and and local time.
141 // ISO 8601 says we need the difference between local time and UTC,
142 // we change the sign of the localtime_pd() result.
143 const time_t local_to_UTC = -(UTC_to_local);
144 // Then we have to figure out if if we are ahead (+) or behind (-) UTC.
145 char sign_local_to_UTC = '+';
146 time_t abs_local_to_UTC = local_to_UTC;
147 if (local_to_UTC < 0) {
375
376 static void* _native_java_library = NULL;
377
378 void* os::native_java_library() {
379 if (_native_java_library == NULL) {
380 char buffer[JVM_MAXPATHLEN];
381 char ebuf[1024];
382
383 // Try to load verify dll first. In 1.3 java dll depends on it and is not
384 // always able to find it when the loading executable is outside the JDK.
385 // In order to keep working with 1.2 we ignore any loading errors.
386 dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(), "verify");
387 dll_load(buffer, ebuf, sizeof(ebuf));
388
389 // Load java dll
390 dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(), "java");
391 _native_java_library = dll_load(buffer, ebuf, sizeof(ebuf));
392 if (_native_java_library == NULL) {
393 vm_exit_during_initialization("Unable to load native library", ebuf);
394 }
395
396 #if defined(__OpenBSD__)
397 // Work-around OpenBSD's lack of $ORIGIN support by pre-loading libnet.so
398 // ignore errors
399 dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(), "net");
400 dll_load(buffer, ebuf, sizeof(ebuf));
401 #endif
402 }
403 static jboolean onLoaded = JNI_FALSE;
404 if (onLoaded) {
405 // We may have to wait to fire OnLoad until TLS is initialized.
406 if (ThreadLocalStorage::is_initialized()) {
407 // The JNI_OnLoad handling is normally done by method load in
408 // java.lang.ClassLoader$NativeLibrary, but the VM loads the base library
409 // explicitly so we have to check for JNI_OnLoad as well
410 const char *onLoadSymbols[] = JNI_ONLOAD_SYMBOLS;
411 JNI_OnLoad_t JNI_OnLoad = CAST_TO_FN_PTR(
412 JNI_OnLoad_t, dll_lookup(_native_java_library, onLoadSymbols[0]));
413 if (JNI_OnLoad != NULL) {
414 JavaThread* thread = JavaThread::current();
415 ThreadToNativeFromVM ttn(thread);
416 HandleMark hm(thread);
417 jint ver = (*JNI_OnLoad)(&main_vm, NULL);
418 onLoaded = JNI_TRUE;
419 if (!Threads::is_supported_jni_version_including_1_1(ver)) {
420 vm_exit_during_initialization("Unsupported JNI version");
421 }
|