编译源码
apt-get install -y autoconf zip libx11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev libcups2-dev libfontconfig1-dev libasound2-dev
编译配置:
hotspot\make\linux\makefiles\gcc.make
CFLAGS += -std=c++98
WARNINGS_ARE_ERRORS = -Wno-all -fpermissive
JDK8编译命令
./configure --with-debug-level=slowdebug --disable-zip-debug-info
DEBUG_BINARIES=true make JOBS=10 CONF=linux-x86_64-normal-server-slowdebug
make all ZIP_DEBUGINFO_FILES=0 DISABLE_HOTSPOT_OS_VERSION_CHECK=OK
主函数路径:/jdk/src/share/bin/main.c
启动lancher jdk/src/share/bin/java.c
内存分配部分代码:/src/share/vm/gc_interface collectedHeap.inline.hpp
oop CollectedHeap::obj_allocate(KlassHandle klass, int size, TRAPS) {
debug_only(check_for_valid_allocation_state());
assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed");
assert(size >= 0, "int won't convert to size_t");
HeapWord* obj = common_mem_allocate_init(klass, size, CHECK_NULL);
post_allocation_setup_obj(klass, obj, size);
NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size));
return (oop)obj;
}
指针碰撞的内存分配:/src/share/vm/space.cpp
inline HeapWord* ContiguousSpace::par_allocate_impl(size_t size,
HeapWord* const end_value) {
do {
HeapWord* obj = top();
if (pointer_delta(end_value, obj) >= size) {
HeapWord* new_top = obj + size;
HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj);
// result can be one of two:
// the old top value: the exchange succeeded
// otherwise: the new value of the top is returned.
if (result == obj) {
assert(is_aligned(obj) && is_aligned(new_top), "checking alignment");
return obj;
}
} else {
return NULL;
}
} while (true);
}
系统可用内存 ,top指针加上对象的尺寸大于size 则进行分配,分配之前进行cas操作如果成功则分配.