Wed, 12 Nov 2008 23:26:45 -0800
6770949: minor tweaks before 6655638
Summary: minor cleanups & tuning of array.hpp, debug.cpp, growableArray.hpp, hashtable.cpp
Reviewed-by: kvn
1.1 --- a/src/share/vm/utilities/array.hpp Wed Nov 12 22:33:26 2008 -0800 1.2 +++ b/src/share/vm/utilities/array.hpp Wed Nov 12 23:26:45 2008 -0800 1.3 @@ -40,11 +40,18 @@ 1.4 _length = 0; 1.5 _data = NULL; 1.6 DEBUG_ONLY(init_nesting();) 1.7 + // client may call initialize, at most once 1.8 } 1.9 1.10 1.11 ResourceArray(size_t esize, int length) { 1.12 + DEBUG_ONLY(_data = NULL); 1.13 + initialize(esize, length); 1.14 + } 1.15 + 1.16 + void initialize(size_t esize, int length) { 1.17 assert(length >= 0, "illegal length"); 1.18 + assert(_data == NULL, "must be new object"); 1.19 _length = length; 1.20 _data = resource_allocate_bytes(esize * length); 1.21 DEBUG_ONLY(init_nesting();) 1.22 @@ -111,7 +118,10 @@ 1.23 /* creation */ \ 1.24 array_name() : base_class() {} \ 1.25 array_name(const int length) : base_class(esize, length) {} \ 1.26 - array_name(const int length, const etype fx) : base_class(esize, length) { \ 1.27 + array_name(const int length, const etype fx) { initialize(length, fx); } \ 1.28 + void initialize(const int length) { base_class::initialize(esize, length); } \ 1.29 + void initialize(const int length, const etype fx) { \ 1.30 + initialize(length); \ 1.31 for (int i = 0; i < length; i++) ((etype*)_data)[i] = fx; \ 1.32 } \ 1.33 \ 1.34 @@ -157,16 +167,29 @@ 1.35 \ 1.36 public: \ 1.37 /* creation */ \ 1.38 - stack_name() : array_name() { _size = 0; } \ 1.39 - stack_name(const int size) : array_name(size){ _length = 0; _size = size; } \ 1.40 - stack_name(const int size, const etype fx) : array_name(size, fx) { _size = size; } \ 1.41 + stack_name() : array_name() { _size = 0; } \ 1.42 + stack_name(const int size) { initialize(size); } \ 1.43 + stack_name(const int size, const etype fx) { initialize(size, fx); } \ 1.44 + void initialize(const int size, const etype fx) { \ 1.45 + _size = size; \ 1.46 + array_name::initialize(size, fx); \ 1.47 + /* _length == size, allocation and size are the same */ \ 1.48 + } \ 1.49 + void initialize(const int size) { \ 1.50 + _size = size; \ 1.51 + array_name::initialize(size); \ 1.52 + _length = 0; /* reset length to zero; _size records the allocation */ \ 1.53 + } \ 1.54 \ 1.55 /* standard operations */ \ 1.56 int size() const { return _size; } \ 1.57 \ 1.58 - void push(const etype x) { \ 1.59 - if (length() >= size()) expand(esize, length(), _size); \ 1.60 - ((etype*)_data)[_length++] = x; \ 1.61 + int push(const etype x) { \ 1.62 + int len = length(); \ 1.63 + if (len >= size()) expand(esize, len, _size); \ 1.64 + ((etype*)_data)[len] = x; \ 1.65 + _length = len+1; \ 1.66 + return len; \ 1.67 } \ 1.68 \ 1.69 etype pop() { \ 1.70 @@ -235,7 +258,7 @@ 1.71 int capacity() const { return size(); } \ 1.72 void clear() { truncate(0); } \ 1.73 void trunc_to(const int length) { truncate(length); } \ 1.74 - void append(const etype x) { push(x); } \ 1.75 + int append(const etype x) { return push(x); } \ 1.76 void appendAll(const stack_name* stack) { push_all(stack); } \ 1.77 etype last() const { return top(); } \ 1.78 }; \
2.1 --- a/src/share/vm/utilities/debug.cpp Wed Nov 12 22:33:26 2008 -0800 2.2 +++ b/src/share/vm/utilities/debug.cpp Wed Nov 12 23:26:45 2008 -0800 2.3 @@ -567,7 +567,7 @@ 2.4 } 2.5 // the InlineCacheBuffer is using stubs generated into a buffer blob 2.6 if (InlineCacheBuffer::contains(addr)) { 2.7 - tty->print_cr(INTPTR_FORMAT "is pointing into InlineCacheBuffer", addr); 2.8 + tty->print_cr(INTPTR_FORMAT " is pointing into InlineCacheBuffer", addr); 2.9 return; 2.10 } 2.11 VtableStub* v = VtableStubs::stub_containing(addr); 2.12 @@ -595,7 +595,7 @@ 2.13 return; 2.14 } 2.15 2.16 - if (Universe::heap()->is_in_reserved(addr)) { 2.17 + if (Universe::heap()->is_in(addr)) { 2.18 HeapWord* p = Universe::heap()->block_start(addr); 2.19 bool print = false; 2.20 // If we couldn't find it it just may mean that heap wasn't parseable 2.21 @@ -621,24 +621,28 @@ 2.22 } 2.23 return; 2.24 } 2.25 + } else if (Universe::heap()->is_in_reserved(addr)) { 2.26 + tty->print_cr(INTPTR_FORMAT " is an unallocated location in the heap", addr); 2.27 + return; 2.28 } 2.29 + 2.30 if (JNIHandles::is_global_handle((jobject) addr)) { 2.31 - tty->print_cr(INTPTR_FORMAT "is a global jni handle", addr); 2.32 + tty->print_cr(INTPTR_FORMAT " is a global jni handle", addr); 2.33 return; 2.34 } 2.35 if (JNIHandles::is_weak_global_handle((jobject) addr)) { 2.36 - tty->print_cr(INTPTR_FORMAT "is a weak global jni handle", addr); 2.37 + tty->print_cr(INTPTR_FORMAT " is a weak global jni handle", addr); 2.38 return; 2.39 } 2.40 if (JNIHandleBlock::any_contains((jobject) addr)) { 2.41 - tty->print_cr(INTPTR_FORMAT "is a local jni handle", addr); 2.42 + tty->print_cr(INTPTR_FORMAT " is a local jni handle", addr); 2.43 return; 2.44 } 2.45 2.46 for(JavaThread *thread = Threads::first(); thread; thread = thread->next()) { 2.47 - // Check for priviledge stack 2.48 + // Check for privilege stack 2.49 if (thread->privileged_stack_top() != NULL && thread->privileged_stack_top()->contains(addr)) { 2.50 - tty->print_cr(INTPTR_FORMAT "is pointing into the priviledge stack for thread: " INTPTR_FORMAT, addr, thread); 2.51 + tty->print_cr(INTPTR_FORMAT " is pointing into the privilege stack for thread: " INTPTR_FORMAT, addr, thread); 2.52 return; 2.53 } 2.54 // If the addr is a java thread print information about that. 2.55 @@ -659,7 +663,7 @@ 2.56 return; 2.57 } 2.58 2.59 - tty->print_cr(INTPTR_FORMAT "is pointing to unknown location", addr); 2.60 + tty->print_cr(INTPTR_FORMAT " is pointing to unknown location", addr); 2.61 } 2.62 2.63
3.1 --- a/src/share/vm/utilities/growableArray.hpp Wed Nov 12 22:33:26 2008 -0800 3.2 +++ b/src/share/vm/utilities/growableArray.hpp Wed Nov 12 23:26:45 2008 -0800 3.3 @@ -111,6 +111,12 @@ 3.4 } 3.5 3.6 void* raw_allocate(int elementSize); 3.7 + 3.8 + // some uses pass the Thread explicitly for speed (4990299 tuning) 3.9 + void* raw_allocate(Thread* thread, int elementSize) { 3.10 + assert(on_stack(), "fast ResourceObj path only"); 3.11 + return (void*)resource_allocate_bytes(thread, elementSize * _max); 3.12 + } 3.13 }; 3.14 3.15 template<class E> class GrowableArray : public GenericGrowableArray { 3.16 @@ -121,6 +127,11 @@ 3.17 void raw_at_put_grow(int i, const E& p, const E& fill); 3.18 void clear_and_deallocate(); 3.19 public: 3.20 + GrowableArray(Thread* thread, int initial_size) : GenericGrowableArray(initial_size, 0, false) { 3.21 + _data = (E*)raw_allocate(thread, sizeof(E)); 3.22 + for (int i = 0; i < _max; i++) ::new ((void*)&_data[i]) E(); 3.23 + } 3.24 + 3.25 GrowableArray(int initial_size, bool C_heap = false) : GenericGrowableArray(initial_size, 0, C_heap) { 3.26 _data = (E*)raw_allocate(sizeof(E)); 3.27 for (int i = 0; i < _max; i++) ::new ((void*)&_data[i]) E(); 3.28 @@ -159,10 +170,12 @@ 3.29 3.30 void print(); 3.31 3.32 - void append(const E& elem) { 3.33 + int append(const E& elem) { 3.34 check_nesting(); 3.35 if (_len == _max) grow(_len); 3.36 - _data[_len++] = elem; 3.37 + int idx = _len++; 3.38 + _data[idx] = elem; 3.39 + return idx; 3.40 } 3.41 3.42 void append_if_missing(const E& elem) {
4.1 --- a/src/share/vm/utilities/hashtable.cpp Wed Nov 12 22:33:26 2008 -0800 4.2 +++ b/src/share/vm/utilities/hashtable.cpp Wed Nov 12 23:26:45 2008 -0800 4.3 @@ -43,9 +43,11 @@ 4.4 entry = _free_list; 4.5 _free_list = _free_list->next(); 4.6 } else { 4.7 - const int block_size = 500; 4.8 - if (_first_free_entry == _end_block) { 4.9 + if (_first_free_entry + _entry_size >= _end_block) { 4.10 + int block_size = MIN2(512, MAX2((int)_table_size / 2, (int)_number_of_entries)); 4.11 int len = _entry_size * block_size; 4.12 + len = 1 << log2_intptr(len); // round down to power of 2 4.13 + assert(len >= _entry_size, ""); 4.14 _first_free_entry = NEW_C_HEAP_ARRAY(char, len); 4.15 _end_block = _first_free_entry + len; 4.16 } 4.17 @@ -53,6 +55,7 @@ 4.18 _first_free_entry += _entry_size; 4.19 } 4.20 4.21 + assert(_entry_size % HeapWordSize == 0, ""); 4.22 entry->set_hash(hashValue); 4.23 return entry; 4.24 }