提交 af2ee273 编写于 作者: J jrose

6770949: minor tweaks before 6655638

Summary: minor cleanups & tuning of array.hpp, debug.cpp, growableArray.hpp, hashtable.cpp
Reviewed-by: kvn
上级 6c74845c
...@@ -40,11 +40,18 @@ class ResourceArray: public ResourceObj { ...@@ -40,11 +40,18 @@ class ResourceArray: public ResourceObj {
_length = 0; _length = 0;
_data = NULL; _data = NULL;
DEBUG_ONLY(init_nesting();) DEBUG_ONLY(init_nesting();)
// client may call initialize, at most once
} }
ResourceArray(size_t esize, int length) { ResourceArray(size_t esize, int length) {
DEBUG_ONLY(_data = NULL);
initialize(esize, length);
}
void initialize(size_t esize, int length) {
assert(length >= 0, "illegal length"); assert(length >= 0, "illegal length");
assert(_data == NULL, "must be new object");
_length = length; _length = length;
_data = resource_allocate_bytes(esize * length); _data = resource_allocate_bytes(esize * length);
DEBUG_ONLY(init_nesting();) DEBUG_ONLY(init_nesting();)
...@@ -111,7 +118,10 @@ class CHeapArray: public CHeapObj { ...@@ -111,7 +118,10 @@ class CHeapArray: public CHeapObj {
/* creation */ \ /* creation */ \
array_name() : base_class() {} \ array_name() : base_class() {} \
array_name(const int length) : base_class(esize, length) {} \ array_name(const int length) : base_class(esize, length) {} \
array_name(const int length, const etype fx) : base_class(esize, length) { \ array_name(const int length, const etype fx) { initialize(length, fx); } \
void initialize(const int length) { base_class::initialize(esize, length); } \
void initialize(const int length, const etype fx) { \
initialize(length); \
for (int i = 0; i < length; i++) ((etype*)_data)[i] = fx; \ for (int i = 0; i < length; i++) ((etype*)_data)[i] = fx; \
} \ } \
\ \
...@@ -158,15 +168,28 @@ class CHeapArray: public CHeapObj { ...@@ -158,15 +168,28 @@ class CHeapArray: public CHeapObj {
public: \ public: \
/* creation */ \ /* creation */ \
stack_name() : array_name() { _size = 0; } \ stack_name() : array_name() { _size = 0; } \
stack_name(const int size) : array_name(size){ _length = 0; _size = size; } \ stack_name(const int size) { initialize(size); } \
stack_name(const int size, const etype fx) : array_name(size, fx) { _size = size; } \ stack_name(const int size, const etype fx) { initialize(size, fx); } \
void initialize(const int size, const etype fx) { \
_size = size; \
array_name::initialize(size, fx); \
/* _length == size, allocation and size are the same */ \
} \
void initialize(const int size) { \
_size = size; \
array_name::initialize(size); \
_length = 0; /* reset length to zero; _size records the allocation */ \
} \
\ \
/* standard operations */ \ /* standard operations */ \
int size() const { return _size; } \ int size() const { return _size; } \
\ \
void push(const etype x) { \ int push(const etype x) { \
if (length() >= size()) expand(esize, length(), _size); \ int len = length(); \
((etype*)_data)[_length++] = x; \ if (len >= size()) expand(esize, len, _size); \
((etype*)_data)[len] = x; \
_length = len+1; \
return len; \
} \ } \
\ \
etype pop() { \ etype pop() { \
...@@ -235,7 +258,7 @@ class CHeapArray: public CHeapObj { ...@@ -235,7 +258,7 @@ class CHeapArray: public CHeapObj {
int capacity() const { return size(); } \ int capacity() const { return size(); } \
void clear() { truncate(0); } \ void clear() { truncate(0); } \
void trunc_to(const int length) { truncate(length); } \ void trunc_to(const int length) { truncate(length); } \
void append(const etype x) { push(x); } \ int append(const etype x) { return push(x); } \
void appendAll(const stack_name* stack) { push_all(stack); } \ void appendAll(const stack_name* stack) { push_all(stack); } \
etype last() const { return top(); } \ etype last() const { return top(); } \
}; \ }; \
......
...@@ -567,7 +567,7 @@ static void find(intptr_t x, bool print_pc) { ...@@ -567,7 +567,7 @@ static void find(intptr_t x, bool print_pc) {
} }
// the InlineCacheBuffer is using stubs generated into a buffer blob // the InlineCacheBuffer is using stubs generated into a buffer blob
if (InlineCacheBuffer::contains(addr)) { if (InlineCacheBuffer::contains(addr)) {
tty->print_cr(INTPTR_FORMAT "is pointing into InlineCacheBuffer", addr); tty->print_cr(INTPTR_FORMAT " is pointing into InlineCacheBuffer", addr);
return; return;
} }
VtableStub* v = VtableStubs::stub_containing(addr); VtableStub* v = VtableStubs::stub_containing(addr);
...@@ -595,7 +595,7 @@ static void find(intptr_t x, bool print_pc) { ...@@ -595,7 +595,7 @@ static void find(intptr_t x, bool print_pc) {
return; return;
} }
if (Universe::heap()->is_in_reserved(addr)) { if (Universe::heap()->is_in(addr)) {
HeapWord* p = Universe::heap()->block_start(addr); HeapWord* p = Universe::heap()->block_start(addr);
bool print = false; bool print = false;
// If we couldn't find it it just may mean that heap wasn't parseable // If we couldn't find it it just may mean that heap wasn't parseable
...@@ -621,24 +621,28 @@ static void find(intptr_t x, bool print_pc) { ...@@ -621,24 +621,28 @@ static void find(intptr_t x, bool print_pc) {
} }
return; return;
} }
} else if (Universe::heap()->is_in_reserved(addr)) {
tty->print_cr(INTPTR_FORMAT " is an unallocated location in the heap", addr);
return;
} }
if (JNIHandles::is_global_handle((jobject) addr)) { if (JNIHandles::is_global_handle((jobject) addr)) {
tty->print_cr(INTPTR_FORMAT "is a global jni handle", addr); tty->print_cr(INTPTR_FORMAT " is a global jni handle", addr);
return; return;
} }
if (JNIHandles::is_weak_global_handle((jobject) addr)) { if (JNIHandles::is_weak_global_handle((jobject) addr)) {
tty->print_cr(INTPTR_FORMAT "is a weak global jni handle", addr); tty->print_cr(INTPTR_FORMAT " is a weak global jni handle", addr);
return; return;
} }
if (JNIHandleBlock::any_contains((jobject) addr)) { if (JNIHandleBlock::any_contains((jobject) addr)) {
tty->print_cr(INTPTR_FORMAT "is a local jni handle", addr); tty->print_cr(INTPTR_FORMAT " is a local jni handle", addr);
return; return;
} }
for(JavaThread *thread = Threads::first(); thread; thread = thread->next()) { for(JavaThread *thread = Threads::first(); thread; thread = thread->next()) {
// Check for priviledge stack // Check for privilege stack
if (thread->privileged_stack_top() != NULL && thread->privileged_stack_top()->contains(addr)) { if (thread->privileged_stack_top() != NULL && thread->privileged_stack_top()->contains(addr)) {
tty->print_cr(INTPTR_FORMAT "is pointing into the priviledge stack for thread: " INTPTR_FORMAT, addr, thread); tty->print_cr(INTPTR_FORMAT " is pointing into the privilege stack for thread: " INTPTR_FORMAT, addr, thread);
return; return;
} }
// If the addr is a java thread print information about that. // If the addr is a java thread print information about that.
...@@ -659,7 +663,7 @@ static void find(intptr_t x, bool print_pc) { ...@@ -659,7 +663,7 @@ static void find(intptr_t x, bool print_pc) {
return; return;
} }
tty->print_cr(INTPTR_FORMAT "is pointing to unknown location", addr); tty->print_cr(INTPTR_FORMAT " is pointing to unknown location", addr);
} }
......
...@@ -111,6 +111,12 @@ class GenericGrowableArray : public ResourceObj { ...@@ -111,6 +111,12 @@ class GenericGrowableArray : public ResourceObj {
} }
void* raw_allocate(int elementSize); void* raw_allocate(int elementSize);
// some uses pass the Thread explicitly for speed (4990299 tuning)
void* raw_allocate(Thread* thread, int elementSize) {
assert(on_stack(), "fast ResourceObj path only");
return (void*)resource_allocate_bytes(thread, elementSize * _max);
}
}; };
template<class E> class GrowableArray : public GenericGrowableArray { template<class E> class GrowableArray : public GenericGrowableArray {
...@@ -121,6 +127,11 @@ template<class E> class GrowableArray : public GenericGrowableArray { ...@@ -121,6 +127,11 @@ template<class E> class GrowableArray : public GenericGrowableArray {
void raw_at_put_grow(int i, const E& p, const E& fill); void raw_at_put_grow(int i, const E& p, const E& fill);
void clear_and_deallocate(); void clear_and_deallocate();
public: public:
GrowableArray(Thread* thread, int initial_size) : GenericGrowableArray(initial_size, 0, false) {
_data = (E*)raw_allocate(thread, sizeof(E));
for (int i = 0; i < _max; i++) ::new ((void*)&_data[i]) E();
}
GrowableArray(int initial_size, bool C_heap = false) : GenericGrowableArray(initial_size, 0, C_heap) { GrowableArray(int initial_size, bool C_heap = false) : GenericGrowableArray(initial_size, 0, C_heap) {
_data = (E*)raw_allocate(sizeof(E)); _data = (E*)raw_allocate(sizeof(E));
for (int i = 0; i < _max; i++) ::new ((void*)&_data[i]) E(); for (int i = 0; i < _max; i++) ::new ((void*)&_data[i]) E();
...@@ -159,10 +170,12 @@ template<class E> class GrowableArray : public GenericGrowableArray { ...@@ -159,10 +170,12 @@ template<class E> class GrowableArray : public GenericGrowableArray {
void print(); void print();
void append(const E& elem) { int append(const E& elem) {
check_nesting(); check_nesting();
if (_len == _max) grow(_len); if (_len == _max) grow(_len);
_data[_len++] = elem; int idx = _len++;
_data[idx] = elem;
return idx;
} }
void append_if_missing(const E& elem) { void append_if_missing(const E& elem) {
......
...@@ -43,9 +43,11 @@ BasicHashtableEntry* BasicHashtable::new_entry(unsigned int hashValue) { ...@@ -43,9 +43,11 @@ BasicHashtableEntry* BasicHashtable::new_entry(unsigned int hashValue) {
entry = _free_list; entry = _free_list;
_free_list = _free_list->next(); _free_list = _free_list->next();
} else { } else {
const int block_size = 500; if (_first_free_entry + _entry_size >= _end_block) {
if (_first_free_entry == _end_block) { int block_size = MIN2(512, MAX2((int)_table_size / 2, (int)_number_of_entries));
int len = _entry_size * block_size; int len = _entry_size * block_size;
len = 1 << log2_intptr(len); // round down to power of 2
assert(len >= _entry_size, "");
_first_free_entry = NEW_C_HEAP_ARRAY(char, len); _first_free_entry = NEW_C_HEAP_ARRAY(char, len);
_end_block = _first_free_entry + len; _end_block = _first_free_entry + len;
} }
...@@ -53,6 +55,7 @@ BasicHashtableEntry* BasicHashtable::new_entry(unsigned int hashValue) { ...@@ -53,6 +55,7 @@ BasicHashtableEntry* BasicHashtable::new_entry(unsigned int hashValue) {
_first_free_entry += _entry_size; _first_free_entry += _entry_size;
} }
assert(_entry_size % HeapWordSize == 0, "");
entry->set_hash(hashValue); entry->set_hash(hashValue);
return entry; return entry;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册