183 // 4759953: Compensate for ridiculous stack size.
184 size = max_intx;
185 }
186 if (size > (size_t)base) {
187 // 4812466: Make sure size doesn't allow the stack to wrap the address space.
188 size = (size_t)base;
189 }
190 return size;
191 }
192
193 static inline stack_t get_stack_info() {
194 stack_t st;
195 int retval = thr_stksegment(&st);
196 st.ss_size = adjust_stack_size((address)st.ss_sp, st.ss_size);
197 assert(retval == 0, "incorrect return value from thr_stksegment");
198 assert((address)&st < (address)st.ss_sp, "Invalid stack base returned");
199 assert((address)&st > (address)st.ss_sp-st.ss_size, "Invalid stack size returned");
200 return st;
201 }
202
203 address os::current_stack_base() {
204 int r = thr_main();
205 guarantee(r == 0 || r == 1, "CR6501650 or CR6493689");
206 bool is_primordial_thread = r;
207
208 // Workaround 4352906, avoid calls to thr_stksegment by
209 // thr_main after the first one (it looks like we trash
210 // some data, causing the value for ss_sp to be incorrect).
211 if (!is_primordial_thread || os::Solaris::_main_stack_base == NULL) {
212 stack_t st = get_stack_info();
213 if (is_primordial_thread) {
214 // cache initial value of stack base
215 os::Solaris::_main_stack_base = (address)st.ss_sp;
216 }
217 return (address)st.ss_sp;
218 } else {
219 guarantee(os::Solaris::_main_stack_base != NULL, "Attempt to use null cached stack base");
220 return os::Solaris::_main_stack_base;
221 }
222 }
223
224 size_t os::current_stack_size() {
225 size_t size;
226
227 int r = thr_main();
228 guarantee(r == 0 || r == 1, "CR6501650 or CR6493689");
229 if (!r) {
230 size = get_stack_info().ss_size;
231 } else {
232 struct rlimit limits;
233 getrlimit(RLIMIT_STACK, &limits);
234 size = adjust_stack_size(os::Solaris::_main_stack_base, (size_t)limits.rlim_cur);
235 }
236 // base may not be page aligned
237 address base = current_stack_base();
238 address bottom = align_up(base - size, os::vm_page_size());;
239 return (size_t)(base - bottom);
240 }
241
242 struct tm* os::localtime_pd(const time_t* clock, struct tm* res) {
243 return localtime_r(clock, res);
244 }
245
246 void os::Solaris::try_enable_extended_io() {
247 typedef int (*enable_extended_FILE_stdio_t)(int, int);
248
249 if (!UseExtendedFileIO) {
1077 // (For some reason, they get blocked by default.)
1078 sigset_t* os::Solaris::unblocked_signals() {
1079 assert(signal_sets_initialized, "Not initialized");
1080 return &unblocked_sigs;
1081 }
1082
1083 // These are the signals that are blocked while a (non-VM) thread is
1084 // running Java. Only the VM thread handles these signals.
1085 sigset_t* os::Solaris::vm_signals() {
1086 assert(signal_sets_initialized, "Not initialized");
1087 return &vm_sigs;
1088 }
1089
1090 void _handle_uncaught_cxx_exception() {
1091 VMError::report_and_die("An uncaught C++ exception");
1092 }
1093
1094
1095 // First crack at OS-specific initialization, from inside the new thread.
1096 void os::initialize_thread(Thread* thr) {
1097 int r = thr_main();
1098 guarantee(r == 0 || r == 1, "CR6501650 or CR6493689");
1099 if (r) {
1100 JavaThread* jt = (JavaThread *)thr;
1101 assert(jt != NULL, "Sanity check");
1102 size_t stack_size;
1103 address base = jt->stack_base();
1104 if (Arguments::created_by_java_launcher()) {
1105 // Use 2MB to allow for Solaris 7 64 bit mode.
1106 stack_size = JavaThread::stack_size_at_create() == 0
1107 ? 2048*K : JavaThread::stack_size_at_create();
1108
1109 // There are rare cases when we may have already used more than
1110 // the basic stack size allotment before this method is invoked.
1111 // Attempt to allow for a normally sized java_stack.
1112 size_t current_stack_offset = (size_t)(base - (address)&stack_size);
1113 stack_size += ReservedSpace::page_align_size_down(current_stack_offset);
1114 } else {
1115 // 6269555: If we were not created by a Java launcher, i.e. if we are
1116 // running embedded in a native application, treat the primordial thread
1117 // as much like a native attached thread as possible. This means using
1118 // the current stack size from thr_stksegment(), unless it is too large
1119 // to reliably setup guard pages. A reasonable max size is 8MB.
|
183 // 4759953: Compensate for ridiculous stack size.
184 size = max_intx;
185 }
186 if (size > (size_t)base) {
187 // 4812466: Make sure size doesn't allow the stack to wrap the address space.
188 size = (size_t)base;
189 }
190 return size;
191 }
192
193 static inline stack_t get_stack_info() {
194 stack_t st;
195 int retval = thr_stksegment(&st);
196 st.ss_size = adjust_stack_size((address)st.ss_sp, st.ss_size);
197 assert(retval == 0, "incorrect return value from thr_stksegment");
198 assert((address)&st < (address)st.ss_sp, "Invalid stack base returned");
199 assert((address)&st > (address)st.ss_sp-st.ss_size, "Invalid stack size returned");
200 return st;
201 }
202
203 bool os::is_primordial_thread(void) {
204 int r = thr_main();
205 guarantee(r == 0 || r == 1, "CR6501650 or CR6493689");
206 return r == 1;
207 }
208
209 address os::current_stack_base() {
210 bool is_primordial_thread = is_primordial_thread();
211
212 // Workaround 4352906, avoid calls to thr_stksegment by
213 // thr_main after the first one (it looks like we trash
214 // some data, causing the value for ss_sp to be incorrect).
215 if (!is_primordial_thread || os::Solaris::_main_stack_base == NULL) {
216 stack_t st = get_stack_info();
217 if (is_primordial_thread) {
218 // cache initial value of stack base
219 os::Solaris::_main_stack_base = (address)st.ss_sp;
220 }
221 return (address)st.ss_sp;
222 } else {
223 guarantee(os::Solaris::_main_stack_base != NULL, "Attempt to use null cached stack base");
224 return os::Solaris::_main_stack_base;
225 }
226 }
227
228 size_t os::current_stack_size() {
229 size_t size;
230
231 if (!is_primordial_thread()) {
232 size = get_stack_info().ss_size;
233 } else {
234 struct rlimit limits;
235 getrlimit(RLIMIT_STACK, &limits);
236 size = adjust_stack_size(os::Solaris::_main_stack_base, (size_t)limits.rlim_cur);
237 }
238 // base may not be page aligned
239 address base = current_stack_base();
240 address bottom = align_up(base - size, os::vm_page_size());;
241 return (size_t)(base - bottom);
242 }
243
244 struct tm* os::localtime_pd(const time_t* clock, struct tm* res) {
245 return localtime_r(clock, res);
246 }
247
248 void os::Solaris::try_enable_extended_io() {
249 typedef int (*enable_extended_FILE_stdio_t)(int, int);
250
251 if (!UseExtendedFileIO) {
1079 // (For some reason, they get blocked by default.)
1080 sigset_t* os::Solaris::unblocked_signals() {
1081 assert(signal_sets_initialized, "Not initialized");
1082 return &unblocked_sigs;
1083 }
1084
1085 // These are the signals that are blocked while a (non-VM) thread is
1086 // running Java. Only the VM thread handles these signals.
1087 sigset_t* os::Solaris::vm_signals() {
1088 assert(signal_sets_initialized, "Not initialized");
1089 return &vm_sigs;
1090 }
1091
1092 void _handle_uncaught_cxx_exception() {
1093 VMError::report_and_die("An uncaught C++ exception");
1094 }
1095
1096
1097 // First crack at OS-specific initialization, from inside the new thread.
1098 void os::initialize_thread(Thread* thr) {
1099 if (is_primordial_thread()) {
1100 JavaThread* jt = (JavaThread *)thr;
1101 assert(jt != NULL, "Sanity check");
1102 size_t stack_size;
1103 address base = jt->stack_base();
1104 if (Arguments::created_by_java_launcher()) {
1105 // Use 2MB to allow for Solaris 7 64 bit mode.
1106 stack_size = JavaThread::stack_size_at_create() == 0
1107 ? 2048*K : JavaThread::stack_size_at_create();
1108
1109 // There are rare cases when we may have already used more than
1110 // the basic stack size allotment before this method is invoked.
1111 // Attempt to allow for a normally sized java_stack.
1112 size_t current_stack_offset = (size_t)(base - (address)&stack_size);
1113 stack_size += ReservedSpace::page_align_size_down(current_stack_offset);
1114 } else {
1115 // 6269555: If we were not created by a Java launcher, i.e. if we are
1116 // running embedded in a native application, treat the primordial thread
1117 // as much like a native attached thread as possible. This means using
1118 // the current stack size from thr_stksegment(), unless it is too large
1119 // to reliably setup guard pages. A reasonable max size is 8MB.
|