关于你的第二个问题:
2)是否有一个文本这可以指导我详细介绍java 线程创建的全过程,这些线程应该覆盖windows的各个操作系统调用 ?
本指南,但稍微偏离主题是伟大的:http://blog.jamesdbloom.com/JVMInternals.html
而下面的书The Java Virtual Machine Specification, Java SE 7 Edition (google book link)深入阐述JVM内部,因此将是我最好的选择(声明:我只脱脂通过可见部分)
如果这还不够好,你总是可以download为open jdk (7)的源代码,并通过代码爬...
一个摘录从开放的JDK的代码是这样(OpenJDK的\热点的\ src \共享\虚拟机\运行\ thread.cpp - c'tor):
// Base class for all threads: VMThread, WatcherThread, ConcurrentMarkSweepThread,
// JavaThread
Thread::Thread() {
// stack and get_thread
set_stack_base(NULL);
set_stack_size(0);
set_self_raw_id(0);
set_lgrp_id(-1);
// allocated data structures
set_osthread(NULL);
set_resource_area(new ResourceArea());
set_handle_area(new HandleArea(NULL));
set_active_handles(NULL);
set_free_handle_block(NULL);
set_last_handle_mark(NULL);
// This initial value ==> never claimed.
_oops_do_parity = 0;
// the handle mark links itself to last_handle_mark
new HandleMark(this);
// plain initialization
debug_only(_owned_locks = NULL;)
debug_only(_allow_allocation_count = 0;)
NOT_PRODUCT(_allow_safepoint_count = 0;)
NOT_PRODUCT(_skip_gcalot = false;)
CHECK_UNHANDLED_OOPS_ONLY(_gc_locked_out_count = 0;)
_jvmti_env_iteration_count = 0;
set_allocated_bytes(0);
_vm_operation_started_count = 0;
_vm_operation_completed_count = 0;
_current_pending_monitor = NULL;
_current_pending_monitor_is_from_java = true;
_current_waiting_monitor = NULL;
_num_nested_signal = 0;
omFreeList = NULL ;
omFreeCount = 0 ;
omFreeProvision = 32 ;
omInUseList = NULL ;
omInUseCount = 0 ;
_SR_lock = new Monitor(Mutex::suspend_resume, "SR_lock", true);
_suspend_flags = 0;
// thread-specific hashCode stream generator state - Marsaglia shift-xor form
_hashStateX = os::random() ;
_hashStateY = 842502087 ;
_hashStateZ = 0x8767 ; // (int)(3579807591LL & 0xffff) ;
_hashStateW = 273326509 ;
_OnTrap = 0 ;
_schedctl = NULL ;
_Stalled = 0 ;
_TypeTag = 0x2BAD ;
// Many of the following fields are effectively final - immutable
// Note that nascent threads can't use the Native Monitor-Mutex
// construct until the _MutexEvent is initialized ...
// CONSIDER: instead of using a fixed set of purpose-dedicated ParkEvents
// we might instead use a stack of ParkEvents that we could provision on-demand.
// The stack would act as a cache to avoid calls to ParkEvent::Allocate()
// and ::Release()
_ParkEvent = ParkEvent::Allocate (this) ;
_SleepEvent = ParkEvent::Allocate (this) ;
_MutexEvent = ParkEvent::Allocate (this) ;
_MuxEvent = ParkEvent::Allocate (this) ;
#ifdef CHECK_UNHANDLED_OOPS
if (CheckUnhandledOops) {
_unhandled_oops = new UnhandledOops(this);
}
#endif // CHECK_UNHANDLED_OOPS
#ifdef ASSERT
if (UseBiasedLocking) {
assert((((uintptr_t) this) & (markOopDesc::biased_lock_alignment - 1)) == 0, "forced alignment of thread object failed");
assert(this == _real_malloc_address ||
this == (void*) align_size_up((intptr_t) _real_malloc_address, markOopDesc::biased_lock_alignment),
"bug in forced alignment of thread objects");
}
#endif /* ASSERT */
}
你有没有看JConsole的附带分布的jdk? –
@Shervin - 我研究过jconsole和jvisualvm,既然它们都支持mbeans,我去了ThreadImpl.getThreadAllocatedBytes,它是java堆栈大小的指标吗?我也找不到线程创建所花时间的任何指示符?你也可以帮助我在第二点,我正在寻找一些关于Java线程构建过程和Windows相关操作系统级别调用的重要理论。 – 100pipers