1097 stack_size / 1024, guard_size / 1024, |
1097 stack_size / 1024, guard_size / 1024, |
1098 (detachstate == PTHREAD_CREATE_DETACHED ? "detached" : "joinable")); |
1098 (detachstate == PTHREAD_CREATE_DETACHED ? "detached" : "joinable")); |
1099 return buf; |
1099 return buf; |
1100 } |
1100 } |
1101 |
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 } |
1102 |
1219 |
1103 os::WatcherThreadCrashProtection::WatcherThreadCrashProtection() { |
1220 os::WatcherThreadCrashProtection::WatcherThreadCrashProtection() { |
1104 assert(Thread::current()->is_Watcher_thread(), "Must be WatcherThread"); |
1221 assert(Thread::current()->is_Watcher_thread(), "Must be WatcherThread"); |
1105 } |
1222 } |
1106 |
1223 |