1023 } |
1023 } |
1024 |
1024 |
1025 |
1025 |
1026 // Creates the initial ThreadGroup |
1026 // Creates the initial ThreadGroup |
1027 static Handle create_initial_thread_group(TRAPS) { |
1027 static Handle create_initial_thread_group(TRAPS) { |
1028 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_ThreadGroup(), true, CHECK_NH); |
1028 Handle system_instance = JavaCalls::construct_new_instance( |
1029 InstanceKlass* ik = InstanceKlass::cast(k); |
1029 SystemDictionary::ThreadGroup_klass(), |
1030 |
|
1031 Handle system_instance = ik->allocate_instance_handle(CHECK_NH); |
|
1032 { |
|
1033 JavaValue result(T_VOID); |
|
1034 JavaCalls::call_special(&result, |
|
1035 system_instance, |
|
1036 ik, |
|
1037 vmSymbols::object_initializer_name(), |
|
1038 vmSymbols::void_method_signature(), |
1030 vmSymbols::void_method_signature(), |
1039 CHECK_NH); |
1031 CHECK_NH); |
1040 } |
|
1041 Universe::set_system_thread_group(system_instance()); |
1032 Universe::set_system_thread_group(system_instance()); |
1042 |
1033 |
1043 Handle main_instance = ik->allocate_instance_handle(CHECK_NH); |
1034 Handle string = java_lang_String::create_from_str("main", CHECK_NH); |
1044 { |
1035 Handle main_instance = JavaCalls::construct_new_instance( |
1045 JavaValue result(T_VOID); |
1036 SystemDictionary::ThreadGroup_klass(), |
1046 Handle string = java_lang_String::create_from_str("main", CHECK_NH); |
|
1047 JavaCalls::call_special(&result, |
|
1048 main_instance, |
|
1049 ik, |
|
1050 vmSymbols::object_initializer_name(), |
|
1051 vmSymbols::threadgroup_string_void_signature(), |
1037 vmSymbols::threadgroup_string_void_signature(), |
1052 system_instance, |
1038 system_instance, |
1053 string, |
1039 string, |
1054 CHECK_NH); |
1040 CHECK_NH); |
1055 } |
|
1056 return main_instance; |
1041 return main_instance; |
1057 } |
1042 } |
1058 |
1043 |
1059 // Creates the initial Thread |
1044 // Creates the initial Thread |
1060 static oop create_initial_thread(Handle thread_group, JavaThread* thread, |
1045 static oop create_initial_thread(Handle thread_group, JavaThread* thread, |
1061 TRAPS) { |
1046 TRAPS) { |
1062 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK_NULL); |
1047 InstanceKlass* ik = SystemDictionary::Thread_klass(); |
1063 InstanceKlass* ik = InstanceKlass::cast(k); |
1048 assert(ik->is_initialized(), "must be"); |
1064 instanceHandle thread_oop = ik->allocate_instance_handle(CHECK_NULL); |
1049 instanceHandle thread_oop = ik->allocate_instance_handle(CHECK_NULL); |
1065 |
1050 |
|
1051 // Cannot use JavaCalls::construct_new_instance because the java.lang.Thread |
|
1052 // constructor calls Thread.current(), which must be set here for the |
|
1053 // initial thread. |
1066 java_lang_Thread::set_thread(thread_oop(), thread); |
1054 java_lang_Thread::set_thread(thread_oop(), thread); |
1067 java_lang_Thread::set_priority(thread_oop(), NormPriority); |
1055 java_lang_Thread::set_priority(thread_oop(), NormPriority); |
1068 thread->set_threadObj(thread_oop()); |
1056 thread->set_threadObj(thread_oop()); |
1069 |
1057 |
1070 Handle string = java_lang_String::create_from_str("main", CHECK_NULL); |
1058 Handle string = java_lang_String::create_from_str("main", CHECK_NULL); |
1168 void JavaThread::allocate_threadObj(Handle thread_group, const char* thread_name, |
1156 void JavaThread::allocate_threadObj(Handle thread_group, const char* thread_name, |
1169 bool daemon, TRAPS) { |
1157 bool daemon, TRAPS) { |
1170 assert(thread_group.not_null(), "thread group should be specified"); |
1158 assert(thread_group.not_null(), "thread group should be specified"); |
1171 assert(threadObj() == NULL, "should only create Java thread object once"); |
1159 assert(threadObj() == NULL, "should only create Java thread object once"); |
1172 |
1160 |
1173 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK); |
1161 InstanceKlass* ik = SystemDictionary::Thread_klass(); |
1174 InstanceKlass* ik = InstanceKlass::cast(k); |
1162 assert(ik->is_initialized(), "must be"); |
1175 instanceHandle thread_oop = ik->allocate_instance_handle(CHECK); |
1163 instanceHandle thread_oop = ik->allocate_instance_handle(CHECK); |
1176 |
1164 |
|
1165 // We are called from jni_AttachCurrentThread/jni_AttachCurrentThreadAsDaemon. |
|
1166 // We cannot use JavaCalls::construct_new_instance because the java.lang.Thread |
|
1167 // constructor calls Thread.current(), which must be set here. |
1177 java_lang_Thread::set_thread(thread_oop(), this); |
1168 java_lang_Thread::set_thread(thread_oop(), this); |
1178 java_lang_Thread::set_priority(thread_oop(), NormPriority); |
1169 java_lang_Thread::set_priority(thread_oop(), NormPriority); |
1179 set_threadObj(thread_oop()); |
1170 set_threadObj(thread_oop()); |
1180 |
1171 |
1181 JavaValue result(T_VOID); |
1172 JavaValue result(T_VOID); |
1185 JavaCalls::call_special(&result, |
1176 JavaCalls::call_special(&result, |
1186 thread_oop, |
1177 thread_oop, |
1187 ik, |
1178 ik, |
1188 vmSymbols::object_initializer_name(), |
1179 vmSymbols::object_initializer_name(), |
1189 vmSymbols::threadgroup_string_void_signature(), |
1180 vmSymbols::threadgroup_string_void_signature(), |
1190 thread_group, // Argument 1 |
1181 thread_group, |
1191 name, // Argument 2 |
1182 name, |
1192 THREAD); |
1183 THREAD); |
1193 } else { |
1184 } else { |
1194 // Thread gets assigned name "Thread-nnn" and null target |
1185 // Thread gets assigned name "Thread-nnn" and null target |
1195 // (java.lang.Thread doesn't have a constructor taking only a ThreadGroup argument) |
1186 // (java.lang.Thread doesn't have a constructor taking only a ThreadGroup argument) |
1196 JavaCalls::call_special(&result, |
1187 JavaCalls::call_special(&result, |
1197 thread_oop, |
1188 thread_oop, |
1198 ik, |
1189 ik, |
1199 vmSymbols::object_initializer_name(), |
1190 vmSymbols::object_initializer_name(), |
1200 vmSymbols::threadgroup_runnable_void_signature(), |
1191 vmSymbols::threadgroup_runnable_void_signature(), |
1201 thread_group, // Argument 1 |
1192 thread_group, |
1202 Handle(), // Argument 2 |
1193 Handle(), |
1203 THREAD); |
1194 THREAD); |
1204 } |
1195 } |
1205 |
1196 |
1206 |
1197 |
1207 if (daemon) { |
1198 if (daemon) { |