--- old/src/share/vm/opto/macro.cpp 2016-04-26 13:47:37.586707035 +0200 +++ new/src/share/vm/opto/macro.cpp 2016-04-26 13:47:37.450707041 +0200 @@ -1897,7 +1897,7 @@ Node *prefetch_adr; Node *prefetch; - uint lines = AllocatePrefetchDistance / AllocatePrefetchStepSize; + uint lines = (length != NULL) ? AllocatePrefetchLines : AllocateInstancePrefetchLines; uint step_size = AllocatePrefetchStepSize; uint distance = 0; @@ -1926,12 +1926,8 @@ contended_phi_rawmem = pf_phi_rawmem; i_o = pf_phi_abio; } else if( UseTLAB && AllocatePrefetchStyle == 3 ) { - // Insert a prefetch for each allocation. - // This code is used for Sparc with BIS. - Node *pf_region = new RegionNode(3); - Node *pf_phi_rawmem = new PhiNode( pf_region, Type::MEMORY, - TypeRawPtr::BOTTOM ); - transform_later(pf_region); + // Insert a prefetch instruction for each allocation. + // This code is used for SPARC with BIS. // Generate several prefetch instructions. uint lines = (length != NULL) ? AllocatePrefetchLines : AllocateInstancePrefetchLines; @@ -1944,7 +1940,8 @@ transform_later(cache_adr); cache_adr = new CastP2XNode(needgc_false, cache_adr); transform_later(cache_adr); - Node* mask = _igvn.MakeConX(~(intptr_t)(step_size-1)); + // BIS instructions require 8-byte aligned addresses + Node* mask = _igvn.MakeConX(~(intptr_t)(wordSize - 1)); cache_adr = new AndXNode(cache_adr, mask); transform_later(cache_adr); cache_adr = new CastX2PNode(cache_adr); --- old/src/share/vm/runtime/commandLineFlagConstraintsCompiler.cpp 2016-04-26 13:47:37.622707033 +0200 +++ new/src/share/vm/runtime/commandLineFlagConstraintsCompiler.cpp 2016-04-26 13:47:37.446707041 +0200 @@ -89,27 +89,16 @@ } } -Flag::Error AllocatePrefetchDistanceConstraintFunc(intx value, bool verbose) { - if (value < 0) { - CommandLineError::print(verbose, - "Unable to determine system-specific value for AllocatePrefetchDistance. " - "Please provide appropriate value, if unsure, use 0 to disable prefetching\n"); - return Flag::VIOLATES_CONSTRAINT; - } - - return Flag::SUCCESS; -} - -Flag::Error AllocatePrefetchInstrConstraintFunc(intx value, bool verbose) { - intx max_value = max_intx; +Flag::Error AllocatePrefetchStyleConstraintFunc(intx value, bool verbose) { + intx max_value; #if defined(SPARC) - max_value = 1; -#elif defined(X86) max_value = 3; +#else + max_value = 2; #endif if (value < 0 || value > max_value) { CommandLineError::print(verbose, - "AllocatePrefetchInstr (" INTX_FORMAT ") must be " + "AllocatePrefetchStyle (" INTX_FORMAT ") must be " "between 0 and " INTX_FORMAT "\n", value, max_value); return Flag::VIOLATES_CONSTRAINT; } @@ -117,43 +106,48 @@ return Flag::SUCCESS; } -Flag::Error AllocatePrefetchStepSizeConstraintFunc(intx value, bool verbose) { - intx max_value = 512; - if (value < 1 || value > max_value) { - CommandLineError::print(verbose, - "AllocatePrefetchStepSize (" INTX_FORMAT ") " - "must be between 1 and %d\n", - AllocatePrefetchStepSize, - max_value); - return Flag::VIOLATES_CONSTRAINT; +Flag::Error AllocatePrefetchDistanceConstraintFunc(intx value, bool verbose) { + intx min_value; + if (AllocatePrefetchStyle == 3) { + min_value = wordSize; + } else { + min_value = 0; } - if (AllocatePrefetchDistance % AllocatePrefetchStepSize != 0) { + if (value < min_value || value > 512) { CommandLineError::print(verbose, - "AllocatePrefetchDistance (" INTX_FORMAT ") " - "%% AllocatePrefetchStepSize (" INTX_FORMAT ") " - "= " INTX_FORMAT " " - "must be 0\n", - AllocatePrefetchDistance, AllocatePrefetchStepSize, - AllocatePrefetchDistance % AllocatePrefetchStepSize); + "AllocatePrefetchDistance (" INTX_FORMAT ") must be " + "between " INTX_FORMAT " and " INTX_FORMAT "\n", + AllocatePrefetchDistance, min_value, 512); return Flag::VIOLATES_CONSTRAINT; } - /* The limit of 64 for the quotient of AllocatePrefetchDistance and AllocatePrefetchSize - * originates from the limit of 64 for AllocatePrefetchLines/AllocateInstancePrefetchLines. - * If AllocatePrefetchStyle == 2, the quotient from above is used in PhaseMacroExpand::prefetch_allocation() - * to determine the number of lines to prefetch. For other values of AllocatePrefetchStyle, - * AllocatePrefetchDistance and AllocatePrefetchSize is used. For consistency, all these - * quantities must have the same limit (64 in this case). - */ - if (AllocatePrefetchDistance / AllocatePrefetchStepSize > 64) { + return Flag::SUCCESS; +} + +Flag::Error AllocatePrefetchStepSizeConstraintFunc(intx value, bool verbose) { + if (AllocatePrefetchStyle == 3) { + if (value % wordSize != 0) { + CommandLineError::print(verbose, + "AllocatePrefetchStepSize (" INTX_FORMAT ") must be multiple of %d\n", + value, wordSize); + return Flag::VIOLATES_CONSTRAINT; + } + } + return Flag::SUCCESS; +} + +Flag::Error AllocatePrefetchInstrConstraintFunc(intx value, bool verbose) { + intx max_value = max_intx; +#if defined(SPARC) + max_value = 1; +#elif defined(X86) + max_value = 3; +#endif + if (value < 0 || value > max_value) { CommandLineError::print(verbose, - "AllocatePrefetchDistance (" INTX_FORMAT ") too large or " - "AllocatePrefetchStepSize (" INTX_FORMAT ") too small; " - "try decreasing/increasing values so that " - "AllocatePrefetchDistance / AllocatePrefetchStepSize <= 64\n", - AllocatePrefetchDistance, AllocatePrefetchStepSize, - AllocatePrefetchDistance % AllocatePrefetchStepSize); + "AllocatePrefetchInstr (" INTX_FORMAT ") must be " + "between 0 and " INTX_FORMAT "\n", value, max_value); return Flag::VIOLATES_CONSTRAINT; } --- old/src/share/vm/runtime/globals.hpp 2016-04-26 13:47:37.706707029 +0200 +++ new/src/share/vm/runtime/globals.hpp 2016-04-26 13:47:37.462707041 +0200 @@ -2901,10 +2901,10 @@ \ product(intx, AllocatePrefetchStyle, 1, \ "0 = no prefetch, " \ - "1 = prefetch instructions for each allocation, " \ + "1 = generate prefetch instructions for each allocation, " \ "2 = use TLAB watermark to gate allocation prefetch, " \ - "3 = use BIS instruction on Sparc for allocation prefetch") \ - range(0, 3) \ + "3 = use BIS instruction for prefetch (only available on SPARC)") \ + constraint(AllocatePrefetchStyleConstraintFunc, AfterErgo) \ \ product(intx, AllocatePrefetchDistance, -1, \ "Distance to prefetch ahead of allocation pointer. " \ @@ -2926,7 +2926,7 @@ constraint(AllocatePrefetchStepSizeConstraintFunc,AfterMemoryInit)\ \ product(intx, AllocatePrefetchInstr, 0, \ - "Prefetch instruction to prefetch ahead of allocation pointer") \ + "Select instruction to prefetch ahead of allocation pointer") \ constraint(AllocatePrefetchInstrConstraintFunc, AfterErgo) \ \ /* deoptimization */ \ --- old/src/share/vm/runtime/commandLineFlagConstraintsCompiler.hpp 2016-04-26 13:47:37.750707027 +0200 +++ new/src/share/vm/runtime/commandLineFlagConstraintsCompiler.hpp 2016-04-26 13:47:37.606707034 +0200 @@ -38,6 +38,8 @@ Flag::Error CICompilerCountConstraintFunc(intx value, bool verbose); +Flag::Error AllocatePrefetchStyleConstraintFunc(intx value, bool verbose); + Flag::Error AllocatePrefetchDistanceConstraintFunc(intx value, bool verbose); Flag::Error AllocatePrefetchInstrConstraintFunc(intx value, bool verbose); --- old/test/runtime/CommandLine/OptionsValidation/TestOptionsWithRanges.java 2016-04-26 13:47:37.790707025 +0200 +++ new/test/runtime/CommandLine/OptionsValidation/TestOptionsWithRanges.java 2016-04-26 13:47:37.586707035 +0200 @@ -90,13 +90,6 @@ excludeTestMaxRange("CICompilerCount"); /* - * JDK-8153340 - * Temporary exclude AllocatePrefetchDistance option from testing - */ - excludeTestRange("AllocatePrefetchDistance"); - - - /* * JDK-8136766 * Temporarily remove ThreadStackSize from testing because Windows can set it to 0 * (for default OS size) but other platforms insist it must be greater than 0 --- old/src/cpu/sparc/vm/vm_version_sparc.cpp 2016-04-26 13:47:37.798707025 +0200 +++ new/src/cpu/sparc/vm/vm_version_sparc.cpp 2016-04-26 13:47:37.518707038 +0200 @@ -49,9 +49,15 @@ AllocatePrefetchDistance = allocate_prefetch_distance(); AllocatePrefetchStyle = allocate_prefetch_style(); - if (AllocatePrefetchStyle == 3 && !has_blk_init()) { - warning("BIS instructions are not available on this CPU"); - FLAG_SET_DEFAULT(AllocatePrefetchStyle, 1); + if (!has_blk_init()) { + if (AllocatePrefetchStyle == 3) { + warning("BIS instructions required for AllocatePrefetchStyle 3 unavailable"); + FLAG_SET_DEFAULT(AllocatePrefetchStyle, 1); + } + if (AllocatePrefetchInstr == 1) { + warning("BIS instructions required for AllocatePrefetchInstr 1 unavailable"); + FLAG_SET_DEFAULT(AllocatePrefetchInstr, 0); + } } UseSSE = 0; // Only on x86 and x64 @@ -88,11 +94,13 @@ if (has_blk_init() && UseTLAB && FLAG_IS_DEFAULT(AllocatePrefetchInstr)) { // Use BIS instruction for TLAB allocation prefetch. - FLAG_SET_ERGO(intx, AllocatePrefetchInstr, 1); - if (FLAG_IS_DEFAULT(AllocatePrefetchStyle)) { - FLAG_SET_ERGO(intx, AllocatePrefetchStyle, 3); - } - if (FLAG_IS_DEFAULT(AllocatePrefetchDistance)) { + FLAG_SET_DEFAULT(AllocatePrefetchInstr, 1); + } + if (FLAG_IS_DEFAULT(AllocatePrefetchDistance)) { + if (AllocatePrefetchInstr == 0) { + // Use different prefetch distance without BIS + FLAG_SET_DEFAULT(AllocatePrefetchDistance, 256); + } else { // Use smaller prefetch distance with BIS FLAG_SET_DEFAULT(AllocatePrefetchDistance, 64); } @@ -107,25 +115,25 @@ FLAG_SET_ERGO(intx, AllocateInstancePrefetchLines, AllocateInstancePrefetchLines*2); } } - if (AllocatePrefetchStyle != 3 && FLAG_IS_DEFAULT(AllocatePrefetchDistance)) { - // Use different prefetch distance without BIS - FLAG_SET_DEFAULT(AllocatePrefetchDistance, 256); - } - if (AllocatePrefetchInstr == 1) { - // Need extra space at the end of TLAB for BIS, otherwise prefetching - // instructions will fault (due to accessing memory outside of heap). - // The amount of space is the max of the number of lines to - // prefetch for array and for instance allocations. (Extra space must be - // reserved to accomodate both types of allocations.) - - // +1 for rounding up to next cache line, +1 to be safe - int lines = MAX2(AllocatePrefetchLines, AllocateInstancePrefetchLines) + 2; - int step_size = AllocatePrefetchStepSize; - int distance = AllocatePrefetchDistance; - _reserve_for_allocation_prefetch = (distance + step_size*lines)/(int)HeapWordSize; - } } -#endif + if (AllocatePrefetchInstr == 1) { + // Use allocation prefetch style 3 because BIS instructions + // require aligned memory addresses. + FLAG_SET_DEFAULT(AllocatePrefetchStyle, 3); + + // Need extra space at the end of TLAB for BIS, otherwise prefetching + // instructions will fault (due to accessing memory outside of heap). + // The amount of space is the max of the number of lines to + // prefetch for array and for instance allocations. (Extra space must be + // reserved to accomodate both types of allocations.) + + // +1 for rounding up to next cache line, +1 to be safe + int lines = MAX2(AllocatePrefetchLines, AllocateInstancePrefetchLines) + 2; + int step_size = AllocatePrefetchStepSize; + int distance = AllocatePrefetchDistance; + _reserve_for_allocation_prefetch = (distance + step_size*lines)/(int)HeapWordSize; + } +#endif /* COMPILER2 */ } // Use hardware population count instruction if available.