1082 #elif defined(SOLARIS) 1083 Solaris::ucontext_set_pc(ctx, pc); 1084 #else 1085 VMError::report_and_die("unimplemented ucontext_get_pc"); 1086 #endif 1087 } 1088 1089 char* os::Posix::describe_pthread_attr(char* buf, size_t buflen, const pthread_attr_t* attr) { 1090 size_t stack_size = 0; 1091 size_t guard_size = 0; 1092 int detachstate = 0; 1093 pthread_attr_getstacksize(attr, &stack_size); 1094 pthread_attr_getguardsize(attr, &guard_size); 1095 pthread_attr_getdetachstate(attr, &detachstate); 1096 jio_snprintf(buf, buflen, "stacksize: " SIZE_FORMAT "k, guardsize: " SIZE_FORMAT "k, %s", 1097 stack_size / 1024, guard_size / 1024, 1098 (detachstate == PTHREAD_CREATE_DETACHED ? "detached" : "joinable")); 1099 return buf; 1100 } 1101 1102 1103 os::WatcherThreadCrashProtection::WatcherThreadCrashProtection() { 1104 assert(Thread::current()->is_Watcher_thread(), "Must be WatcherThread"); 1105 } 1106 1107 /* 1108 * See the caveats for this class in os_posix.hpp 1109 * Protects the callback call so that SIGSEGV / SIGBUS jumps back into this 1110 * method and returns false. If none of the signals are raised, returns true. 1111 * The callback is supposed to provide the method that should be protected. 1112 */ 1113 bool os::WatcherThreadCrashProtection::call(os::CrashProtectionCallback& cb) { 1114 sigset_t saved_sig_mask; 1115 1116 assert(Thread::current()->is_Watcher_thread(), "Only for WatcherThread"); 1117 assert(!WatcherThread::watcher_thread()->has_crash_protection(), 1118 "crash_protection already set?"); 1119 1120 // we cannot rely on sigsetjmp/siglongjmp to save/restore the signal mask 1121 // since on at least some systems (OS X) siglongjmp will restore the mask 1122 // for the process, not the thread | 1082 #elif defined(SOLARIS) 1083 Solaris::ucontext_set_pc(ctx, pc); 1084 #else 1085 VMError::report_and_die("unimplemented ucontext_get_pc"); 1086 #endif 1087 } 1088 1089 char* os::Posix::describe_pthread_attr(char* buf, size_t buflen, const pthread_attr_t* attr) { 1090 size_t stack_size = 0; 1091 size_t guard_size = 0; 1092 int detachstate = 0; 1093 pthread_attr_getstacksize(attr, &stack_size); 1094 pthread_attr_getguardsize(attr, &guard_size); 1095 pthread_attr_getdetachstate(attr, &detachstate); 1096 jio_snprintf(buf, buflen, "stacksize: " SIZE_FORMAT "k, guardsize: " SIZE_FORMAT "k, %s", 1097 stack_size / 1024, guard_size / 1024, 1098 (detachstate == PTHREAD_CREATE_DETACHED ? "detached" : "joinable")); 1099 return buf; 1100 } 1101 1102 // Check minimum allowable stack sizes for thread creation and to initialize 1103 // the java system classes, including StackOverflowError - depends on page 1104 // size. Add two 4K pages for compiler2 recursion in main thread. 1105 // Add in 4*BytesPerWord 4K pages to account for VM stack during 1106 // class initialization depending on 32 or 64 bit VM. 1107 jint os::Posix::set_minimum_stack_sizes() { 1108 _java_thread_min_stack_allowed = MAX2(_java_thread_min_stack_allowed, 1109 JavaThread::stack_guard_zone_size() + 1110 JavaThread::stack_shadow_zone_size() + 1111 (4 * BytesPerWord COMPILER2_PRESENT(+ 2)) * 4 * K); 1112 1113 _java_thread_min_stack_allowed = align_size_up(_java_thread_min_stack_allowed, vm_page_size()); 1114 1115 size_t stack_size_in_bytes = ThreadStackSize * K; 1116 if (stack_size_in_bytes != 0 && 1117 stack_size_in_bytes < _java_thread_min_stack_allowed) { 1118 // The '-Xss' and '-XX:ThreadStackSize=N' options both set 1119 // ThreadStackSize so we go with "Java thread stack size" instead 1120 // of "ThreadStackSize" to be more friendly. 1121 tty->print_cr("\nThe Java thread stack size specified is too small. " 1122 "Specify at least " SIZE_FORMAT "k", 1123 _java_thread_min_stack_allowed / K); 1124 return JNI_ERR; 1125 } 1126 1127 #ifdef SOLARIS 1128 // For 64kbps there will be a 64kb page size, which makes 1129 // the usable default stack size quite a bit less. Increase the 1130 // stack for 64kb (or any > than 8kb) pages, this increases 1131 // virtual memory fragmentation (since we're not creating the 1132 // stack on a power of 2 boundary. The real fix for this 1133 // should be to fix the guard page mechanism. 1134 1135 if (vm_page_size() > 8*K) { 1136 stack_size_in_bytes = (stack_size_in_bytes != 0) 1137 ? stack_size_in_bytes + 1138 JavaThread::stack_red_zone_size() + 1139 JavaThread::stack_yellow_zone_size() 1140 : 0; 1141 ThreadStackSize = stack_size_in_bytes/K; 1142 } 1143 #endif // SOLARIS 1144 1145 // Make the stack size a multiple of the page size so that 1146 // the yellow/red zones can be guarded. 1147 JavaThread::set_stack_size_at_create(round_to(stack_size_in_bytes, 1148 vm_page_size())); 1149 1150 _compiler_thread_min_stack_allowed = align_size_up(_compiler_thread_min_stack_allowed, vm_page_size()); 1151 1152 stack_size_in_bytes = CompilerThreadStackSize * K; 1153 if (stack_size_in_bytes != 0 && 1154 stack_size_in_bytes < _compiler_thread_min_stack_allowed) { 1155 tty->print_cr("\nThe CompilerThreadStackSize specified is too small. " 1156 "Specify at least " SIZE_FORMAT "k", 1157 _compiler_thread_min_stack_allowed / K); 1158 return JNI_ERR; 1159 } 1160 1161 _vm_internal_thread_min_stack_allowed = align_size_up(_vm_internal_thread_min_stack_allowed, vm_page_size()); 1162 1163 stack_size_in_bytes = VMThreadStackSize * K; 1164 if (stack_size_in_bytes != 0 && 1165 stack_size_in_bytes < _vm_internal_thread_min_stack_allowed) { 1166 tty->print_cr("\nThe VMThreadStackSize specified is too small. " 1167 "Specify at least " SIZE_FORMAT "k", 1168 _vm_internal_thread_min_stack_allowed / K); 1169 return JNI_ERR; 1170 } 1171 return JNI_OK; 1172 } 1173 1174 // Called when creating the thread. The minimum stack sizes have already been calculated 1175 size_t os::Posix::get_initial_stack_size(ThreadType thr_type, size_t req_stack_size) { 1176 size_t stack_size; 1177 if (req_stack_size == 0) { 1178 stack_size = default_stack_size(thr_type); 1179 } else { 1180 stack_size = req_stack_size; 1181 } 1182 1183 switch (thr_type) { 1184 case os::java_thread: 1185 // Java threads use ThreadStackSize which default value can be 1186 // changed with the flag -Xss 1187 if (req_stack_size == 0 && JavaThread::stack_size_at_create() > 0) { 1188 // no requested size and we have a more specific default value 1189 stack_size = JavaThread::stack_size_at_create(); 1190 } 1191 stack_size = MAX2(stack_size, 1192 _java_thread_min_stack_allowed); 1193 break; 1194 case os::compiler_thread: 1195 if (req_stack_size == 0 && CompilerThreadStackSize > 0) { 1196 // no requested size and we have a more specific default value 1197 stack_size = (size_t)(CompilerThreadStackSize * K); 1198 } 1199 stack_size = MAX2(stack_size, 1200 _compiler_thread_min_stack_allowed); 1201 break; 1202 case os::vm_thread: 1203 case os::pgc_thread: 1204 case os::cgc_thread: 1205 case os::watcher_thread: 1206 default: // presume the unknown thr_type is a VM internal 1207 if (req_stack_size == 0 && VMThreadStackSize > 0) { 1208 // no requested size and we have a more specific default value 1209 stack_size = (size_t)(VMThreadStackSize * K); 1210 } 1211 1212 stack_size = MAX2(stack_size, 1213 _vm_internal_thread_min_stack_allowed); 1214 break; 1215 } 1216 1217 return stack_size; 1218 } 1219 1220 os::WatcherThreadCrashProtection::WatcherThreadCrashProtection() { 1221 assert(Thread::current()->is_Watcher_thread(), "Must be WatcherThread"); 1222 } 1223 1224 /* 1225 * See the caveats for this class in os_posix.hpp 1226 * Protects the callback call so that SIGSEGV / SIGBUS jumps back into this 1227 * method and returns false. If none of the signals are raised, returns true. 1228 * The callback is supposed to provide the method that should be protected. 1229 */ 1230 bool os::WatcherThreadCrashProtection::call(os::CrashProtectionCallback& cb) { 1231 sigset_t saved_sig_mask; 1232 1233 assert(Thread::current()->is_Watcher_thread(), "Only for WatcherThread"); 1234 assert(!WatcherThread::watcher_thread()->has_crash_protection(), 1235 "crash_protection already set?"); 1236 1237 // we cannot rely on sigsetjmp/siglongjmp to save/restore the signal mask 1238 // since on at least some systems (OS X) siglongjmp will restore the mask 1239 // for the process, not the thread |