# HG changeset patch # User kvn # Date 1394747821 25200 # Node ID bbfbe9b06038b17909c2b37847bfaf6ac2fb2772 # Parent fd1b9f02cc91475bfb5e37ccff10d80c749e3fb4# Parent d8a0bb6f62a5ca1219db95dd2b86364d0ab433e9 Merge diff -r fd1b9f02cc91 -r bbfbe9b06038 .hgtags --- a/.hgtags Mon Mar 10 12:58:02 2014 +0100 +++ b/.hgtags Thu Mar 13 14:57:01 2014 -0700 @@ -420,9 +420,15 @@ 35038da7bb9ddd367a0a6bf926dfb281aee1d554 jdk8-b127 874c0b4a946c362bbf20d37c2a564b39093152e6 jdk8-b128 cb39165c4a65bbff8db356df411e762f9e5423b8 jdk8-b129 +1dbaf664a611e5d9cab6d1be42537b67d0d05f94 jdk8-b130 +b5e7ebfe185cb4c2eeb8a919025fc6a26be2fcef jdk8-b131 +9f9179e8f0cfe74c08f3716cf3c38e21e1de4c4a hs25-b70 +0c94c41dcd70e9a9b4d96e31275afd5a73daa72d jdk8-b132 412d3b5fe90e54c0ff9d9ac7374b98607c561d5a hs25.20-b01 4638c4d7ff106db0f29ef7f18b128dd7e69bc470 hs25.20-b02 e56d11f8cc2158d4280f80e56d196193349c150a hs25.20-b03 757fe22ae90681e2b6cff50699c5abbe2563dd2c jdk8u20-b01 9c2ddd17626e375554044a3082a6dc5e68184ed9 jdk8u20-b02 ecf3678d5736a645aea893b525a9eb5fa1a8e072 hs25.20-b04 +51e1bb81df8680bd237630323de5e0704fb25607 jdk8u20-b03 +54436d3b2a915ff50a8d6b34f61d5afb45be7bb6 hs25.20-b05 diff -r fd1b9f02cc91 -r bbfbe9b06038 agent/src/share/classes/sun/jvm/hotspot/utilities/Hashtable.java --- a/agent/src/share/classes/sun/jvm/hotspot/utilities/Hashtable.java Mon Mar 10 12:58:02 2014 +0100 +++ b/agent/src/share/classes/sun/jvm/hotspot/utilities/Hashtable.java Thu Mar 13 14:57:01 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -61,8 +61,9 @@ long h = 0; int s = 0; int len = buf.length; + // Emulate the unsigned int in java_lang_String::hash_code while (len-- > 0) { - h = 31*h + (0xFFL & buf[s]); + h = 31*h + (0xFFFFFFFFL & buf[s]); s++; } return h & 0xFFFFFFFFL; diff -r fd1b9f02cc91 -r bbfbe9b06038 make/excludeSrc.make --- a/make/excludeSrc.make Mon Mar 10 12:58:02 2014 +0100 +++ b/make/excludeSrc.make Thu Mar 13 14:57:01 2014 -0700 @@ -86,7 +86,7 @@ concurrentMark.cpp concurrentMarkThread.cpp dirtyCardQueue.cpp g1AllocRegion.cpp \ g1BlockOffsetTable.cpp g1CardCounts.cpp g1CollectedHeap.cpp g1CollectorPolicy.cpp \ g1ErgoVerbose.cpp g1GCPhaseTimes.cpp g1HRPrinter.cpp g1HotCardCache.cpp g1Log.cpp \ - g1MMUTracker.cpp g1MarkSweep.cpp g1MemoryPool.cpp g1MonitoringSupport.cpp \ + g1MMUTracker.cpp g1MarkSweep.cpp g1MemoryPool.cpp g1MonitoringSupport.cpp g1OopClosures.cpp \ g1RemSet.cpp g1RemSetSummary.cpp g1SATBCardTableModRefBS.cpp g1_globals.cpp heapRegion.cpp \ g1BiasedArray.cpp heapRegionRemSet.cpp heapRegionSeq.cpp heapRegionSet.cpp heapRegionSets.cpp \ ptrQueue.cpp satbQueue.cpp sparsePRT.cpp survRateGroup.cpp vm_operations_g1.cpp \ diff -r fd1b9f02cc91 -r bbfbe9b06038 make/hotspot_version --- a/make/hotspot_version Mon Mar 10 12:58:02 2014 +0100 +++ b/make/hotspot_version Thu Mar 13 14:57:01 2014 -0700 @@ -35,7 +35,7 @@ HS_MAJOR_VER=25 HS_MINOR_VER=20 -HS_BUILD_NUMBER=04 +HS_BUILD_NUMBER=05 JDK_MAJOR_VER=1 JDK_MINOR_VER=8 diff -r fd1b9f02cc91 -r bbfbe9b06038 src/cpu/sparc/vm/vm_version_sparc.hpp --- a/src/cpu/sparc/vm/vm_version_sparc.hpp Mon Mar 10 12:58:02 2014 +0100 +++ b/src/cpu/sparc/vm/vm_version_sparc.hpp Thu Mar 13 14:57:01 2014 -0700 @@ -49,7 +49,8 @@ M_family = 15, T_family = 16, T1_model = 17, - aes_instructions = 18 + sparc5_instructions = 18, + aes_instructions = 19 }; enum Feature_Flag_Set { @@ -74,6 +75,7 @@ M_family_m = 1 << M_family, T_family_m = 1 << T_family, T1_model_m = 1 << T1_model, + sparc5_instructions_m = 1 << sparc5_instructions, aes_instructions_m = 1 << aes_instructions, generic_v8_m = v8_instructions_m | hardware_mul32_m | hardware_div32_m | hardware_fsmuld_m, @@ -125,6 +127,7 @@ static bool has_vis3() { return (_features & vis3_instructions_m) != 0; } static bool has_blk_init() { return (_features & blk_init_instructions_m) != 0; } static bool has_cbcond() { return (_features & cbcond_instructions_m) != 0; } + static bool has_sparc5_instr() { return (_features & sparc5_instructions_m) != 0; } static bool has_aes() { return (_features & aes_instructions_m) != 0; } static bool supports_compare_and_exchange() @@ -136,6 +139,7 @@ static bool is_M_series() { return is_M_family(_features); } static bool is_T4() { return is_T_family(_features) && has_cbcond(); } + static bool is_T7() { return is_T_family(_features) && has_sparc5_instr(); } // Fujitsu SPARC64 static bool is_sparc64() { return (_features & sparc64_family_m) != 0; } @@ -155,7 +159,7 @@ static const char* cpu_features() { return _features_str; } static intx prefetch_data_size() { - return is_T4() ? 32 : 64; // default prefetch block size on sparc + return is_T4() && !is_T7() ? 32 : 64; // default prefetch block size on sparc } // Prefetch diff -r fd1b9f02cc91 -r bbfbe9b06038 src/os/bsd/vm/os_bsd.cpp --- a/src/os/bsd/vm/os_bsd.cpp Mon Mar 10 12:58:02 2014 +0100 +++ b/src/os/bsd/vm/os_bsd.cpp Thu Mar 13 14:57:01 2014 -0700 @@ -1557,6 +1557,17 @@ } #endif /* !__APPLE__ */ +void* os::get_default_process_handle() { +#ifdef __APPLE__ + // MacOS X needs to use RTLD_FIRST instead of RTLD_LAZY + // to avoid finding unexpected symbols on second (or later) + // loads of a library. + return (void*)::dlopen(NULL, RTLD_FIRST); +#else + return (void*)::dlopen(NULL, RTLD_LAZY); +#endif +} + // XXX: Do we need a lock around this as per Linux? void* os::dll_lookup(void* handle, const char* name) { return dlsym(handle, name); diff -r fd1b9f02cc91 -r bbfbe9b06038 src/os/linux/vm/os_linux.cpp --- a/src/os/linux/vm/os_linux.cpp Mon Mar 10 12:58:02 2014 +0100 +++ b/src/os/linux/vm/os_linux.cpp Thu Mar 13 14:57:01 2014 -0700 @@ -2109,6 +2109,9 @@ return res; } +void* os::get_default_process_handle() { + return (void*)::dlopen(NULL, RTLD_LAZY); +} static bool _print_ascii_file(const char* filename, outputStream* st) { int fd = ::open(filename, O_RDONLY); diff -r fd1b9f02cc91 -r bbfbe9b06038 src/os/posix/vm/os_posix.cpp --- a/src/os/posix/vm/os_posix.cpp Mon Mar 10 12:58:02 2014 +0100 +++ b/src/os/posix/vm/os_posix.cpp Thu Mar 13 14:57:01 2014 -0700 @@ -270,10 +270,6 @@ return ::fdopen(fd, mode); } -void* os::get_default_process_handle() { - return (void*)::dlopen(NULL, RTLD_LAZY); -} - // Builds a platform dependent Agent_OnLoad_ function name // which is used to find statically linked in agents. // Parameters: diff -r fd1b9f02cc91 -r bbfbe9b06038 src/os/solaris/vm/os_solaris.cpp --- a/src/os/solaris/vm/os_solaris.cpp Mon Mar 10 12:58:02 2014 +0100 +++ b/src/os/solaris/vm/os_solaris.cpp Thu Mar 13 14:57:01 2014 -0700 @@ -2146,6 +2146,10 @@ return dlsym(handle, name); } +void* os::get_default_process_handle() { + return (void*)::dlopen(NULL, RTLD_LAZY); +} + int os::stat(const char *path, struct stat *sbuf) { char pathbuf[MAX_PATH]; if (strlen(path) > MAX_PATH - 1) { diff -r fd1b9f02cc91 -r bbfbe9b06038 src/os_cpu/solaris_sparc/vm/vm_version_solaris_sparc.cpp --- a/src/os_cpu/solaris_sparc/vm/vm_version_solaris_sparc.cpp Mon Mar 10 12:58:02 2014 +0100 +++ b/src/os_cpu/solaris_sparc/vm/vm_version_solaris_sparc.cpp Thu Mar 13 14:57:01 2014 -0700 @@ -75,13 +75,19 @@ do_sysinfo(SI_ARCHITECTURE_64, "sparcv9", &features, generic_v9_m); // Extract valid instruction set extensions. - uint_t av; - uint_t avn = os::Solaris::getisax(&av, 1); - assert(avn == 1, "should only return one av"); + uint_t avs[2]; + uint_t avn = os::Solaris::getisax(avs, 2); + assert(avn <= 2, "should return two or less av's"); + uint_t av = avs[0]; #ifndef PRODUCT - if (PrintMiscellaneous && Verbose) - tty->print_cr("getisax(2) returned: " PTR32_FORMAT, av); + if (PrintMiscellaneous && Verbose) { + tty->print("getisax(2) returned: " PTR32_FORMAT, av); + if (avn > 1) { + tty->print(", " PTR32_FORMAT, avs[1]); + } + tty->cr(); + } #endif if (av & AV_SPARC_MUL32) features |= hardware_mul32_m; @@ -91,6 +97,13 @@ if (av & AV_SPARC_POPC) features |= hardware_popc_m; if (av & AV_SPARC_VIS) features |= vis1_instructions_m; if (av & AV_SPARC_VIS2) features |= vis2_instructions_m; + if (avn > 1) { + uint_t av2 = avs[1]; +#ifndef AV2_SPARC_SPARC5 +#define AV2_SPARC_SPARC5 0x00000008 /* The 29 new fp and sub instructions */ +#endif + if (av2 & AV2_SPARC_SPARC5) features |= sparc5_instructions_m; + } // Next values are not defined before Solaris 10 // but Solaris 8 is used for jdk6 update builds. diff -r fd1b9f02cc91 -r bbfbe9b06038 src/share/vm/ci/ciMethod.cpp --- a/src/share/vm/ci/ciMethod.cpp Mon Mar 10 12:58:02 2014 +0100 +++ b/src/share/vm/ci/ciMethod.cpp Thu Mar 13 14:57:01 2014 -0700 @@ -724,6 +724,11 @@ VM_ENTRY_MARK; + // Disable CHA for default methods for now + if (root_m->get_Method()->is_default_method()) { + return NULL; + } + methodHandle target; { MutexLocker locker(Compile_lock); diff -r fd1b9f02cc91 -r bbfbe9b06038 src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp Mon Mar 10 12:58:02 2014 +0100 +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp Thu Mar 13 14:57:01 2014 -0700 @@ -1730,8 +1730,8 @@ _dictionary->return_chunk(chunk); #ifndef PRODUCT if (CMSCollector::abstract_state() != CMSCollector::Sweeping) { - TreeChunk* tc = TreeChunk::as_TreeChunk(chunk); - TreeList* tl = tc->list(); + TreeChunk >* tc = TreeChunk >::as_TreeChunk(chunk); + TreeList >* tl = tc->list(); tl->verify_stats(); } #endif // PRODUCT @@ -2541,10 +2541,10 @@ #ifndef PRODUCT void CompactibleFreeListSpace::check_free_list_consistency() const { - assert((TreeChunk::min_size() <= IndexSetSize), + assert((TreeChunk >::min_size() <= IndexSetSize), "Some sizes can't be allocated without recourse to" " linear allocation buffers"); - assert((TreeChunk::min_size()*HeapWordSize == sizeof(TreeChunk)), + assert((TreeChunk >::min_size()*HeapWordSize == sizeof(TreeChunk >)), "else MIN_TREE_CHUNK_SIZE is wrong"); assert(IndexSetStart != 0, "IndexSetStart not initialized"); assert(IndexSetStride != 0, "IndexSetStride not initialized"); diff -r fd1b9f02cc91 -r bbfbe9b06038 src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp --- a/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp Mon Mar 10 12:58:02 2014 +0100 +++ b/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp Thu Mar 13 14:57:01 2014 -0700 @@ -4539,7 +4539,7 @@ G1ParGCAllocBuffer::G1ParGCAllocBuffer(size_t gclab_word_size) : ParGCAllocBuffer(gclab_word_size), _retired(false) { } -G1ParScanThreadState::G1ParScanThreadState(G1CollectedHeap* g1h, uint queue_num) +G1ParScanThreadState::G1ParScanThreadState(G1CollectedHeap* g1h, uint queue_num, ReferenceProcessor* rp) : _g1h(g1h), _refs(g1h->task_queue(queue_num)), _dcq(&g1h->dirty_card_queue_set()), @@ -4549,7 +4549,7 @@ _term_attempts(0), _surviving_alloc_buffer(g1h->desired_plab_sz(GCAllocForSurvived)), _tenured_alloc_buffer(g1h->desired_plab_sz(GCAllocForTenured)), - _age_table(false), + _age_table(false), _scanner(g1h, this, rp), _strong_roots_time(0), _term_time(0), _alloc_buffer_waste(0), _undo_waste(0) { // we allocate G1YoungSurvRateNumRegions plus one entries, since @@ -4658,14 +4658,10 @@ G1ParClosureSuper::G1ParClosureSuper(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state) : - _g1(g1), _g1_rem(_g1->g1_rem_set()), _cm(_g1->concurrent_mark()), - _par_scan_state(par_scan_state), - _worker_id(par_scan_state->queue_num()), - _during_initial_mark(_g1->g1_policy()->during_initial_mark_pause()), - _mark_in_progress(_g1->mark_in_progress()) { } - -template -void G1ParCopyClosure::mark_object(oop obj) { + _g1(g1), _par_scan_state(par_scan_state), + _worker_id(par_scan_state->queue_num()) { } + +void G1ParCopyHelper::mark_object(oop obj) { #ifdef ASSERT HeapRegion* hr = _g1->heap_region_containing(obj); assert(hr != NULL, "sanity"); @@ -4676,9 +4672,7 @@ _cm->grayRoot(obj, (size_t) obj->size(), _worker_id); } -template -void G1ParCopyClosure - ::mark_forwarded_object(oop from_obj, oop to_obj) { +void G1ParCopyHelper::mark_forwarded_object(oop from_obj, oop to_obj) { #ifdef ASSERT assert(from_obj->is_forwarded(), "from obj should be forwarded"); assert(from_obj->forwardee() == to_obj, "to obj should be the forwardee"); @@ -4700,27 +4694,25 @@ _cm->grayRoot(to_obj, (size_t) from_obj->size(), _worker_id); } -template -oop G1ParCopyClosure - ::copy_to_survivor_space(oop old) { +oop G1ParScanThreadState::copy_to_survivor_space(oop const old) { size_t word_sz = old->size(); - HeapRegion* from_region = _g1->heap_region_containing_raw(old); + HeapRegion* from_region = _g1h->heap_region_containing_raw(old); // +1 to make the -1 indexes valid... int young_index = from_region->young_index_in_cset()+1; assert( (from_region->is_young() && young_index > 0) || (!from_region->is_young() && young_index == 0), "invariant" ); - G1CollectorPolicy* g1p = _g1->g1_policy(); + G1CollectorPolicy* g1p = _g1h->g1_policy(); markOop m = old->mark(); int age = m->has_displaced_mark_helper() ? m->displaced_mark_helper()->age() : m->age(); GCAllocPurpose alloc_purpose = g1p->evacuation_destination(from_region, age, word_sz); - HeapWord* obj_ptr = _par_scan_state->allocate(alloc_purpose, word_sz); + HeapWord* obj_ptr = allocate(alloc_purpose, word_sz); #ifndef PRODUCT // Should this evacuation fail? - if (_g1->evacuation_should_fail()) { + if (_g1h->evacuation_should_fail()) { if (obj_ptr != NULL) { - _par_scan_state->undo_allocation(alloc_purpose, obj_ptr, word_sz); + undo_allocation(alloc_purpose, obj_ptr, word_sz); obj_ptr = NULL; } } @@ -4729,7 +4721,7 @@ if (obj_ptr == NULL) { // This will either forward-to-self, or detect that someone else has // installed a forwarding pointer. - return _g1->handle_evacuation_failure_par(_par_scan_state, old); + return _g1h->handle_evacuation_failure_par(this, old); } oop obj = oop(obj_ptr); @@ -4762,12 +4754,12 @@ m = m->incr_age(); obj->set_mark(m); } - _par_scan_state->age_table()->add(obj, word_sz); + age_table()->add(obj, word_sz); } else { obj->set_mark(m); } - size_t* surv_young_words = _par_scan_state->surviving_young_words(); + size_t* surv_young_words = surviving_young_words(); surv_young_words[young_index] += word_sz; if (obj->is_objArray() && arrayOop(obj)->length() >= ParGCArrayScanChunk) { @@ -4776,15 +4768,15 @@ // length field of the from-space object. arrayOop(obj)->set_length(0); oop* old_p = set_partial_array_mask(old); - _par_scan_state->push_on_queue(old_p); + push_on_queue(old_p); } else { // No point in using the slower heap_region_containing() method, // given that we know obj is in the heap. - _scanner.set_region(_g1->heap_region_containing_raw(obj)); + _scanner.set_region(_g1h->heap_region_containing_raw(obj)); obj->oop_iterate_backwards(&_scanner); } } else { - _par_scan_state->undo_allocation(alloc_purpose, obj_ptr, word_sz); + undo_allocation(alloc_purpose, obj_ptr, word_sz); obj = forward_ptr; } return obj; @@ -4799,19 +4791,23 @@ template template -void G1ParCopyClosure -::do_oop_work(T* p) { - oop obj = oopDesc::load_decode_heap_oop(p); +void G1ParCopyClosure::do_oop_work(T* p) { + T heap_oop = oopDesc::load_heap_oop(p); + + if (oopDesc::is_null(heap_oop)) { + return; + } + + oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); assert(_worker_id == _par_scan_state->queue_num(), "sanity"); - // here the null check is implicit in the cset_fast_test() test if (_g1->in_cset_fast_test(obj)) { oop forwardee; if (obj->is_forwarded()) { forwardee = obj->forwardee(); } else { - forwardee = copy_to_survivor_space(obj); + forwardee = _par_scan_state->copy_to_survivor_space(obj); } assert(forwardee != NULL, "forwardee should not be NULL"); oopDesc::encode_store_heap_oop(p, forwardee); @@ -4828,12 +4824,12 @@ // The object is not in collection set. If we're a root scanning // closure during an initial mark pause (i.e. do_mark_object will // be true) then attempt to mark the object. - if (do_mark_object && _g1->is_in_g1_reserved(obj)) { + if (do_mark_object) { mark_object(obj); } } - if (barrier == G1BarrierEvac && obj != NULL) { + if (barrier == G1BarrierEvac) { _par_scan_state->update_rs(_from, p, _worker_id); } } @@ -5030,7 +5026,7 @@ ReferenceProcessor* rp = _g1h->ref_processor_stw(); - G1ParScanThreadState pss(_g1h, worker_id); + G1ParScanThreadState pss(_g1h, worker_id, rp); G1ParScanHeapEvacClosure scan_evac_cl(_g1h, &pss, rp); G1ParScanHeapEvacFailureClosure evac_failure_cl(_g1h, &pss, rp); G1ParScanPartialArrayClosure partial_scan_cl(_g1h, &pss, rp); @@ -5473,7 +5469,7 @@ G1STWIsAliveClosure is_alive(_g1h); - G1ParScanThreadState pss(_g1h, worker_id); + G1ParScanThreadState pss(_g1h, worker_id, NULL); G1ParScanHeapEvacClosure scan_evac_cl(_g1h, &pss, NULL); G1ParScanHeapEvacFailureClosure evac_failure_cl(_g1h, &pss, NULL); @@ -5585,7 +5581,7 @@ ResourceMark rm; HandleMark hm; - G1ParScanThreadState pss(_g1h, worker_id); + G1ParScanThreadState pss(_g1h, worker_id, NULL); G1ParScanHeapEvacClosure scan_evac_cl(_g1h, &pss, NULL); G1ParScanHeapEvacFailureClosure evac_failure_cl(_g1h, &pss, NULL); G1ParScanPartialArrayClosure partial_scan_cl(_g1h, &pss, NULL); @@ -5711,7 +5707,7 @@ // JNI refs. // Use only a single queue for this PSS. - G1ParScanThreadState pss(this, 0); + G1ParScanThreadState pss(this, 0, NULL); // We do not embed a reference processor in the copying/scanning // closures while we're actually processing the discovered diff -r fd1b9f02cc91 -r bbfbe9b06038 src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp --- a/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp Mon Mar 10 12:58:02 2014 +0100 +++ b/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp Thu Mar 13 14:57:01 2014 -0700 @@ -606,6 +606,11 @@ // may not be a humongous - it must fit into a single heap region. HeapWord* par_allocate_during_gc(GCAllocPurpose purpose, size_t word_size); + HeapWord* allocate_during_gc_slow(GCAllocPurpose purpose, + HeapRegion* alloc_region, + bool par, + size_t word_size); + // Ensure that no further allocations can happen in "r", bearing in mind // that parallel threads might be attempting allocations. void par_allocate_remaining_space(HeapRegion* r); @@ -698,23 +703,20 @@ } // This is a fast test on whether a reference points into the - // collection set or not. It does not assume that the reference - // points into the heap; if it doesn't, it will return false. + // collection set or not. Assume that the reference + // points into the heap. bool in_cset_fast_test(oop obj) { assert(_in_cset_fast_test != NULL, "sanity"); - if (_g1_committed.contains((HeapWord*) obj)) { - // no need to subtract the bottom of the heap from obj, - // _in_cset_fast_test is biased - uintx index = cast_from_oop(obj) >> HeapRegion::LogOfHRGrainBytes; - bool ret = _in_cset_fast_test[index]; - // let's make sure the result is consistent with what the slower - // test returns - assert( ret || !obj_in_cs(obj), "sanity"); - assert(!ret || obj_in_cs(obj), "sanity"); - return ret; - } else { - return false; - } + assert(_g1_committed.contains((HeapWord*) obj), err_msg("Given reference outside of heap, is "PTR_FORMAT, (HeapWord*)obj)); + // no need to subtract the bottom of the heap from obj, + // _in_cset_fast_test is biased + uintx index = cast_from_oop(obj) >> HeapRegion::LogOfHRGrainBytes; + bool ret = _in_cset_fast_test[index]; + // let's make sure the result is consistent with what the slower + // test returns + assert( ret || !obj_in_cs(obj), "sanity"); + assert(!ret || obj_in_cs(obj), "sanity"); + return ret; } void clear_cset_fast_test() { @@ -1786,95 +1788,6 @@ ParGCAllocBuffer::retire(end_of_gc, retain); _retired = true; } - - bool is_retired() { - return _retired; - } -}; - -class G1ParGCAllocBufferContainer { -protected: - static int const _priority_max = 2; - G1ParGCAllocBuffer* _priority_buffer[_priority_max]; - -public: - G1ParGCAllocBufferContainer(size_t gclab_word_size) { - for (int pr = 0; pr < _priority_max; ++pr) { - _priority_buffer[pr] = new G1ParGCAllocBuffer(gclab_word_size); - } - } - - ~G1ParGCAllocBufferContainer() { - for (int pr = 0; pr < _priority_max; ++pr) { - assert(_priority_buffer[pr]->is_retired(), "alloc buffers should all retire at this point."); - delete _priority_buffer[pr]; - } - } - - HeapWord* allocate(size_t word_sz) { - HeapWord* obj; - for (int pr = 0; pr < _priority_max; ++pr) { - obj = _priority_buffer[pr]->allocate(word_sz); - if (obj != NULL) return obj; - } - return obj; - } - - bool contains(void* addr) { - for (int pr = 0; pr < _priority_max; ++pr) { - if (_priority_buffer[pr]->contains(addr)) return true; - } - return false; - } - - void undo_allocation(HeapWord* obj, size_t word_sz) { - bool finish_undo; - for (int pr = 0; pr < _priority_max; ++pr) { - if (_priority_buffer[pr]->contains(obj)) { - _priority_buffer[pr]->undo_allocation(obj, word_sz); - finish_undo = true; - } - } - if (!finish_undo) ShouldNotReachHere(); - } - - size_t words_remaining() { - size_t result = 0; - for (int pr = 0; pr < _priority_max; ++pr) { - result += _priority_buffer[pr]->words_remaining(); - } - return result; - } - - size_t words_remaining_in_retired_buffer() { - G1ParGCAllocBuffer* retired = _priority_buffer[0]; - return retired->words_remaining(); - } - - void flush_stats_and_retire(PLABStats* stats, bool end_of_gc, bool retain) { - for (int pr = 0; pr < _priority_max; ++pr) { - _priority_buffer[pr]->flush_stats_and_retire(stats, end_of_gc, retain); - } - } - - void update(bool end_of_gc, bool retain, HeapWord* buf, size_t word_sz) { - G1ParGCAllocBuffer* retired_and_set = _priority_buffer[0]; - retired_and_set->retire(end_of_gc, retain); - retired_and_set->set_buf(buf); - retired_and_set->set_word_size(word_sz); - adjust_priority_order(); - } - -private: - void adjust_priority_order() { - G1ParGCAllocBuffer* retired_and_set = _priority_buffer[0]; - - int last = _priority_max - 1; - for (int pr = 0; pr < last; ++pr) { - _priority_buffer[pr] = _priority_buffer[pr + 1]; - } - _priority_buffer[last] = retired_and_set; - } }; class G1ParScanThreadState : public StackObj { @@ -1885,11 +1798,13 @@ G1SATBCardTableModRefBS* _ct_bs; G1RemSet* _g1_rem; - G1ParGCAllocBufferContainer _surviving_alloc_buffer; - G1ParGCAllocBufferContainer _tenured_alloc_buffer; - G1ParGCAllocBufferContainer* _alloc_buffers[GCAllocPurposeCount]; + G1ParGCAllocBuffer _surviving_alloc_buffer; + G1ParGCAllocBuffer _tenured_alloc_buffer; + G1ParGCAllocBuffer* _alloc_buffers[GCAllocPurposeCount]; ageTable _age_table; + G1ParScanClosure _scanner; + size_t _alloc_buffer_waste; size_t _undo_waste; @@ -1942,7 +1857,7 @@ } public: - G1ParScanThreadState(G1CollectedHeap* g1h, uint queue_num); + G1ParScanThreadState(G1CollectedHeap* g1h, uint queue_num, ReferenceProcessor* rp); ~G1ParScanThreadState() { FREE_C_HEAP_ARRAY(size_t, _surviving_young_words_base, mtGC); @@ -1951,7 +1866,7 @@ RefToScanQueue* refs() { return _refs; } ageTable* age_table() { return &_age_table; } - G1ParGCAllocBufferContainer* alloc_buffer(GCAllocPurpose purpose) { + G1ParGCAllocBuffer* alloc_buffer(GCAllocPurpose purpose) { return _alloc_buffers[purpose]; } @@ -1981,13 +1896,15 @@ HeapWord* obj = NULL; size_t gclab_word_size = _g1h->desired_plab_sz(purpose); if (word_sz * 100 < gclab_word_size * ParallelGCBufferWastePct) { - G1ParGCAllocBufferContainer* alloc_buf = alloc_buffer(purpose); + G1ParGCAllocBuffer* alloc_buf = alloc_buffer(purpose); + add_to_alloc_buffer_waste(alloc_buf->words_remaining()); + alloc_buf->retire(false /* end_of_gc */, false /* retain */); HeapWord* buf = _g1h->par_allocate_during_gc(purpose, gclab_word_size); if (buf == NULL) return NULL; // Let caller handle allocation failure. - - add_to_alloc_buffer_waste(alloc_buf->words_remaining_in_retired_buffer()); - alloc_buf->update(false /* end_of_gc */, false /* retain */, buf, gclab_word_size); + // Otherwise. + alloc_buf->set_word_size(gclab_word_size); + alloc_buf->set_buf(buf); obj = alloc_buf->allocate(word_sz); assert(obj != NULL, "buffer was definitely big enough..."); @@ -2077,6 +1994,8 @@ } } + oop copy_to_survivor_space(oop const obj); + template void deal_with_reference(T* ref_to_scan) { if (has_partial_array_mask(ref_to_scan)) { _partial_scan_cl->do_oop_nv(ref_to_scan); @@ -2099,6 +2018,7 @@ } } +public: void trim_queue(); }; diff -r fd1b9f02cc91 -r bbfbe9b06038 src/share/vm/gc_implementation/g1/g1OopClosures.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/vm/gc_implementation/g1/g1OopClosures.cpp Thu Mar 13 14:57:01 2014 -0700 @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#include "precompiled.hpp" +#include "gc_implementation/g1/g1CollectedHeap.inline.hpp" +#include "gc_implementation/g1/g1OopClosures.inline.hpp" + +G1ParCopyHelper::G1ParCopyHelper(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state) : + G1ParClosureSuper(g1, par_scan_state), _scanned_klass(NULL), + _cm(_g1->concurrent_mark()) {} diff -r fd1b9f02cc91 -r bbfbe9b06038 src/share/vm/gc_implementation/g1/g1OopClosures.hpp --- a/src/share/vm/gc_implementation/g1/g1OopClosures.hpp Mon Mar 10 12:58:02 2014 +0100 +++ b/src/share/vm/gc_implementation/g1/g1OopClosures.hpp Thu Mar 13 14:57:01 2014 -0700 @@ -48,12 +48,8 @@ class G1ParClosureSuper : public OopsInHeapRegionClosure { protected: G1CollectedHeap* _g1; - G1RemSet* _g1_rem; - ConcurrentMark* _cm; G1ParScanThreadState* _par_scan_state; uint _worker_id; - bool _during_initial_mark; - bool _mark_in_progress; public: G1ParClosureSuper(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state); bool apply_to_weak_ref_discovered_field() { return true; } @@ -133,23 +129,10 @@ // Add back base class for metadata class G1ParCopyHelper : public G1ParClosureSuper { +protected: Klass* _scanned_klass; - - public: - G1ParCopyHelper(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state) : - _scanned_klass(NULL), - G1ParClosureSuper(g1, par_scan_state) {} + ConcurrentMark* _cm; - void set_scanned_klass(Klass* k) { _scanned_klass = k; } - template void do_klass_barrier(T* p, oop new_obj); -}; - -template -class G1ParCopyClosure : public G1ParCopyHelper { - G1ParScanClosure _scanner; - template void do_oop_work(T* p); - -protected: // Mark the object if it's not already marked. This is used to mark // objects pointed to by roots that are guaranteed not to move // during the GC (i.e., non-CSet objects). It is MT-safe. @@ -159,22 +142,26 @@ // objects pointed to by roots that have been forwarded during a // GC. It is MT-safe. void mark_forwarded_object(oop from_obj, oop to_obj); + public: + G1ParCopyHelper(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state); - oop copy_to_survivor_space(oop obj); + void set_scanned_klass(Klass* k) { _scanned_klass = k; } + template void do_klass_barrier(T* p, oop new_obj); +}; + +template +class G1ParCopyClosure : public G1ParCopyHelper { +private: + template void do_oop_work(T* p); public: G1ParCopyClosure(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state, ReferenceProcessor* rp) : - _scanner(g1, par_scan_state, rp), G1ParCopyHelper(g1, par_scan_state) { assert(_ref_processor == NULL, "sanity"); } - G1ParScanClosure* scanner() { return &_scanner; } - - template void do_oop_nv(T* p) { - do_oop_work(p); - } + template void do_oop_nv(T* p) { do_oop_work(p); } virtual void do_oop(oop* p) { do_oop_nv(p); } virtual void do_oop(narrowOop* p) { do_oop_nv(p); } }; diff -r fd1b9f02cc91 -r bbfbe9b06038 src/share/vm/gc_implementation/g1/g1OopClosures.inline.hpp --- a/src/share/vm/gc_implementation/g1/g1OopClosures.inline.hpp Mon Mar 10 12:58:02 2014 +0100 +++ b/src/share/vm/gc_implementation/g1/g1OopClosures.inline.hpp Thu Mar 13 14:57:01 2014 -0700 @@ -83,7 +83,7 @@ _par_scan_state->push_on_queue(p); } else { - _par_scan_state->update_rs(_from, p, _par_scan_state->queue_num()); + _par_scan_state->update_rs(_from, p, _worker_id); } } } diff -r fd1b9f02cc91 -r bbfbe9b06038 src/share/vm/gc_implementation/shared/parGCAllocBuffer.hpp --- a/src/share/vm/gc_implementation/shared/parGCAllocBuffer.hpp Mon Mar 10 12:58:02 2014 +0100 +++ b/src/share/vm/gc_implementation/shared/parGCAllocBuffer.hpp Thu Mar 13 14:57:01 2014 -0700 @@ -158,7 +158,7 @@ // Fills in the unallocated portion of the buffer with a garbage object. // If "end_of_gc" is TRUE, is after the last use in the GC. IF "retain" // is true, attempt to re-use the unused portion in the next GC. - virtual void retire(bool end_of_gc, bool retain); + void retire(bool end_of_gc, bool retain); void print() PRODUCT_RETURN; }; diff -r fd1b9f02cc91 -r bbfbe9b06038 src/share/vm/memory/binaryTreeDictionary.cpp --- a/src/share/vm/memory/binaryTreeDictionary.cpp Mon Mar 10 12:58:02 2014 +0100 +++ b/src/share/vm/memory/binaryTreeDictionary.cpp Thu Mar 13 14:57:01 2014 -0700 @@ -44,16 +44,16 @@ // This is currently used in the Concurrent Mark&Sweep implementation. //////////////////////////////////////////////////////////////////////////////// -template class FreeList_t> +template size_t TreeChunk::_min_tree_chunk_size = sizeof(TreeChunk)/HeapWordSize; -template class FreeList_t> +template TreeChunk* TreeChunk::as_TreeChunk(Chunk_t* fc) { // Do some assertion checking here. return (TreeChunk*) fc; } -template class FreeList_t> +template void TreeChunk::verify_tree_chunk_list() const { TreeChunk* nextTC = (TreeChunk*)next(); if (prev() != NULL) { // interior list node shouldn'r have tree fields @@ -67,11 +67,11 @@ } } -template class FreeList_t> +template TreeList::TreeList() : _parent(NULL), _left(NULL), _right(NULL) {} -template class FreeList_t> +template TreeList* TreeList::as_TreeList(TreeChunk* tc) { // This first free chunk in the list will be the tree list. @@ -88,20 +88,7 @@ return tl; } - -template class FreeList_t> -TreeList* -get_chunk(size_t size, enum FreeBlockDictionary::Dither dither) { - FreeBlockDictionary::verify_par_locked(); - Chunk_t* res = get_chunk_from_tree(size, dither); - assert(res == NULL || res->is_free(), - "Should be returning a free chunk"); - assert(dither != FreeBlockDictionary::exactly || - res->size() == size, "Not correct size"); - return res; -} - -template class FreeList_t> +template TreeList* TreeList::as_TreeList(HeapWord* addr, size_t size) { TreeChunk* tc = (TreeChunk*) addr; @@ -125,17 +112,17 @@ // an over populated size. The general get_better_list() just returns // the current list. template <> -TreeList* -TreeList::get_better_list( - BinaryTreeDictionary* dictionary) { +TreeList >* +TreeList >::get_better_list( + BinaryTreeDictionary >* dictionary) { // A candidate chunk has been found. If it is already under // populated, get a chunk associated with the hint for this // chunk. - TreeList* curTL = this; + TreeList >* curTL = this; if (surplus() <= 0) { /* Use the hint to find a size with a surplus, and reset the hint. */ - TreeList* hintTL = this; + TreeList >* hintTL = this; while (hintTL->hint() != 0) { assert(hintTL->hint() > hintTL->size(), "hint points in the wrong direction"); @@ -163,14 +150,14 @@ } #endif // INCLUDE_ALL_GCS -template class FreeList_t> +template TreeList* TreeList::get_better_list( BinaryTreeDictionary* dictionary) { return this; } -template class FreeList_t> +template TreeList* TreeList::remove_chunk_replace_if_needed(TreeChunk* tc) { TreeList* retTL = this; @@ -286,7 +273,7 @@ return retTL; } -template class FreeList_t> +template void TreeList::return_chunk_at_tail(TreeChunk* chunk) { assert(chunk != NULL, "returning NULL chunk"); assert(chunk->list() == this, "list should be set for chunk"); @@ -301,7 +288,7 @@ this->link_tail(chunk); assert(!tail() || size() == tail()->size(), "Wrong sized chunk in list"); - FreeList_t::increment_count(); + FreeList_t::increment_count(); debug_only(this->increment_returned_bytes_by(chunk->size()*sizeof(HeapWord));) assert(head() == NULL || head()->prev() == NULL, "list invariant"); assert(tail() == NULL || tail()->next() == NULL, "list invariant"); @@ -311,7 +298,7 @@ // is defined to be after the chunk pointer to by head(). This is // because the TreeList is embedded in the first TreeChunk in the // list. See the definition of TreeChunk. -template class FreeList_t> +template void TreeList::return_chunk_at_head(TreeChunk* chunk) { assert(chunk->list() == this, "list should be set for chunk"); assert(head() != NULL, "The tree list is embedded in the first chunk"); @@ -329,13 +316,13 @@ } head()->link_after(chunk); assert(!head() || size() == head()->size(), "Wrong sized chunk in list"); - FreeList_t::increment_count(); + FreeList_t::increment_count(); debug_only(this->increment_returned_bytes_by(chunk->size()*sizeof(HeapWord));) assert(head() == NULL || head()->prev() == NULL, "list invariant"); assert(tail() == NULL || tail()->next() == NULL, "list invariant"); } -template class FreeList_t> +template void TreeChunk::assert_is_mangled() const { assert((ZapUnusedHeapArea && SpaceMangler::is_mangled((HeapWord*) Chunk_t::size_addr()) && @@ -345,14 +332,14 @@ "Space should be clear or mangled"); } -template class FreeList_t> +template TreeChunk* TreeList::head_as_TreeChunk() { assert(head() == NULL || (TreeChunk::as_TreeChunk(head())->list() == this), "Wrong type of chunk?"); return TreeChunk::as_TreeChunk(head()); } -template class FreeList_t> +template TreeChunk* TreeList::first_available() { assert(head() != NULL, "The head of the list cannot be NULL"); Chunk_t* fc = head()->next(); @@ -369,7 +356,7 @@ // Returns the block with the largest heap address amongst // those in the list for this size; potentially slow and expensive, // use with caution! -template class FreeList_t> +template TreeChunk* TreeList::largest_address() { assert(head() != NULL, "The head of the list cannot be NULL"); Chunk_t* fc = head()->next(); @@ -392,7 +379,7 @@ return retTC; } -template class FreeList_t> +template BinaryTreeDictionary::BinaryTreeDictionary(MemRegion mr) { assert((mr.byte_size() > min_size()), "minimum chunk size"); @@ -405,17 +392,17 @@ assert(total_free_blocks() == 1, "reset check failed"); } -template class FreeList_t> +template void BinaryTreeDictionary::inc_total_size(size_t inc) { _total_size = _total_size + inc; } -template class FreeList_t> +template void BinaryTreeDictionary::dec_total_size(size_t dec) { _total_size = _total_size - dec; } -template class FreeList_t> +template void BinaryTreeDictionary::reset(MemRegion mr) { assert((mr.byte_size() > min_size()), "minimum chunk size"); set_root(TreeList::as_TreeList(mr.start(), mr.word_size())); @@ -423,13 +410,13 @@ set_total_free_blocks(1); } -template class FreeList_t> +template void BinaryTreeDictionary::reset(HeapWord* addr, size_t byte_size) { MemRegion mr(addr, heap_word_size(byte_size)); reset(mr); } -template class FreeList_t> +template void BinaryTreeDictionary::reset() { set_root(NULL); set_total_size(0); @@ -437,7 +424,7 @@ } // Get a free block of size at least size from tree, or NULL. -template class FreeList_t> +template TreeChunk* BinaryTreeDictionary::get_chunk_from_tree( size_t size, @@ -496,7 +483,7 @@ return retTC; } -template class FreeList_t> +template TreeList* BinaryTreeDictionary::find_list(size_t size) const { TreeList* curTL; for (curTL = root(); curTL != NULL;) { @@ -515,7 +502,7 @@ } -template class FreeList_t> +template bool BinaryTreeDictionary::verify_chunk_in_free_list(Chunk_t* tc) const { size_t size = tc->size(); TreeList* tl = find_list(size); @@ -526,7 +513,7 @@ } } -template class FreeList_t> +template Chunk_t* BinaryTreeDictionary::find_largest_dict() const { TreeList *curTL = root(); if (curTL != NULL) { @@ -541,7 +528,7 @@ // chunk in a list on a tree node, just unlink it. // If it is the last chunk in the list (the next link is NULL), // remove the node and repair the tree. -template class FreeList_t> +template TreeChunk* BinaryTreeDictionary::remove_chunk_from_tree(TreeChunk* tc) { assert(tc != NULL, "Should not call with a NULL chunk"); @@ -682,7 +669,7 @@ // Remove the leftmost node (lm) in the tree and return it. // If lm has a right child, link it to the left node of // the parent of lm. -template class FreeList_t> +template TreeList* BinaryTreeDictionary::remove_tree_minimum(TreeList* tl) { assert(tl != NULL && tl->parent() != NULL, "really need a proper sub-tree"); // locate the subtree minimum by walking down left branches @@ -717,7 +704,7 @@ return curTL; } -template class FreeList_t> +template void BinaryTreeDictionary::insert_chunk_in_tree(Chunk_t* fc) { TreeList *curTL, *prevTL; size_t size = fc->size(); @@ -783,7 +770,7 @@ } } -template class FreeList_t> +template size_t BinaryTreeDictionary::max_chunk_size() const { FreeBlockDictionary::verify_par_locked(); TreeList* tc = root(); @@ -792,7 +779,7 @@ return tc->size(); } -template class FreeList_t> +template size_t BinaryTreeDictionary::total_list_length(TreeList* tl) const { size_t res; res = tl->count(); @@ -805,7 +792,7 @@ return res; } -template class FreeList_t> +template size_t BinaryTreeDictionary::total_size_in_tree(TreeList* tl) const { if (tl == NULL) return 0; @@ -814,7 +801,7 @@ total_size_in_tree(tl->right()); } -template class FreeList_t> +template double BinaryTreeDictionary::sum_of_squared_block_sizes(TreeList* const tl) const { if (tl == NULL) { return 0.0; @@ -826,7 +813,7 @@ return curr; } -template class FreeList_t> +template size_t BinaryTreeDictionary::total_free_blocks_in_tree(TreeList* tl) const { if (tl == NULL) return 0; @@ -835,14 +822,14 @@ total_free_blocks_in_tree(tl->right()); } -template class FreeList_t> +template size_t BinaryTreeDictionary::num_free_blocks() const { assert(total_free_blocks_in_tree(root()) == total_free_blocks(), "_total_free_blocks inconsistency"); return total_free_blocks(); } -template class FreeList_t> +template size_t BinaryTreeDictionary::tree_height_helper(TreeList* tl) const { if (tl == NULL) return 0; @@ -850,12 +837,12 @@ tree_height_helper(tl->right())); } -template class FreeList_t> +template size_t BinaryTreeDictionary::tree_height() const { return tree_height_helper(root()); } -template class FreeList_t> +template size_t BinaryTreeDictionary::total_nodes_helper(TreeList* tl) const { if (tl == NULL) { return 0; @@ -864,18 +851,18 @@ total_nodes_helper(tl->right()); } -template class FreeList_t> +template size_t BinaryTreeDictionary::total_nodes_in_tree(TreeList* tl) const { return total_nodes_helper(root()); } -template class FreeList_t> +template void BinaryTreeDictionary::dict_census_update(size_t size, bool split, bool birth){} #if INCLUDE_ALL_GCS template <> -void AFLBinaryTreeDictionary::dict_census_update(size_t size, bool split, bool birth){ - TreeList* nd = find_list(size); +void AFLBinaryTreeDictionary::dict_census_update(size_t size, bool split, bool birth) { + TreeList >* nd = find_list(size); if (nd) { if (split) { if (birth) { @@ -903,7 +890,7 @@ } #endif // INCLUDE_ALL_GCS -template class FreeList_t> +template bool BinaryTreeDictionary::coal_dict_over_populated(size_t size) { // For the general type of freelists, encourage coalescing by // returning true. @@ -915,7 +902,7 @@ bool AFLBinaryTreeDictionary::coal_dict_over_populated(size_t size) { if (FLSAlwaysCoalesceLarge) return true; - TreeList* list_of_size = find_list(size); + TreeList >* list_of_size = find_list(size); // None of requested size implies overpopulated. return list_of_size == NULL || list_of_size->coal_desired() <= 0 || list_of_size->count() > list_of_size->coal_desired(); @@ -928,15 +915,15 @@ // do_tree() walks the nodes in the binary tree applying do_list() // to each list at each node. -template class FreeList_t> +template class TreeCensusClosure : public StackObj { protected: - virtual void do_list(FreeList_t* fl) = 0; + virtual void do_list(FreeList_t* fl) = 0; public: virtual void do_tree(TreeList* tl) = 0; }; -template class FreeList_t> +template class AscendTreeCensusClosure : public TreeCensusClosure { public: void do_tree(TreeList* tl) { @@ -948,7 +935,7 @@ } }; -template class FreeList_t> +template class DescendTreeCensusClosure : public TreeCensusClosure { public: void do_tree(TreeList* tl) { @@ -962,7 +949,7 @@ // For each list in the tree, calculate the desired, desired // coalesce, count before sweep, and surplus before sweep. -template class FreeList_t> +template class BeginSweepClosure : public AscendTreeCensusClosure { double _percentage; float _inter_sweep_current; @@ -995,16 +982,16 @@ // Similar to TreeCensusClosure but searches the // tree and returns promptly when found. -template class FreeList_t> +template class TreeSearchClosure : public StackObj { protected: - virtual bool do_list(FreeList_t* fl) = 0; + virtual bool do_list(FreeList_t* fl) = 0; public: virtual bool do_tree(TreeList* tl) = 0; }; #if 0 // Don't need this yet but here for symmetry. -template class FreeList_t> +template class AscendTreeSearchClosure : public TreeSearchClosure { public: bool do_tree(TreeList* tl) { @@ -1018,7 +1005,7 @@ }; #endif -template class FreeList_t> +template class DescendTreeSearchClosure : public TreeSearchClosure { public: bool do_tree(TreeList* tl) { @@ -1033,14 +1020,14 @@ // Searches the tree for a chunk that ends at the // specified address. -template class FreeList_t> +template class EndTreeSearchClosure : public DescendTreeSearchClosure { HeapWord* _target; Chunk_t* _found; public: EndTreeSearchClosure(HeapWord* target) : _target(target), _found(NULL) {} - bool do_list(FreeList_t* fl) { + bool do_list(FreeList_t* fl) { Chunk_t* item = fl->head(); while (item != NULL) { if (item->end() == (uintptr_t*) _target) { @@ -1054,7 +1041,7 @@ Chunk_t* found() { return _found; } }; -template class FreeList_t> +template Chunk_t* BinaryTreeDictionary::find_chunk_ends_at(HeapWord* target) const { EndTreeSearchClosure etsc(target); bool found_target = etsc.do_tree(root()); @@ -1063,7 +1050,7 @@ return etsc.found(); } -template class FreeList_t> +template void BinaryTreeDictionary::begin_sweep_dict_census(double coalSurplusPercent, float inter_sweep_current, float inter_sweep_estimate, float intra_sweep_estimate) { BeginSweepClosure bsc(coalSurplusPercent, inter_sweep_current, @@ -1075,32 +1062,32 @@ // Closures and methods for calculating total bytes returned to the // free lists in the tree. #ifndef PRODUCT -template class FreeList_t> +template class InitializeDictReturnedBytesClosure : public AscendTreeCensusClosure { public: - void do_list(FreeList_t* fl) { + void do_list(FreeList_t* fl) { fl->set_returned_bytes(0); } }; -template class FreeList_t> +template void BinaryTreeDictionary::initialize_dict_returned_bytes() { InitializeDictReturnedBytesClosure idrb; idrb.do_tree(root()); } -template class FreeList_t> +template class ReturnedBytesClosure : public AscendTreeCensusClosure { size_t _dict_returned_bytes; public: ReturnedBytesClosure() { _dict_returned_bytes = 0; } - void do_list(FreeList_t* fl) { + void do_list(FreeList_t* fl) { _dict_returned_bytes += fl->returned_bytes(); } size_t dict_returned_bytes() { return _dict_returned_bytes; } }; -template class FreeList_t> +template size_t BinaryTreeDictionary::sum_dict_returned_bytes() { ReturnedBytesClosure rbc; rbc.do_tree(root()); @@ -1109,17 +1096,17 @@ } // Count the number of entries in the tree. -template class FreeList_t> +template class treeCountClosure : public DescendTreeCensusClosure { public: uint count; treeCountClosure(uint c) { count = c; } - void do_list(FreeList_t* fl) { + void do_list(FreeList_t* fl) { count++; } }; -template class FreeList_t> +template size_t BinaryTreeDictionary::total_count() { treeCountClosure ctc(0); ctc.do_tree(root()); @@ -1128,7 +1115,7 @@ #endif // PRODUCT // Calculate surpluses for the lists in the tree. -template class FreeList_t> +template class setTreeSurplusClosure : public AscendTreeCensusClosure { double percentage; public: @@ -1144,14 +1131,14 @@ #endif // INCLUDE_ALL_GCS }; -template class FreeList_t> +template void BinaryTreeDictionary::set_tree_surplus(double splitSurplusPercent) { setTreeSurplusClosure sts(splitSurplusPercent); sts.do_tree(root()); } // Set hints for the lists in the tree. -template class FreeList_t> +template class setTreeHintsClosure : public DescendTreeCensusClosure { size_t hint; public: @@ -1170,14 +1157,14 @@ #endif // INCLUDE_ALL_GCS }; -template class FreeList_t> +template void BinaryTreeDictionary::set_tree_hints(void) { setTreeHintsClosure sth(0); sth.do_tree(root()); } // Save count before previous sweep and splits and coalesces. -template class FreeList_t> +template class clearTreeCensusClosure : public AscendTreeCensusClosure { void do_list(FreeList* fl) {} @@ -1192,14 +1179,14 @@ #endif // INCLUDE_ALL_GCS }; -template class FreeList_t> +template void BinaryTreeDictionary::clear_tree_census(void) { clearTreeCensusClosure ctc; ctc.do_tree(root()); } // Do reporting and post sweep clean up. -template class FreeList_t> +template void BinaryTreeDictionary::end_sweep_dict_census(double splitSurplusPercent) { // Does walking the tree 3 times hurt? set_tree_surplus(splitSurplusPercent); @@ -1211,7 +1198,7 @@ } // Print summary statistics -template class FreeList_t> +template void BinaryTreeDictionary::report_statistics() const { FreeBlockDictionary::verify_par_locked(); gclog_or_tty->print("Statistics for BinaryTreeDictionary:\n" @@ -1230,22 +1217,22 @@ // Print census information - counts, births, deaths, etc. // for each list in the tree. Also print some summary // information. -template class FreeList_t> +template class PrintTreeCensusClosure : public AscendTreeCensusClosure { int _print_line; size_t _total_free; - FreeList_t _total; + FreeList_t _total; public: PrintTreeCensusClosure() { _print_line = 0; _total_free = 0; } - FreeList_t* total() { return &_total; } + FreeList_t* total() { return &_total; } size_t total_free() { return _total_free; } void do_list(FreeList* fl) { if (++_print_line >= 40) { - FreeList_t::print_labels_on(gclog_or_tty, "size"); + FreeList_t::print_labels_on(gclog_or_tty, "size"); _print_line = 0; } fl->print_on(gclog_or_tty); @@ -1256,7 +1243,7 @@ #if INCLUDE_ALL_GCS void do_list(AdaptiveFreeList* fl) { if (++_print_line >= 40) { - FreeList_t::print_labels_on(gclog_or_tty, "size"); + FreeList_t::print_labels_on(gclog_or_tty, "size"); _print_line = 0; } fl->print_on(gclog_or_tty); @@ -1275,16 +1262,16 @@ #endif // INCLUDE_ALL_GCS }; -template class FreeList_t> +template void BinaryTreeDictionary::print_dict_census(void) const { gclog_or_tty->print("\nBinaryTree\n"); - FreeList_t::print_labels_on(gclog_or_tty, "size"); + FreeList_t::print_labels_on(gclog_or_tty, "size"); PrintTreeCensusClosure ptc; ptc.do_tree(root()); - FreeList_t* total = ptc.total(); - FreeList_t::print_labels_on(gclog_or_tty, " "); + FreeList_t* total = ptc.total(); + FreeList_t::print_labels_on(gclog_or_tty, " "); } #if INCLUDE_ALL_GCS @@ -1293,7 +1280,7 @@ gclog_or_tty->print("\nBinaryTree\n"); AdaptiveFreeList::print_labels_on(gclog_or_tty, "size"); - PrintTreeCensusClosure ptc; + PrintTreeCensusClosure > ptc; ptc.do_tree(root()); AdaptiveFreeList* total = ptc.total(); @@ -1311,7 +1298,7 @@ } #endif // INCLUDE_ALL_GCS -template class FreeList_t> +template class PrintFreeListsClosure : public AscendTreeCensusClosure { outputStream* _st; int _print_line; @@ -1321,9 +1308,9 @@ _st = st; _print_line = 0; } - void do_list(FreeList_t* fl) { + void do_list(FreeList_t* fl) { if (++_print_line >= 40) { - FreeList_t::print_labels_on(_st, "size"); + FreeList_t::print_labels_on(_st, "size"); _print_line = 0; } fl->print_on(gclog_or_tty); @@ -1337,10 +1324,10 @@ } }; -template class FreeList_t> +template void BinaryTreeDictionary::print_free_lists(outputStream* st) const { - FreeList_t::print_labels_on(st, "size"); + FreeList_t::print_labels_on(st, "size"); PrintFreeListsClosure pflc(st); pflc.do_tree(root()); } @@ -1349,7 +1336,7 @@ // . _root has no parent // . parent and child point to each other // . each node's key correctly related to that of its child(ren) -template class FreeList_t> +template void BinaryTreeDictionary::verify_tree() const { guarantee(root() == NULL || total_free_blocks() == 0 || total_size() != 0, "_total_size should't be 0?"); @@ -1357,7 +1344,7 @@ verify_tree_helper(root()); } -template class FreeList_t> +template size_t BinaryTreeDictionary::verify_prev_free_ptrs(TreeList* tl) { size_t ct = 0; for (Chunk_t* curFC = tl->head(); curFC != NULL; curFC = curFC->next()) { @@ -1371,7 +1358,7 @@ // Note: this helper is recursive rather than iterative, so use with // caution on very deep trees; and watch out for stack overflow errors; // In general, to be used only for debugging. -template class FreeList_t> +template void BinaryTreeDictionary::verify_tree_helper(TreeList* tl) const { if (tl == NULL) return; @@ -1400,25 +1387,25 @@ verify_tree_helper(tl->right()); } -template class FreeList_t> +template void BinaryTreeDictionary::verify() const { verify_tree(); guarantee(total_size() == total_size_in_tree(root()), "Total Size inconsistency"); } -template class TreeList; -template class BinaryTreeDictionary; -template class TreeChunk; +template class TreeList >; +template class BinaryTreeDictionary >; +template class TreeChunk >; -template class TreeList; -template class BinaryTreeDictionary; -template class TreeChunk; +template class TreeList >; +template class BinaryTreeDictionary >; +template class TreeChunk >; #if INCLUDE_ALL_GCS // Explicitly instantiate these types for FreeChunk. -template class TreeList; -template class BinaryTreeDictionary; -template class TreeChunk; +template class TreeList >; +template class BinaryTreeDictionary >; +template class TreeChunk >; #endif // INCLUDE_ALL_GCS diff -r fd1b9f02cc91 -r bbfbe9b06038 src/share/vm/memory/binaryTreeDictionary.hpp --- a/src/share/vm/memory/binaryTreeDictionary.hpp Mon Mar 10 12:58:02 2014 +0100 +++ b/src/share/vm/memory/binaryTreeDictionary.hpp Thu Mar 13 14:57:01 2014 -0700 @@ -37,18 +37,18 @@ // A TreeList is a FreeList which can be used to maintain a // binary tree of free lists. -template class FreeList_t> class TreeChunk; -template class FreeList_t> class BinaryTreeDictionary; -template class FreeList_t> class AscendTreeCensusClosure; -template class FreeList_t> class DescendTreeCensusClosure; -template class FreeList_t> class DescendTreeSearchClosure; +template class TreeChunk; +template class BinaryTreeDictionary; +template class AscendTreeCensusClosure; +template class DescendTreeCensusClosure; +template class DescendTreeSearchClosure; class FreeChunk; template class AdaptiveFreeList; -typedef BinaryTreeDictionary AFLBinaryTreeDictionary; +typedef BinaryTreeDictionary > AFLBinaryTreeDictionary; -template class FreeList_t> -class TreeList : public FreeList_t { +template +class TreeList : public FreeList_t { friend class TreeChunk; friend class BinaryTreeDictionary; friend class AscendTreeCensusClosure; @@ -66,12 +66,12 @@ TreeList* right() const { return _right; } // Wrapper on call to base class, to get the template to compile. - Chunk_t* head() const { return FreeList_t::head(); } - Chunk_t* tail() const { return FreeList_t::tail(); } - void set_head(Chunk_t* head) { FreeList_t::set_head(head); } - void set_tail(Chunk_t* tail) { FreeList_t::set_tail(tail); } + Chunk_t* head() const { return FreeList_t::head(); } + Chunk_t* tail() const { return FreeList_t::tail(); } + void set_head(Chunk_t* head) { FreeList_t::set_head(head); } + void set_tail(Chunk_t* tail) { FreeList_t::set_tail(tail); } - size_t size() const { return FreeList_t::size(); } + size_t size() const { return FreeList_t::size(); } // Accessors for links in tree. @@ -90,7 +90,7 @@ void clear_left() { _left = NULL; } void clear_right() { _right = NULL; } void clear_parent() { _parent = NULL; } - void initialize() { clear_left(); clear_right(), clear_parent(); FreeList_t::initialize(); } + void initialize() { clear_left(); clear_right(), clear_parent(); FreeList_t::initialize(); } // For constructing a TreeList from a Tree chunk or // address and size. @@ -139,7 +139,7 @@ // on the free list for a node in the tree and is only removed if // it is the last chunk on the free list. -template class FreeList_t> +template class TreeChunk : public Chunk_t { friend class TreeList; TreeList* _list; @@ -173,7 +173,7 @@ }; -template class FreeList_t> +template class BinaryTreeDictionary: public FreeBlockDictionary { friend class VMStructs; size_t _total_size; diff -r fd1b9f02cc91 -r bbfbe9b06038 src/share/vm/memory/metaspace.cpp --- a/src/share/vm/memory/metaspace.cpp Mon Mar 10 12:58:02 2014 +0100 +++ b/src/share/vm/memory/metaspace.cpp Thu Mar 13 14:57:01 2014 -0700 @@ -46,8 +46,8 @@ #include "utilities/copy.hpp" #include "utilities/debug.hpp" -typedef BinaryTreeDictionary BlockTreeDictionary; -typedef BinaryTreeDictionary ChunkTreeDictionary; +typedef BinaryTreeDictionary > BlockTreeDictionary; +typedef BinaryTreeDictionary > ChunkTreeDictionary; // Set this constant to enable slow integrity checking of the free chunk lists const bool metaspace_slow_verify = false; @@ -790,7 +790,7 @@ return NULL; } - if (word_size < TreeChunk::min_size()) { + if (word_size < TreeChunk >::min_size()) { // Dark matter. Too small for dictionary. return NULL; } @@ -810,7 +810,7 @@ MetaWord* new_block = (MetaWord*)free_block; assert(block_size >= word_size, "Incorrect size of block from freelist"); const size_t unused = block_size - word_size; - if (unused >= TreeChunk::min_size()) { + if (unused >= TreeChunk >::min_size()) { return_block(new_block + word_size, unused); } @@ -2239,7 +2239,7 @@ void SpaceManager::deallocate(MetaWord* p, size_t word_size) { assert_lock_strong(_lock); size_t raw_word_size = get_raw_word_size(word_size); - size_t min_size = TreeChunk::min_size(); + size_t min_size = TreeChunk >::min_size(); assert(raw_word_size >= min_size, err_msg("Should not deallocate dark matter " SIZE_FORMAT "<" SIZE_FORMAT, word_size, min_size)); block_freelists()->return_block(p, raw_word_size); @@ -2295,7 +2295,7 @@ void SpaceManager::retire_current_chunk() { if (current_chunk() != NULL) { size_t remaining_words = current_chunk()->free_word_size(); - if (remaining_words >= TreeChunk::min_size()) { + if (remaining_words >= TreeChunk >::min_size()) { block_freelists()->return_block(current_chunk()->allocate(remaining_words), remaining_words); inc_used_metrics(remaining_words); } @@ -3278,7 +3278,7 @@ assert(Thread::current()->is_VM_thread(), "should be the VM thread"); // Don't take Heap_lock MutexLockerEx ml(vsm()->lock(), Mutex::_no_safepoint_check_flag); - if (word_size < TreeChunk::min_size()) { + if (word_size < TreeChunk >::min_size()) { // Dark matter. Too small for dictionary. #ifdef ASSERT Copy::fill_to_words((HeapWord*)ptr, word_size, 0xf5f5f5f5); @@ -3293,7 +3293,7 @@ } else { MutexLockerEx ml(vsm()->lock(), Mutex::_no_safepoint_check_flag); - if (word_size < TreeChunk::min_size()) { + if (word_size < TreeChunk >::min_size()) { // Dark matter. Too small for dictionary. #ifdef ASSERT Copy::fill_to_words((HeapWord*)ptr, word_size, 0xf5f5f5f5); diff -r fd1b9f02cc91 -r bbfbe9b06038 src/share/vm/oops/constantPool.cpp --- a/src/share/vm/oops/constantPool.cpp Mon Mar 10 12:58:02 2014 +0100 +++ b/src/share/vm/oops/constantPool.cpp Thu Mar 13 14:57:01 2014 -0700 @@ -1295,6 +1295,7 @@ } break; case JVM_CONSTANT_UnresolvedClass: + case JVM_CONSTANT_UnresolvedClassInError: { // Can be resolved after checking tag, so check the slot first. CPSlot entry = from_cp->slot_at(from_i); diff -r fd1b9f02cc91 -r bbfbe9b06038 src/share/vm/opto/c2_globals.hpp --- a/src/share/vm/opto/c2_globals.hpp Mon Mar 10 12:58:02 2014 +0100 +++ b/src/share/vm/opto/c2_globals.hpp Thu Mar 13 14:57:01 2014 -0700 @@ -357,6 +357,9 @@ "File to dump ideal graph to. If set overrides the " \ "use of the network") \ \ + product(bool, UseOldInlining, true, \ + "Enable the 1.3 inlining strategy") \ + \ product(bool, UseBimorphicInlining, true, \ "Profiling based inlining for two receivers") \ \ diff -r fd1b9f02cc91 -r bbfbe9b06038 src/share/vm/opto/output.cpp --- a/src/share/vm/opto/output.cpp Mon Mar 10 12:58:02 2014 +0100 +++ b/src/share/vm/opto/output.cpp Thu Mar 13 14:57:01 2014 -0700 @@ -344,6 +344,11 @@ uint* jmp_offset = NEW_RESOURCE_ARRAY(uint,nblocks); uint* jmp_size = NEW_RESOURCE_ARRAY(uint,nblocks); int* jmp_nidx = NEW_RESOURCE_ARRAY(int ,nblocks); + + // Collect worst case block paddings + int* block_worst_case_pad = NEW_RESOURCE_ARRAY(int, nblocks); + memset(block_worst_case_pad, 0, nblocks * sizeof(int)); + DEBUG_ONLY( uint *jmp_target = NEW_RESOURCE_ARRAY(uint,nblocks); ) DEBUG_ONLY( uint *jmp_rule = NEW_RESOURCE_ARRAY(uint,nblocks); ) @@ -460,6 +465,7 @@ last_avoid_back_to_back_adr += max_loop_pad; } blk_size += max_loop_pad; + block_worst_case_pad[i + 1] = max_loop_pad; } } @@ -499,9 +505,16 @@ if (bnum > i) { // adjust following block's offset offset -= adjust_block_start; } + + // This block can be a loop header, account for the padding + // in the previous block. + int block_padding = block_worst_case_pad[i]; + assert(i == 0 || block_padding == 0 || br_offs >= block_padding, "Should have at least a padding on top"); // In the following code a nop could be inserted before // the branch which will increase the backward distance. - bool needs_padding = ((uint)br_offs == last_may_be_short_branch_adr); + bool needs_padding = ((uint)(br_offs - block_padding) == last_may_be_short_branch_adr); + assert(!needs_padding || jmp_offset[i] == 0, "padding only branches at the beginning of block"); + if (needs_padding && offset <= 0) offset -= nop_size; diff -r fd1b9f02cc91 -r bbfbe9b06038 src/share/vm/prims/jni.cpp --- a/src/share/vm/prims/jni.cpp Mon Mar 10 12:58:02 2014 +0100 +++ b/src/share/vm/prims/jni.cpp Thu Mar 13 14:57:01 2014 -0700 @@ -1356,9 +1356,13 @@ // interface call KlassHandle h_holder(THREAD, holder); - int itbl_index = m->itable_index(); - Klass* k = h_recv->klass(); - selected_method = InstanceKlass::cast(k)->method_at_itable(h_holder(), itbl_index, CHECK); + if (call_type == JNI_VIRTUAL) { + int itbl_index = m->itable_index(); + Klass* k = h_recv->klass(); + selected_method = InstanceKlass::cast(k)->method_at_itable(h_holder(), itbl_index, CHECK); + } else { + selected_method = m; + } } } @@ -5061,8 +5065,8 @@ void TestMetaspaceAux_test(); void TestMetachunk_test(); void TestVirtualSpaceNode_test(); +#if INCLUDE_ALL_GCS void TestOldFreeSpaceCalculation_test(); -#if INCLUDE_ALL_GCS void TestG1BiasedArray_test(); #endif @@ -5082,11 +5086,11 @@ run_unit_test(QuickSort::test_quick_sort()); run_unit_test(AltHashing::test_alt_hash()); run_unit_test(test_loggc_filename()); - run_unit_test(TestOldFreeSpaceCalculation_test()); #if INCLUDE_VM_STRUCTS run_unit_test(VMStructs::test()); #endif #if INCLUDE_ALL_GCS + run_unit_test(TestOldFreeSpaceCalculation_test()); run_unit_test(TestG1BiasedArray_test()); run_unit_test(HeapRegionRemSet::test_prt()); #endif diff -r fd1b9f02cc91 -r bbfbe9b06038 src/share/vm/prims/jvm.cpp --- a/src/share/vm/prims/jvm.cpp Mon Mar 10 12:58:02 2014 +0100 +++ b/src/share/vm/prims/jvm.cpp Thu Mar 13 14:57:01 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -521,6 +521,12 @@ JavaThreadInObjectWaitState jtiows(thread, ms != 0); if (JvmtiExport::should_post_monitor_wait()) { JvmtiExport::post_monitor_wait((JavaThread *)THREAD, (oop)obj(), ms); + + // The current thread already owns the monitor and it has not yet + // been added to the wait queue so the current thread cannot be + // made the successor. This means that the JVMTI_EVENT_MONITOR_WAIT + // event handler cannot accidentally consume an unpark() meant for + // the ParkEvent associated with this ObjectMonitor. } ObjectSynchronizer::wait(obj, ms, CHECK); JVM_END diff -r fd1b9f02cc91 -r bbfbe9b06038 src/share/vm/runtime/globals.cpp --- a/src/share/vm/runtime/globals.cpp Mon Mar 10 12:58:02 2014 +0100 +++ b/src/share/vm/runtime/globals.cpp Thu Mar 13 14:57:01 2014 -0700 @@ -31,6 +31,7 @@ #include "utilities/ostream.hpp" #include "utilities/macros.hpp" #include "utilities/top.hpp" +#include "trace/tracing.hpp" #if INCLUDE_ALL_GCS #include "gc_implementation/g1/g1_globals.hpp" #endif // INCLUDE_ALL_GCS @@ -593,6 +594,17 @@ return true; } +template +static void trace_flag_changed(const char* name, const T old_value, const T new_value, const Flag::Flags origin) +{ + E e; + e.set_name(name); + e.set_old_value(old_value); + e.set_new_value(new_value); + e.set_origin(origin); + e.commit(); +} + bool CommandLineFlags::boolAt(char* name, size_t len, bool* value) { Flag* result = Flag::find_flag(name, len); if (result == NULL) return false; @@ -606,6 +618,7 @@ if (result == NULL) return false; if (!result->is_bool()) return false; bool old_value = result->get_bool(); + trace_flag_changed(name, old_value, *value, origin); result->set_bool(*value); *value = old_value; result->set_origin(origin); @@ -615,6 +628,7 @@ void CommandLineFlagsEx::boolAtPut(CommandLineFlagWithType flag, bool value, Flag::Flags origin) { Flag* faddr = address_of_flag(flag); guarantee(faddr != NULL && faddr->is_bool(), "wrong flag type"); + trace_flag_changed(faddr->_name, faddr->get_bool(), value, origin); faddr->set_bool(value); faddr->set_origin(origin); } @@ -632,6 +646,7 @@ if (result == NULL) return false; if (!result->is_intx()) return false; intx old_value = result->get_intx(); + trace_flag_changed(name, old_value, *value, origin); result->set_intx(*value); *value = old_value; result->set_origin(origin); @@ -641,6 +656,7 @@ void CommandLineFlagsEx::intxAtPut(CommandLineFlagWithType flag, intx value, Flag::Flags origin) { Flag* faddr = address_of_flag(flag); guarantee(faddr != NULL && faddr->is_intx(), "wrong flag type"); + trace_flag_changed(faddr->_name, faddr->get_intx(), value, origin); faddr->set_intx(value); faddr->set_origin(origin); } @@ -658,6 +674,7 @@ if (result == NULL) return false; if (!result->is_uintx()) return false; uintx old_value = result->get_uintx(); + trace_flag_changed(name, old_value, *value, origin); result->set_uintx(*value); *value = old_value; result->set_origin(origin); @@ -667,6 +684,7 @@ void CommandLineFlagsEx::uintxAtPut(CommandLineFlagWithType flag, uintx value, Flag::Flags origin) { Flag* faddr = address_of_flag(flag); guarantee(faddr != NULL && faddr->is_uintx(), "wrong flag type"); + trace_flag_changed(faddr->_name, faddr->get_uintx(), value, origin); faddr->set_uintx(value); faddr->set_origin(origin); } @@ -684,6 +702,7 @@ if (result == NULL) return false; if (!result->is_uint64_t()) return false; uint64_t old_value = result->get_uint64_t(); + trace_flag_changed(name, old_value, *value, origin); result->set_uint64_t(*value); *value = old_value; result->set_origin(origin); @@ -693,6 +712,7 @@ void CommandLineFlagsEx::uint64_tAtPut(CommandLineFlagWithType flag, uint64_t value, Flag::Flags origin) { Flag* faddr = address_of_flag(flag); guarantee(faddr != NULL && faddr->is_uint64_t(), "wrong flag type"); + trace_flag_changed(faddr->_name, faddr->get_uint64_t(), value, origin); faddr->set_uint64_t(value); faddr->set_origin(origin); } @@ -710,6 +730,7 @@ if (result == NULL) return false; if (!result->is_double()) return false; double old_value = result->get_double(); + trace_flag_changed(name, old_value, *value, origin); result->set_double(*value); *value = old_value; result->set_origin(origin); @@ -719,6 +740,7 @@ void CommandLineFlagsEx::doubleAtPut(CommandLineFlagWithType flag, double value, Flag::Flags origin) { Flag* faddr = address_of_flag(flag); guarantee(faddr != NULL && faddr->is_double(), "wrong flag type"); + trace_flag_changed(faddr->_name, faddr->get_double(), value, origin); faddr->set_double(value); faddr->set_origin(origin); } @@ -738,6 +760,7 @@ if (result == NULL) return false; if (!result->is_ccstr()) return false; ccstr old_value = result->get_ccstr(); + trace_flag_changed(name, old_value, *value, origin); char* new_value = NULL; if (*value != NULL) { new_value = NEW_C_HEAP_ARRAY(char, strlen(*value)+1, mtInternal); @@ -760,6 +783,7 @@ Flag* faddr = address_of_flag(flag); guarantee(faddr != NULL && faddr->is_ccstr(), "wrong flag type"); ccstr old_value = faddr->get_ccstr(); + trace_flag_changed(faddr->_name, old_value, value, origin); char* new_value = NEW_C_HEAP_ARRAY(char, strlen(value)+1, mtInternal); strcpy(new_value, value); faddr->set_ccstr(new_value); diff -r fd1b9f02cc91 -r bbfbe9b06038 src/share/vm/runtime/objectMonitor.cpp --- a/src/share/vm/runtime/objectMonitor.cpp Mon Mar 10 12:58:02 2014 +0100 +++ b/src/share/vm/runtime/objectMonitor.cpp Thu Mar 13 14:57:01 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -382,6 +382,12 @@ DTRACE_MONITOR_PROBE(contended__enter, this, object(), jt); if (JvmtiExport::should_post_monitor_contended_enter()) { JvmtiExport::post_monitor_contended_enter(jt, this); + + // The current thread does not yet own the monitor and does not + // yet appear on any queues that would get it made the successor. + // This means that the JVMTI_EVENT_MONITOR_CONTENDED_ENTER event + // handler cannot accidentally consume an unpark() meant for the + // ParkEvent associated with this ObjectMonitor. } OSThreadContendState osts(Self->osthread()); @@ -439,6 +445,12 @@ DTRACE_MONITOR_PROBE(contended__entered, this, object(), jt); if (JvmtiExport::should_post_monitor_contended_entered()) { JvmtiExport::post_monitor_contended_entered(jt, this); + + // The current thread already owns the monitor and is not going to + // call park() for the remainder of the monitor enter protocol. So + // it doesn't matter if the JVMTI_EVENT_MONITOR_CONTENDED_ENTERED + // event handler consumed an unpark() issued by the thread that + // just exited the monitor. } if (event.should_commit()) { @@ -1456,6 +1468,14 @@ // Note: 'false' parameter is passed here because the // wait was not timed out due to thread interrupt. JvmtiExport::post_monitor_waited(jt, this, false); + + // In this short circuit of the monitor wait protocol, the + // current thread never drops ownership of the monitor and + // never gets added to the wait queue so the current thread + // cannot be made the successor. This means that the + // JVMTI_EVENT_MONITOR_WAITED event handler cannot accidentally + // consume an unpark() meant for the ParkEvent associated with + // this ObjectMonitor. } if (event.should_commit()) { post_monitor_wait_event(&event, 0, millis, false); @@ -1499,21 +1519,6 @@ exit (true, Self) ; // exit the monitor guarantee (_owner != Self, "invariant") ; - // As soon as the ObjectMonitor's ownership is dropped in the exit() - // call above, another thread can enter() the ObjectMonitor, do the - // notify(), and exit() the ObjectMonitor. If the other thread's - // exit() call chooses this thread as the successor and the unpark() - // call happens to occur while this thread is posting a - // MONITOR_CONTENDED_EXIT event, then we run the risk of the event - // handler using RawMonitors and consuming the unpark(). - // - // To avoid the problem, we re-post the event. This does no harm - // even if the original unpark() was not consumed because we are the - // chosen successor for this monitor. - if (node._notified != 0 && _succ == Self) { - node._event->unpark(); - } - // The thread is on the WaitSet list - now park() it. // On MP systems it's conceivable that a brief spin before we park // could be profitable. @@ -1597,6 +1602,33 @@ JvmtiExport::post_monitor_waited(jt, this, ret == OS_TIMEOUT); } + // Without the fix for 8028280, it is possible for the above call: + // + // Thread::SpinAcquire (&_WaitSetLock, "WaitSet - unlink") ; + // + // to consume the unpark() that was done when the successor was set. + // The solution for this very rare possibility is to redo the unpark() + // outside of the JvmtiExport::should_post_monitor_waited() check. + // + if (node._notified != 0 && _succ == Self) { + // In this part of the monitor wait-notify-reenter protocol it + // is possible (and normal) for another thread to do a fastpath + // monitor enter-exit while this thread is still trying to get + // to the reenter portion of the protocol. + // + // The ObjectMonitor was notified and the current thread is + // the successor which also means that an unpark() has already + // been done. The JVMTI_EVENT_MONITOR_WAITED event handler can + // consume the unpark() that was done when the successor was + // set because the same ParkEvent is shared between Java + // monitors and JVM/TI RawMonitors (for now). + // + // We redo the unpark() to ensure forward progress, i.e., we + // don't want all pending threads hanging (parked) with none + // entering the unlocked monitor. + node._event->unpark(); + } + if (event.should_commit()) { post_monitor_wait_event(&event, node._notifier_tid, millis, ret == OS_TIMEOUT); } diff -r fd1b9f02cc91 -r bbfbe9b06038 src/share/vm/runtime/vmStructs.cpp --- a/src/share/vm/runtime/vmStructs.cpp Mon Mar 10 12:58:02 2014 +0100 +++ b/src/share/vm/runtime/vmStructs.cpp Thu Mar 13 14:57:01 2014 -0700 @@ -248,7 +248,7 @@ typedef Hashtable KlassHashtable; typedef HashtableEntry KlassHashtableEntry; typedef TwoOopHashtable SymbolTwoOopHashtable; -typedef BinaryTreeDictionary MetablockTreeDictionary; +typedef BinaryTreeDictionary > MetablockTreeDictionary; //-------------------------------------------------------------------------------- // VM_STRUCTS diff -r fd1b9f02cc91 -r bbfbe9b06038 src/share/vm/trace/trace.xml --- a/src/share/vm/trace/trace.xml Mon Mar 10 12:58:02 2014 +0100 +++ b/src/share/vm/trace/trace.xml Thu Mar 13 14:57:01 2014 -0700 @@ -122,6 +122,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r fd1b9f02cc91 -r bbfbe9b06038 src/share/vm/trace/tracetypes.xml --- a/src/share/vm/trace/tracetypes.xml Mon Mar 10 12:58:02 2014 +0100 +++ b/src/share/vm/trace/tracetypes.xml Thu Mar 13 14:57:01 2014 -0700 @@ -85,12 +85,6 @@ - - - - - @@ -116,17 +110,6 @@ - - - - - - - - - - @@ -167,6 +150,11 @@ + + + + @@ -351,6 +339,10 @@ + + + diff -r fd1b9f02cc91 -r bbfbe9b06038 test/compiler/inlining/InlineDefaultMethod1.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/compiler/inlining/InlineDefaultMethod1.java Thu Mar 13 14:57:01 2014 -0700 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8036100 + * @summary Default method returns true for a while, and then returns false + * @run main/othervm -Xcomp -XX:CompileOnly=InlineDefaultMethod1::test + * -XX:CompileOnly=I1::m -XX:CompileOnly=I2::m + * InlineDefaultMethod1 + */ +interface I1 { + default public int m() { return 0; } +} + +interface I2 extends I1 { + default public int m() { return 1; } +} + +abstract class A implements I1 { +} + +class B extends A implements I2 { +} + +public class InlineDefaultMethod1 { + public static void test(A obj) { + int id = obj.m(); + if (id != 1) { + throw new AssertionError("Called wrong method: 1 != "+id); + } + } + + public static void main(String[] args) throws InterruptedException { + test(new B()); + System.out.println("TEST PASSED"); + } +} diff -r fd1b9f02cc91 -r bbfbe9b06038 test/serviceability/jvmti/TestRedefineWithUnresolvedClass.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/serviceability/jvmti/TestRedefineWithUnresolvedClass.java Thu Mar 13 14:57:01 2014 -0700 @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @summary Redefine a class with an UnresolvedClass reference in the constant pool. + * @bug 8035150 + * @library /testlibrary + * @build UnresolvedClassAgent com.oracle.java.testlibrary.ProcessTools com.oracle.java.testlibrary.OutputAnalyzer + * @run main TestRedefineWithUnresolvedClass + */ + +import java.io.File; +import java.util.Arrays; + +import com.oracle.java.testlibrary.OutputAnalyzer; +import com.oracle.java.testlibrary.ProcessTools; + +public class TestRedefineWithUnresolvedClass { + + final static String slash = File.separator; + final static String testClasses = System.getProperty("test.classes") + slash; + + public static void main(String... args) throws Throwable { + // delete this class to cause a NoClassDefFoundError + File unresolved = new File(testClasses, "MyUnresolvedClass.class"); + if (unresolved.exists() && !unresolved.delete()) { + throw new Exception("Could not delete: " + unresolved); + } + + // build the javaagent + buildJar("UnresolvedClassAgent"); + + // launch a VM with the javaagent + launchTest(); + } + + private static void buildJar(String jarName) throws Throwable { + String testSrc = System.getProperty("test.src", "?") + slash; + + String jarPath = String.format("%s%s.jar", testClasses, jarName); + String manifestPath = String.format("%s%s.mf", testSrc, jarName); + String className = String.format("%s.class", jarName); + + String[] args = new String[] {"-cfm", jarPath, manifestPath, "-C", testClasses, className}; + + System.out.println("Running jar " + Arrays.toString(args)); + sun.tools.jar.Main jarTool = new sun.tools.jar.Main(System.out, System.err, "jar"); + if (!jarTool.run(args)) { + throw new Exception("jar failed: args=" + Arrays.toString(args)); + } + } + + private static void launchTest() throws Throwable { + String[] args = { + "-javaagent:" + testClasses + "UnresolvedClassAgent.jar", + "-Dtest.classes=" + testClasses, + "UnresolvedClassAgent" }; + OutputAnalyzer output = ProcessTools.executeTestJvm(args); + output.shouldHaveExitValue(0); + } +} diff -r fd1b9f02cc91 -r bbfbe9b06038 test/serviceability/jvmti/UnresolvedClassAgent.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/serviceability/jvmti/UnresolvedClassAgent.java Thu Mar 13 14:57:01 2014 -0700 @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.lang.instrument.ClassDefinition; +import java.lang.instrument.Instrumentation; + +/* + * This class is present during compilation, but will be deleted before execution. + */ +class MyUnresolvedClass { + static void bar() { + } +} + +class MyRedefinedClass { + static void foo() { + MyUnresolvedClass.bar(); + } +} + +public class UnresolvedClassAgent { + public static void main(String... args) { + } + + public static void premain(String args, Instrumentation inst) throws Exception { + try { + MyRedefinedClass.foo(); + } catch(NoClassDefFoundError err) { + System.out.println("NoClassDefFoundError (expected)"); + } + + File f = new File(System.getProperty("test.classes"), "MyRedefinedClass.class"); + byte[] buf = new byte[(int)f.length()]; + try (DataInputStream dis = new DataInputStream(new FileInputStream(f))) { + dis.readFully(buf); + } + ClassDefinition cd = new ClassDefinition(MyRedefinedClass.class, buf); + inst.redefineClasses(new ClassDefinition[] {cd}); + + try { + MyRedefinedClass.foo(); + } catch(NoClassDefFoundError err) { + System.out.println("NoClassDefFoundError (expected again)"); + } + } +} diff -r fd1b9f02cc91 -r bbfbe9b06038 test/serviceability/jvmti/UnresolvedClassAgent.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/serviceability/jvmti/UnresolvedClassAgent.mf Thu Mar 13 14:57:01 2014 -0700 @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Premain-Class: UnresolvedClassAgent +Can-Redefine-Classes: true diff -r fd1b9f02cc91 -r bbfbe9b06038 test/serviceability/sa/jmap-hashcode/Test8028623.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/serviceability/sa/jmap-hashcode/Test8028623.java Thu Mar 13 14:57:01 2014 -0700 @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8028623 + * @summary Test hashing of extended characters in Serviceability Agent. + * @library /testlibrary + * @compile -encoding utf8 Test8028623.java + * @run main Test8028623 + */ + +import com.oracle.java.testlibrary.JDKToolLauncher; +import com.oracle.java.testlibrary.OutputBuffer; +import com.oracle.java.testlibrary.ProcessTools; + +import java.io.File; + +public class Test8028623 { + + public static int à = 1; + public static String dumpFile = "heap.out"; + + public static void main (String[] args) { + + System.out.println(Ã); + + try { + int pid = ProcessTools.getProcessId(); + JDKToolLauncher jmap = JDKToolLauncher.create("jmap") + .addToolArg("-F") + .addToolArg("-dump:live,format=b,file=" + dumpFile) + .addToolArg(Integer.toString(pid)); + ProcessBuilder pb = new ProcessBuilder(jmap.getCommand()); + OutputBuffer output = ProcessTools.getOutput(pb); + Process p = pb.start(); + int e = p.waitFor(); + System.out.println("stdout:"); + System.out.println(output.getStdout()); + System.out.println("stderr:"); + System.out.println(output.getStderr()); + + if (e != 0) { + throw new RuntimeException("jmap returns: " + e); + } + if (! new File(dumpFile).exists()) { + throw new RuntimeException("dump file NOT created: '" + dumpFile + "'"); + } + } catch (Throwable t) { + t.printStackTrace(); + throw new RuntimeException("Test failed with: " + t); + } + } +} diff -r fd1b9f02cc91 -r bbfbe9b06038 test/testlibrary/com/oracle/java/testlibrary/ProcessTools.java --- a/test/testlibrary/com/oracle/java/testlibrary/ProcessTools.java Mon Mar 10 12:58:02 2014 +0100 +++ b/test/testlibrary/com/oracle/java/testlibrary/ProcessTools.java Thu Mar 13 14:57:01 2014 -0700 @@ -151,11 +151,88 @@ // Reporting StringBuilder cmdLine = new StringBuilder(); - for (String cmd : args) - cmdLine.append(cmd).append(' '); + for (String cmd : args) { + cmdLine.append(cmd).append(' '); + } System.out.println("Command line: [" + cmdLine.toString() + "]"); return new ProcessBuilder(args.toArray(new String[args.size()])); } + /** + * Executes a test jvm process, waits for it to finish and returns the process output. + * The default jvm options from jtreg, test.vm.opts and test.java.opts, are added. + * The java from the test.jdk is used to execute the command. + * + * The command line will be like: + * {test.jdk}/bin/java {test.vm.opts} {test.java.opts} cmds + * + * @param cmds User specifed arguments. + * @return The output from the process. + */ + public static OutputAnalyzer executeTestJvm(String... cmds) throws Throwable { + ProcessBuilder pb = createJavaProcessBuilder(Utils.addTestJavaOpts(cmds)); + return executeProcess(pb); + } + + /** + * Executes a process, waits for it to finish and returns the process output. + * @param pb The ProcessBuilder to execute. + * @return The output from the process. + */ + public static OutputAnalyzer executeProcess(ProcessBuilder pb) throws Throwable { + OutputAnalyzer output = null; + try { + output = new OutputAnalyzer(pb.start()); + return output; + } catch (Throwable t) { + System.out.println("executeProcess() failed: " + t); + throw t; + } finally { + System.out.println(getProcessLog(pb, output)); + } + } + + /** + * Executes a process, waits for it to finish and returns the process output. + * @param cmds The command line to execute. + * @return The output from the process. + */ + public static OutputAnalyzer executeProcess(String... cmds) throws Throwable { + return executeProcess(new ProcessBuilder(cmds)); + } + + /** + * Used to log command line, stdout, stderr and exit code from an executed process. + * @param pb The executed process. + * @param output The output from the process. + */ + public static String getProcessLog(ProcessBuilder pb, OutputAnalyzer output) { + String stderr = output == null ? "null" : output.getStderr(); + String stdout = output == null ? "null" : output.getStdout(); + String exitValue = output == null ? "null": Integer.toString(output.getExitValue()); + StringBuilder logMsg = new StringBuilder(); + final String nl = System.getProperty("line.separator"); + logMsg.append("--- ProcessLog ---" + nl); + logMsg.append("cmd: " + getCommandLine(pb) + nl); + logMsg.append("exitvalue: " + exitValue + nl); + logMsg.append("stderr: " + stderr + nl); + logMsg.append("stdout: " + stdout + nl); + return logMsg.toString(); + } + + /** + * @return The full command line for the ProcessBuilder. + */ + public static String getCommandLine(ProcessBuilder pb) { + if (pb == null) { + return "null"; + } + StringBuilder cmd = new StringBuilder(); + for (String s : pb.command()) { + cmd.append(s).append(" "); + } + return cmd.toString().trim(); + } + } diff -r fd1b9f02cc91 -r bbfbe9b06038 test/testlibrary/com/oracle/java/testlibrary/Utils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/testlibrary/com/oracle/java/testlibrary/Utils.java Thu Mar 13 14:57:01 2014 -0700 @@ -0,0 +1,263 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.oracle.java.testlibrary; + +import static com.oracle.java.testlibrary.Asserts.assertTrue; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.List; +import java.util.Arrays; +import java.util.Collections; +import java.util.regex.Pattern; +import java.util.regex.Matcher; + +/** + * Common library for various test helper functions. + */ +public final class Utils { + + /** + * Returns the sequence used by operating system to separate lines. + */ + public static final String NEW_LINE = System.getProperty("line.separator"); + + /** + * Returns the value of 'test.vm.opts'system property. + */ + public static final String VM_OPTIONS = System.getProperty("test.vm.opts", "").trim(); + + /** + * Returns the value of 'test.java.opts'system property. + */ + public static final String JAVA_OPTIONS = System.getProperty("test.java.opts", "").trim(); + + /** + * Returns the value of 'test.timeout.factor' system property + * converted to {@code double}. + */ + public static final double TIMEOUT_FACTOR; + static { + String toFactor = System.getProperty("test.timeout.factor", "1.0"); + TIMEOUT_FACTOR = Double.parseDouble(toFactor); + } + + private Utils() { + // Private constructor to prevent class instantiation + } + + /** + * Returns the list of VM options. + * + * @return List of VM options + */ + public static List getVmOptions() { + return Arrays.asList(safeSplitString(VM_OPTIONS)); + } + + /** + * Returns the list of VM options with -J prefix. + * + * @return The list of VM options with -J prefix + */ + public static List getForwardVmOptions() { + String[] opts = safeSplitString(VM_OPTIONS); + for (int i = 0; i < opts.length; i++) { + opts[i] = "-J" + opts[i]; + } + return Arrays.asList(opts); + } + + /** + * Returns the default JTReg arguments for a jvm running a test. + * This is the combination of JTReg arguments test.vm.opts and test.java.opts. + * @return An array of options, or an empty array if no opptions. + */ + public static String[] getTestJavaOpts() { + List opts = new ArrayList(); + Collections.addAll(opts, safeSplitString(VM_OPTIONS)); + Collections.addAll(opts, safeSplitString(JAVA_OPTIONS)); + return opts.toArray(new String[0]); + } + + /** + * Combines given arguments with default JTReg arguments for a jvm running a test. + * This is the combination of JTReg arguments test.vm.opts and test.java.opts + * @return The combination of JTReg test java options and user args. + */ + public static String[] addTestJavaOpts(String... userArgs) { + List opts = new ArrayList(); + Collections.addAll(opts, getTestJavaOpts()); + Collections.addAll(opts, userArgs); + return opts.toArray(new String[0]); + } + + /** + * Splits a string by white space. + * Works like String.split(), but returns an empty array + * if the string is null or empty. + */ + private static String[] safeSplitString(String s) { + if (s == null || s.trim().isEmpty()) { + return new String[] {}; + } + return s.trim().split("\\s+"); + } + + /** + * @return The full command line for the ProcessBuilder. + */ + public static String getCommandLine(ProcessBuilder pb) { + StringBuilder cmd = new StringBuilder(); + for (String s : pb.command()) { + cmd.append(s).append(" "); + } + return cmd.toString(); + } + + /** + * Returns the free port on the local host. + * The function will spin until a valid port number is found. + * + * @return The port number + * @throws InterruptedException if any thread has interrupted the current thread + * @throws IOException if an I/O error occurs when opening the socket + */ + public static int getFreePort() throws InterruptedException, IOException { + int port = -1; + + while (port <= 0) { + Thread.sleep(100); + + ServerSocket serverSocket = null; + try { + serverSocket = new ServerSocket(0); + port = serverSocket.getLocalPort(); + } finally { + serverSocket.close(); + } + } + + return port; + } + + /** + * Returns the name of the local host. + * + * @return The host name + * @throws UnknownHostException if IP address of a host could not be determined + */ + public static String getHostname() throws UnknownHostException { + InetAddress inetAddress = InetAddress.getLocalHost(); + String hostName = inetAddress.getHostName(); + + assertTrue((hostName != null && !hostName.isEmpty()), + "Cannot get hostname"); + + return hostName; + } + + /** + * Uses "jcmd -l" to search for a jvm pid. This function will wait + * forever (until jtreg timeout) for the pid to be found. + * @param key Regular expression to search for + * @return The found pid. + */ + public static int waitForJvmPid(String key) throws Throwable { + final long iterationSleepMillis = 250; + System.out.println("waitForJvmPid: Waiting for key '" + key + "'"); + System.out.flush(); + while (true) { + int pid = tryFindJvmPid(key); + if (pid >= 0) { + return pid; + } + Thread.sleep(iterationSleepMillis); + } + } + + /** + * Searches for a jvm pid in the output from "jcmd -l". + * + * Example output from jcmd is: + * 12498 sun.tools.jcmd.JCmd -l + * 12254 /tmp/jdk8/tl/jdk/JTwork/classes/com/sun/tools/attach/Application.jar + * + * @param key A regular expression to search for. + * @return The found pid, or -1 if Enot found. + * @throws Exception If multiple matching jvms are found. + */ + public static int tryFindJvmPid(String key) throws Throwable { + OutputAnalyzer output = null; + try { + JDKToolLauncher jcmdLauncher = JDKToolLauncher.create("jcmd"); + jcmdLauncher.addToolArg("-l"); + output = ProcessTools.executeProcess(jcmdLauncher.getCommand()); + output.shouldHaveExitValue(0); + + // Search for a line starting with numbers (pid), follwed by the key. + Pattern pattern = Pattern.compile("([0-9]+)\\s.*(" + key + ").*\\r?\\n"); + Matcher matcher = pattern.matcher(output.getStdout()); + + int pid = -1; + if (matcher.find()) { + pid = Integer.parseInt(matcher.group(1)); + System.out.println("findJvmPid.pid: " + pid); + if (matcher.find()) { + throw new Exception("Found multiple JVM pids for key: " + key); + } + } + return pid; + } catch (Throwable t) { + System.out.println(String.format("Utils.findJvmPid(%s) failed: %s", key, t)); + throw t; + } + } + + /** + * Returns file content as a list of strings + * + * @param file File to operate on + * @return List of strings + * @throws IOException + */ + public static List fileAsList(File file) throws IOException { + assertTrue(file.exists() && file.isFile(), + file.getAbsolutePath() + " does not exist or not a file"); + List output = new ArrayList<>(); + try (BufferedReader reader = new BufferedReader(new FileReader(file.getAbsolutePath()))) { + while (reader.ready()) { + output.add(reader.readLine().replace(NEW_LINE, "")); + } + } + return output; + } + +}