1 /*
2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
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 = (address)align_size_up((intptr_t)(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 // interruptible infrastructure
247
248 // setup_interruptible saves the thread state before going into an
249 // interruptible system call.
1260 sigset_t* os::Solaris::vm_signals() {
1261 assert(signal_sets_initialized, "Not initialized");
1262 return &vm_sigs;
1263 }
1264
1265 // These are signals that are blocked during cond_wait to allow debugger in
1266 sigset_t* os::Solaris::allowdebug_blocked_signals() {
1267 assert(signal_sets_initialized, "Not initialized");
1268 return &allowdebug_blocked_sigs;
1269 }
1270
1271
1272 void _handle_uncaught_cxx_exception() {
1273 VMError err("An uncaught C++ exception");
1274 err.report_and_die();
1275 }
1276
1277
1278 // First crack at OS-specific initialization, from inside the new thread.
1279 void os::initialize_thread(Thread* thr) {
1280 int r = thr_main() ;
1281 guarantee (r == 0 || r == 1, "CR6501650 or CR6493689") ;
1282 if (r) {
1283 JavaThread* jt = (JavaThread *)thr;
1284 assert(jt != NULL,"Sanity check");
1285 size_t stack_size;
1286 address base = jt->stack_base();
1287 if (Arguments::created_by_java_launcher()) {
1288 // Use 2MB to allow for Solaris 7 64 bit mode.
1289 stack_size = JavaThread::stack_size_at_create() == 0
1290 ? 2048*K : JavaThread::stack_size_at_create();
1291
1292 // There are rare cases when we may have already used more than
1293 // the basic stack size allotment before this method is invoked.
1294 // Attempt to allow for a normally sized java_stack.
1295 size_t current_stack_offset = (size_t)(base - (address)&stack_size);
1296 stack_size += ReservedSpace::page_align_size_down(current_stack_offset);
1297 } else {
1298 // 6269555: If we were not created by a Java launcher, i.e. if we are
1299 // running embedded in a native application, treat the primordial thread
1300 // as much like a native attached thread as possible. This means using
1301 // the current stack size from thr_stksegment(), unless it is too large
1302 // to reliably setup guard pages. A reasonable max size is 8MB.
4887 } else {
4888 Solaris::set_dev_zero_fd(fd);
4889
4890 // Close on exec, child won't inherit.
4891 fcntl(fd, F_SETFD, FD_CLOEXEC);
4892 }
4893
4894 clock_tics_per_sec = CLK_TCK;
4895
4896 // check if dladdr1() exists; dladdr1 can provide more information than
4897 // dladdr for os::dll_address_to_function_name. It comes with SunOS 5.9
4898 // and is available on linker patches for 5.7 and 5.8.
4899 // libdl.so must have been loaded, this call is just an entry lookup
4900 void * hdl = dlopen("libdl.so", RTLD_NOW);
4901 if (hdl)
4902 dladdr1_func = CAST_TO_FN_PTR(dladdr1_func_type, dlsym(hdl, "dladdr1"));
4903
4904 // (Solaris only) this switches to calls that actually do locking.
4905 ThreadCritical::initialize();
4906
4907 main_thread = thr_self();
4908
4909 // Constant minimum stack size allowed. It must be at least
4910 // the minimum of what the OS supports (thr_min_stack()), and
4911 // enough to allow the thread to get to user bytecode execution.
4912 Solaris::min_stack_allowed = MAX2(thr_min_stack(), Solaris::min_stack_allowed);
4913 // If the pagesize of the VM is greater than 8K determine the appropriate
4914 // number of initial guard pages. The user can change this with the
4915 // command line arguments, if needed.
4916 if (vm_page_size() > 8*K) {
4917 StackYellowPages = 1;
4918 StackRedPages = 1;
4919 StackShadowPages = round_to((StackShadowPages*8*K), vm_page_size()) / vm_page_size();
4920 }
4921 }
4922
4923 // To install functions for atexit system call
4924 extern "C" {
4925 static void perfMemory_exit_helper() {
4926 perfMemory_exit();
|
1 /*
2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
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 = (address)align_size_up((intptr_t)(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 // interruptible infrastructure
249
250 // setup_interruptible saves the thread state before going into an
251 // interruptible system call.
1262 sigset_t* os::Solaris::vm_signals() {
1263 assert(signal_sets_initialized, "Not initialized");
1264 return &vm_sigs;
1265 }
1266
1267 // These are signals that are blocked during cond_wait to allow debugger in
1268 sigset_t* os::Solaris::allowdebug_blocked_signals() {
1269 assert(signal_sets_initialized, "Not initialized");
1270 return &allowdebug_blocked_sigs;
1271 }
1272
1273
1274 void _handle_uncaught_cxx_exception() {
1275 VMError err("An uncaught C++ exception");
1276 err.report_and_die();
1277 }
1278
1279
1280 // First crack at OS-specific initialization, from inside the new thread.
1281 void os::initialize_thread(Thread* thr) {
1282 if (is_primordial_thread()) {
1283 JavaThread* jt = (JavaThread *)thr;
1284 assert(jt != NULL,"Sanity check");
1285 size_t stack_size;
1286 address base = jt->stack_base();
1287 if (Arguments::created_by_java_launcher()) {
1288 // Use 2MB to allow for Solaris 7 64 bit mode.
1289 stack_size = JavaThread::stack_size_at_create() == 0
1290 ? 2048*K : JavaThread::stack_size_at_create();
1291
1292 // There are rare cases when we may have already used more than
1293 // the basic stack size allotment before this method is invoked.
1294 // Attempt to allow for a normally sized java_stack.
1295 size_t current_stack_offset = (size_t)(base - (address)&stack_size);
1296 stack_size += ReservedSpace::page_align_size_down(current_stack_offset);
1297 } else {
1298 // 6269555: If we were not created by a Java launcher, i.e. if we are
1299 // running embedded in a native application, treat the primordial thread
1300 // as much like a native attached thread as possible. This means using
1301 // the current stack size from thr_stksegment(), unless it is too large
1302 // to reliably setup guard pages. A reasonable max size is 8MB.
4887 } else {
4888 Solaris::set_dev_zero_fd(fd);
4889
4890 // Close on exec, child won't inherit.
4891 fcntl(fd, F_SETFD, FD_CLOEXEC);
4892 }
4893
4894 clock_tics_per_sec = CLK_TCK;
4895
4896 // check if dladdr1() exists; dladdr1 can provide more information than
4897 // dladdr for os::dll_address_to_function_name. It comes with SunOS 5.9
4898 // and is available on linker patches for 5.7 and 5.8.
4899 // libdl.so must have been loaded, this call is just an entry lookup
4900 void * hdl = dlopen("libdl.so", RTLD_NOW);
4901 if (hdl)
4902 dladdr1_func = CAST_TO_FN_PTR(dladdr1_func_type, dlsym(hdl, "dladdr1"));
4903
4904 // (Solaris only) this switches to calls that actually do locking.
4905 ThreadCritical::initialize();
4906
4907 // main_thread points to the thread that created/loaded the JVM.
4908 main_thread = thr_self();
4909
4910 // Constant minimum stack size allowed. It must be at least
4911 // the minimum of what the OS supports (thr_min_stack()), and
4912 // enough to allow the thread to get to user bytecode execution.
4913 Solaris::min_stack_allowed = MAX2(thr_min_stack(), Solaris::min_stack_allowed);
4914 // If the pagesize of the VM is greater than 8K determine the appropriate
4915 // number of initial guard pages. The user can change this with the
4916 // command line arguments, if needed.
4917 if (vm_page_size() > 8*K) {
4918 StackYellowPages = 1;
4919 StackRedPages = 1;
4920 StackShadowPages = round_to((StackShadowPages*8*K), vm_page_size()) / vm_page_size();
4921 }
4922 }
4923
4924 // To install functions for atexit system call
4925 extern "C" {
4926 static void perfMemory_exit_helper() {
4927 perfMemory_exit();
|