uint AdaptiveSizePolicy::calc_active_workers(uintx total_workers, uintx active_workers, uintx application_workers) { // If the user has specifically set the number of // GC threads, use them. // If the user has turned off using a dynamic number of GC threads // or the users has requested a specific number, set the active // number of workers to all the workers. uint new_active_workers; if (!UseDynamicNumberOfGCThreads || (!FLAG_IS_DEFAULT(ParallelGCThreads) && !ForceDynamicNumberOfGCThreads)) { new_active_workers = total_workers; } else { uintx min_workers = (total_workers == 1) ? 1 : 2; new_active_workers = calc_default_active_workers(total_workers, min_workers, active_workers, application_workers); } assert(new_active_workers > 0, "Always need at least 1"); return new_active_workers; }
void SimpleThresholdPolicy::initialize() { if (FLAG_IS_DEFAULT(CICompilerCount)) { FLAG_SET_DEFAULT(CICompilerCount, 3); } int count = CICompilerCount; #ifdef _LP64 // On 64-bit systems, scale the number of compiler threads with // the number of cores available on the system. Scaling is not // performed on 32-bit systems because it can lead to exhaustion // of the virtual memory address space available to the JVM. if (CICompilerCountPerCPU) { count = MAX2(log2_intptr(os::active_processor_count()) * 3 / 2, 2); FLAG_SET_ERGO(intx, CICompilerCount, count); } #endif if (TieredStopAtLevel < CompLevel_full_optimization) { // No C2 compiler thread required set_c1_count(count); } else { set_c1_count(MAX2(count / 3, 1)); set_c2_count(MAX2(count - c1_count(), 1)); } assert(count == c1_count() + c2_count(), "inconsistent compiler thread count"); }
void VM_Version::initialize() { _features = determine_features(); PrefetchCopyIntervalInBytes = prefetch_copy_interval_in_bytes(); PrefetchScanIntervalInBytes = prefetch_scan_interval_in_bytes(); PrefetchFieldsAhead = prefetch_fields_ahead(); assert(0 <= AllocatePrefetchInstr && AllocatePrefetchInstr <= 1, "invalid value"); if( AllocatePrefetchInstr < 0 ) AllocatePrefetchInstr = 0; if( AllocatePrefetchInstr > 1 ) AllocatePrefetchInstr = 0; // Allocation prefetch settings intx cache_line_size = prefetch_data_size(); if( cache_line_size > AllocatePrefetchStepSize ) AllocatePrefetchStepSize = cache_line_size; assert(AllocatePrefetchLines > 0, "invalid value"); if( AllocatePrefetchLines < 1 ) // set valid value in product VM AllocatePrefetchLines = 3; assert(AllocateInstancePrefetchLines > 0, "invalid value"); if( AllocateInstancePrefetchLines < 1 ) // set valid value in product VM AllocateInstancePrefetchLines = 1; AllocatePrefetchDistance = allocate_prefetch_distance(); AllocatePrefetchStyle = allocate_prefetch_style(); assert((AllocatePrefetchDistance % AllocatePrefetchStepSize) == 0 && (AllocatePrefetchDistance > 0), "invalid value"); if ((AllocatePrefetchDistance % AllocatePrefetchStepSize) != 0 || (AllocatePrefetchDistance <= 0)) { AllocatePrefetchDistance = AllocatePrefetchStepSize; } if (AllocatePrefetchStyle == 3 && !has_blk_init()) { warning("BIS instructions are not available on this CPU"); FLAG_SET_DEFAULT(AllocatePrefetchStyle, 1); } guarantee(VM_Version::has_v9(), "only SPARC v9 is supported"); assert(ArraycopySrcPrefetchDistance < 4096, "invalid value"); if (ArraycopySrcPrefetchDistance >= 4096) ArraycopySrcPrefetchDistance = 4064; assert(ArraycopyDstPrefetchDistance < 4096, "invalid value"); if (ArraycopyDstPrefetchDistance >= 4096) ArraycopyDstPrefetchDistance = 4064; UseSSE = 0; // Only on x86 and x64 _supports_cx8 = has_v9(); _supports_atomic_getset4 = true; // swap instruction // There are Fujitsu Sparc64 CPUs which support blk_init as well so // we have to take this check out of the 'is_niagara()' block below. if (has_blk_init()) { // When using CMS or G1, we cannot use memset() in BOT updates // because the sun4v/CMT version in libc_psr uses BIS which // exposes "phantom zeros" to concurrent readers. See 6948537. if (FLAG_IS_DEFAULT(UseMemSetInBOT) && (UseConcMarkSweepGC || UseG1GC)) { FLAG_SET_DEFAULT(UseMemSetInBOT, false); } // Issue a stern warning if the user has explicitly set // UseMemSetInBOT (it is known to cause issues), but allow // use for experimentation and debugging. if (UseConcMarkSweepGC || UseG1GC) { if (UseMemSetInBOT) { assert(!FLAG_IS_DEFAULT(UseMemSetInBOT), "Error"); warning("Experimental flag -XX:+UseMemSetInBOT is known to cause instability" " on sun4v; please understand that you are using at your own risk!"); } } } if (is_niagara()) { // Indirect branch is the same cost as direct if (FLAG_IS_DEFAULT(UseInlineCaches)) { FLAG_SET_DEFAULT(UseInlineCaches, false); } // Align loops on a single instruction boundary. if (FLAG_IS_DEFAULT(OptoLoopAlignment)) { FLAG_SET_DEFAULT(OptoLoopAlignment, 4); } #ifdef _LP64 // 32-bit oops don't make sense for the 64-bit VM on sparc // since the 32-bit VM has the same registers and smaller objects. Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes); Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes); #endif // _LP64 #ifdef COMPILER2 // Indirect branch is the same cost as direct if (FLAG_IS_DEFAULT(UseJumpTables)) { FLAG_SET_DEFAULT(UseJumpTables, true); } // Single-issue, so entry and loop tops are // aligned on a single instruction boundary if (FLAG_IS_DEFAULT(InteriorEntryAlignment)) { FLAG_SET_DEFAULT(InteriorEntryAlignment, 4); } if (is_niagara_plus()) { 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)) { // Use smaller prefetch distance with BIS FLAG_SET_DEFAULT(AllocatePrefetchDistance, 64); } } if (is_T4()) { // Double number of prefetched cache lines on T4 // since L2 cache line size is smaller (32 bytes). if (FLAG_IS_DEFAULT(AllocatePrefetchLines)) { FLAG_SET_ERGO(intx, AllocatePrefetchLines, AllocatePrefetchLines*2); } if (FLAG_IS_DEFAULT(AllocateInstancePrefetchLines)) { 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 a space at the end of TLAB for BIS since it // will fault when accessing memory outside of heap. // +1 for rounding up to next cache line, +1 to be safe int lines = AllocatePrefetchLines + 2; int step_size = AllocatePrefetchStepSize; int distance = AllocatePrefetchDistance; _reserve_for_allocation_prefetch = (distance + step_size*lines)/(int)HeapWordSize; } } #endif } // Use hardware population count instruction if available. if (has_hardware_popc()) { if (FLAG_IS_DEFAULT(UsePopCountInstruction)) { FLAG_SET_DEFAULT(UsePopCountInstruction, true); } } else if (UsePopCountInstruction) { warning("POPC instruction is not available on this CPU"); FLAG_SET_DEFAULT(UsePopCountInstruction, false); } // T4 and newer Sparc cpus have new compare and branch instruction. if (has_cbcond()) { if (FLAG_IS_DEFAULT(UseCBCond)) { FLAG_SET_DEFAULT(UseCBCond, true); } } else if (UseCBCond) { warning("CBCOND instruction is not available on this CPU"); FLAG_SET_DEFAULT(UseCBCond, false); } assert(BlockZeroingLowLimit > 0, "invalid value"); if (has_block_zeroing()) { if (FLAG_IS_DEFAULT(UseBlockZeroing)) { FLAG_SET_DEFAULT(UseBlockZeroing, true); } } else if (UseBlockZeroing) { warning("BIS zeroing instructions are not available on this CPU"); FLAG_SET_DEFAULT(UseBlockZeroing, false); } assert(BlockCopyLowLimit > 0, "invalid value"); if (has_block_zeroing()) { // has_blk_init() && is_T4(): core's local L2 cache if (FLAG_IS_DEFAULT(UseBlockCopy)) { FLAG_SET_DEFAULT(UseBlockCopy, true); } } else if (UseBlockCopy) { warning("BIS instructions are not available or expensive on this CPU"); FLAG_SET_DEFAULT(UseBlockCopy, false); } #ifdef COMPILER2 // T4 and newer Sparc cpus have fast RDPC. if (has_fast_rdpc() && FLAG_IS_DEFAULT(UseRDPCForConstantTableBase)) { FLAG_SET_DEFAULT(UseRDPCForConstantTableBase, true); } // Currently not supported anywhere. FLAG_SET_DEFAULT(UseFPUForSpilling, false); MaxVectorSize = 8; assert((InteriorEntryAlignment % relocInfo::addr_unit()) == 0, "alignment is not a multiple of NOP size"); #endif assert((CodeEntryAlignment % relocInfo::addr_unit()) == 0, "alignment is not a multiple of NOP size"); assert((OptoLoopAlignment % relocInfo::addr_unit()) == 0, "alignment is not a multiple of NOP size"); char buf[512]; jio_snprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", (has_v9() ? ", v9" : (has_v8() ? ", v8" : "")), (has_hardware_popc() ? ", popc" : ""), (has_vis1() ? ", vis1" : ""), (has_vis2() ? ", vis2" : ""), (has_vis3() ? ", vis3" : ""), (has_blk_init() ? ", blk_init" : ""), (has_cbcond() ? ", cbcond" : ""), (has_aes() ? ", aes" : ""), (is_ultra3() ? ", ultra3" : ""), (is_sun4v() ? ", sun4v" : ""), (is_niagara_plus() ? ", niagara_plus" : (is_niagara() ? ", niagara" : "")), (is_sparc64() ? ", sparc64" : ""), (!has_hardware_mul32() ? ", no-mul32" : ""), (!has_hardware_div32() ? ", no-div32" : ""), (!has_hardware_fsmuld() ? ", no-fsmuld" : "")); // buf is started with ", " or is empty _features_str = strdup(strlen(buf) > 2 ? buf + 2 : buf); // UseVIS is set to the smallest of what hardware supports and what // the command line requires. I.e., you cannot set UseVIS to 3 on // older UltraSparc which do not support it. if (UseVIS > 3) UseVIS=3; if (UseVIS < 0) UseVIS=0; if (!has_vis3()) // Drop to 2 if no VIS3 support UseVIS = MIN2((intx)2,UseVIS); if (!has_vis2()) // Drop to 1 if no VIS2 support UseVIS = MIN2((intx)1,UseVIS); if (!has_vis1()) // Drop to 0 if no VIS1 support UseVIS = 0; // T2 and above should have support for AES instructions if (has_aes()) { if (UseVIS > 0) { // AES intrinsics use FXOR instruction which is VIS1 if (FLAG_IS_DEFAULT(UseAES)) { FLAG_SET_DEFAULT(UseAES, true); } if (FLAG_IS_DEFAULT(UseAESIntrinsics)) { FLAG_SET_DEFAULT(UseAESIntrinsics, true); } // we disable both the AES flags if either of them is disabled on the command line if (!UseAES || !UseAESIntrinsics) { FLAG_SET_DEFAULT(UseAES, false); FLAG_SET_DEFAULT(UseAESIntrinsics, false); } } else { if (UseAES || UseAESIntrinsics) { warning("SPARC AES intrinsics require VIS1 instruction support. Intrinsics will be disabled."); if (UseAES) { FLAG_SET_DEFAULT(UseAES, false); } if (UseAESIntrinsics) { FLAG_SET_DEFAULT(UseAESIntrinsics, false); } } } } else if (UseAES || UseAESIntrinsics) { warning("AES instructions are not available on this CPU"); if (UseAES) { FLAG_SET_DEFAULT(UseAES, false); } if (UseAESIntrinsics) { FLAG_SET_DEFAULT(UseAESIntrinsics, false); } } if (FLAG_IS_DEFAULT(ContendedPaddingWidth) && (cache_line_size > ContendedPaddingWidth)) ContendedPaddingWidth = cache_line_size; #ifndef PRODUCT if (PrintMiscellaneous && Verbose) { tty->print("Allocation"); if (AllocatePrefetchStyle <= 0) { tty->print_cr(": no prefetching"); } else { tty->print(" prefetching: "); if (AllocatePrefetchInstr == 0) { tty->print("PREFETCH"); } else if (AllocatePrefetchInstr == 1) { tty->print("BIS"); } if (AllocatePrefetchLines > 1) { tty->print_cr(" at distance %d, %d lines of %d bytes", AllocatePrefetchDistance, AllocatePrefetchLines, AllocatePrefetchStepSize); } else { tty->print_cr(" at distance %d, one line of %d bytes", AllocatePrefetchDistance, AllocatePrefetchStepSize); } } if (PrefetchCopyIntervalInBytes > 0) { tty->print_cr("PrefetchCopyIntervalInBytes %d", PrefetchCopyIntervalInBytes); } if (PrefetchScanIntervalInBytes > 0) { tty->print_cr("PrefetchScanIntervalInBytes %d", PrefetchScanIntervalInBytes); } if (PrefetchFieldsAhead > 0) { tty->print_cr("PrefetchFieldsAhead %d", PrefetchFieldsAhead); } if (ContendedPaddingWidth > 0) { tty->print_cr("ContendedPaddingWidth %d", ContendedPaddingWidth); } } #endif // PRODUCT }
void VM_Version::initialize() { _features = determine_features(); PrefetchCopyIntervalInBytes = prefetch_copy_interval_in_bytes(); PrefetchScanIntervalInBytes = prefetch_scan_interval_in_bytes(); PrefetchFieldsAhead = prefetch_fields_ahead(); // Allocation prefetch settings intx cache_line_size = L1_data_cache_line_size(); if( cache_line_size > AllocatePrefetchStepSize ) AllocatePrefetchStepSize = cache_line_size; if( FLAG_IS_DEFAULT(AllocatePrefetchLines) ) AllocatePrefetchLines = 3; // Optimistic value assert( AllocatePrefetchLines > 0, "invalid value"); if( AllocatePrefetchLines < 1 ) // set valid value in product VM AllocatePrefetchLines = 1; // Conservative value AllocatePrefetchDistance = allocate_prefetch_distance(); AllocatePrefetchStyle = allocate_prefetch_style(); assert(AllocatePrefetchDistance % AllocatePrefetchStepSize == 0, "invalid value"); UseSSE = 0; // Only on x86 and x64 _supports_cx8 = has_v9(); if (is_niagara1()) { // Indirect branch is the same cost as direct if (FLAG_IS_DEFAULT(UseInlineCaches)) { FLAG_SET_DEFAULT(UseInlineCaches, false); } #ifdef _LP64 // Single issue niagara1 is slower for CompressedOops // but niagaras after that it's fine. if (!is_niagara1_plus()) { if (FLAG_IS_DEFAULT(UseCompressedOops)) { FLAG_SET_ERGO(bool, UseCompressedOops, false); } } // 32-bit oops don't make sense for the 64-bit VM on sparc // since the 32-bit VM has the same registers and smaller objects. Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes); #endif // _LP64 #ifdef COMPILER2 // Indirect branch is the same cost as direct if (FLAG_IS_DEFAULT(UseJumpTables)) { FLAG_SET_DEFAULT(UseJumpTables, true); } // Single-issue, so entry and loop tops are // aligned on a single instruction boundary if (FLAG_IS_DEFAULT(InteriorEntryAlignment)) { FLAG_SET_DEFAULT(InteriorEntryAlignment, 4); } if (FLAG_IS_DEFAULT(OptoLoopAlignment)) { FLAG_SET_DEFAULT(OptoLoopAlignment, 4); } if (is_niagara1_plus() && FLAG_IS_DEFAULT(AllocatePrefetchDistance)) { // Use smaller prefetch distance on N2 FLAG_SET_DEFAULT(AllocatePrefetchDistance, 256); } #endif } // Use hardware population count instruction if available. if (has_hardware_popc()) { if (FLAG_IS_DEFAULT(UsePopCountInstruction)) { FLAG_SET_DEFAULT(UsePopCountInstruction, true); } } char buf[512]; jio_snprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s%s%s%s%s%s", (has_v8() ? ", has_v8" : ""), (has_v9() ? ", has_v9" : ""), (has_hardware_popc() ? ", popc" : ""), (has_vis1() ? ", has_vis1" : ""), (has_vis2() ? ", has_vis2" : ""), (is_ultra3() ? ", is_ultra3" : ""), (is_sun4v() ? ", is_sun4v" : ""), (is_niagara1() ? ", is_niagara1" : ""), (is_niagara1_plus() ? ", is_niagara1_plus" : ""), (!has_hardware_mul32() ? ", no-mul32" : ""), (!has_hardware_div32() ? ", no-div32" : ""), (!has_hardware_fsmuld() ? ", no-fsmuld" : "")); // buf is started with ", " or is empty _features_str = strdup(strlen(buf) > 2 ? buf + 2 : buf); #ifndef PRODUCT if (PrintMiscellaneous && Verbose) { tty->print("Allocation: "); if (AllocatePrefetchStyle <= 0) { tty->print_cr("no prefetching"); } else { if (AllocatePrefetchLines > 1) { tty->print_cr("PREFETCH %d, %d lines of size %d bytes", AllocatePrefetchDistance, AllocatePrefetchLines, AllocatePrefetchStepSize); } else { tty->print_cr("PREFETCH %d, one line", AllocatePrefetchDistance); } } if (PrefetchCopyIntervalInBytes > 0) { tty->print_cr("PrefetchCopyIntervalInBytes %d", PrefetchCopyIntervalInBytes); } if (PrefetchScanIntervalInBytes > 0) { tty->print_cr("PrefetchScanIntervalInBytes %d", PrefetchScanIntervalInBytes); } if (PrefetchFieldsAhead > 0) { tty->print_cr("PrefetchFieldsAhead %d", PrefetchFieldsAhead); } } #endif // PRODUCT }
void CollectorPolicy::initialize_flags() { assert(_space_alignment != 0, "Space alignment not set up properly"); assert(_heap_alignment != 0, "Heap alignment not set up properly"); assert(_heap_alignment >= _space_alignment, err_msg("heap_alignment: " SIZE_FORMAT " less than space_alignment: " SIZE_FORMAT, _heap_alignment, _space_alignment)); assert(_heap_alignment % _space_alignment == 0, err_msg("heap_alignment: " SIZE_FORMAT " not aligned by space_alignment: " SIZE_FORMAT, _heap_alignment, _space_alignment)); if (FLAG_IS_CMDLINE(MaxHeapSize)) { if (FLAG_IS_CMDLINE(InitialHeapSize) && InitialHeapSize > MaxHeapSize) { vm_exit_during_initialization("Initial heap size set to a larger value than the maximum heap size"); } if (_min_heap_byte_size != 0 && MaxHeapSize < _min_heap_byte_size) { vm_exit_during_initialization("Incompatible minimum and maximum heap sizes specified"); } _max_heap_size_cmdline = true; } // Check heap parameter properties if (InitialHeapSize < M) { vm_exit_during_initialization("Too small initial heap"); } if (_min_heap_byte_size < M) { vm_exit_during_initialization("Too small minimum heap"); } // User inputs from -Xmx and -Xms must be aligned _min_heap_byte_size = align_size_up(_min_heap_byte_size, _heap_alignment); uintx aligned_initial_heap_size = align_size_up(InitialHeapSize, _heap_alignment); uintx aligned_max_heap_size = align_size_up(MaxHeapSize, _heap_alignment); // Write back to flags if the values changed if (aligned_initial_heap_size != InitialHeapSize) { FLAG_SET_ERGO(uintx, InitialHeapSize, aligned_initial_heap_size); } if (aligned_max_heap_size != MaxHeapSize) { FLAG_SET_ERGO(uintx, MaxHeapSize, aligned_max_heap_size); } if (FLAG_IS_CMDLINE(InitialHeapSize) && _min_heap_byte_size != 0 && InitialHeapSize < _min_heap_byte_size) { vm_exit_during_initialization("Incompatible minimum and initial heap sizes specified"); } if (!FLAG_IS_DEFAULT(InitialHeapSize) && InitialHeapSize > MaxHeapSize) { FLAG_SET_ERGO(uintx, MaxHeapSize, InitialHeapSize); } else if (!FLAG_IS_DEFAULT(MaxHeapSize) && InitialHeapSize > MaxHeapSize) { FLAG_SET_ERGO(uintx, InitialHeapSize, MaxHeapSize); if (InitialHeapSize < _min_heap_byte_size) { _min_heap_byte_size = InitialHeapSize; } } _initial_heap_byte_size = InitialHeapSize; _max_heap_byte_size = MaxHeapSize; FLAG_SET_ERGO(uintx, MinHeapDeltaBytes, align_size_up(MinHeapDeltaBytes, _space_alignment)); DEBUG_ONLY(CollectorPolicy::assert_flags();) }
// Values set on the command line win over any ergonomically // set command line parameters. // Ergonomic choice of parameters are done before this // method is called. Values for command line parameters such as NewSize // and MaxNewSize feed those ergonomic choices into this method. // This method makes the final generation sizings consistent with // themselves and with overall heap sizings. // In the absence of explicitly set command line flags, policies // such as the use of NewRatio are used to size the generation. void GenCollectorPolicy::initialize_size_info() { CollectorPolicy::initialize_size_info(); // _space_alignment is used for alignment within a generation. // There is additional alignment done down stream for some // collectors that sometimes causes unwanted rounding up of // generations sizes. // Determine maximum size of gen0 size_t max_new_size = 0; if (!FLAG_IS_DEFAULT(MaxNewSize)) { max_new_size = MaxNewSize; } else { max_new_size = scale_by_NewRatio_aligned(_max_heap_byte_size); // Bound the maximum size by NewSize below (since it historically // would have been NewSize and because the NewRatio calculation could // yield a size that is too small) and bound it by MaxNewSize above. // Ergonomics plays here by previously calculating the desired // NewSize and MaxNewSize. max_new_size = MIN2(MAX2(max_new_size, NewSize), MaxNewSize); } assert(max_new_size > 0, "All paths should set max_new_size"); // Given the maximum gen0 size, determine the initial and // minimum gen0 sizes. if (_max_heap_byte_size == _min_heap_byte_size) { // The maximum and minimum heap sizes are the same so // the generations minimum and initial must be the // same as its maximum. _min_gen0_size = max_new_size; _initial_gen0_size = max_new_size; _max_gen0_size = max_new_size; } else { size_t desired_new_size = 0; if (FLAG_IS_CMDLINE(NewSize)) { // If NewSize is set on the command line, we must use it as // the initial size and it also makes sense to use it as the // lower limit. _min_gen0_size = NewSize; desired_new_size = NewSize; max_new_size = MAX2(max_new_size, NewSize); } else if (FLAG_IS_ERGO(NewSize)) { // If NewSize is set ergonomically, we should use it as a lower // limit, but use NewRatio to calculate the initial size. _min_gen0_size = NewSize; desired_new_size = MAX2(scale_by_NewRatio_aligned(_initial_heap_byte_size), NewSize); max_new_size = MAX2(max_new_size, NewSize); } else { // For the case where NewSize is the default, use NewRatio // to size the minimum and initial generation sizes. // Use the default NewSize as the floor for these values. If // NewRatio is overly large, the resulting sizes can be too // small. _min_gen0_size = MAX2(scale_by_NewRatio_aligned(_min_heap_byte_size), NewSize); desired_new_size = MAX2(scale_by_NewRatio_aligned(_initial_heap_byte_size), NewSize); } assert(_min_gen0_size > 0, "Sanity check"); _initial_gen0_size = desired_new_size; _max_gen0_size = max_new_size; // At this point the desirable initial and minimum sizes have been // determined without regard to the maximum sizes. // Bound the sizes by the corresponding overall heap sizes. _min_gen0_size = bound_minus_alignment(_min_gen0_size, _min_heap_byte_size); _initial_gen0_size = bound_minus_alignment(_initial_gen0_size, _initial_heap_byte_size); _max_gen0_size = bound_minus_alignment(_max_gen0_size, _max_heap_byte_size); // At this point all three sizes have been checked against the // maximum sizes but have not been checked for consistency // among the three. // Final check min <= initial <= max _min_gen0_size = MIN2(_min_gen0_size, _max_gen0_size); _initial_gen0_size = MAX2(MIN2(_initial_gen0_size, _max_gen0_size), _min_gen0_size); _min_gen0_size = MIN2(_min_gen0_size, _initial_gen0_size); } // Write back to flags if necessary if (NewSize != _initial_gen0_size) { FLAG_SET_ERGO(uintx, NewSize, _initial_gen0_size); } if (MaxNewSize != _max_gen0_size) { FLAG_SET_ERGO(uintx, MaxNewSize, _max_gen0_size); } if (PrintGCDetails && Verbose) { gclog_or_tty->print_cr("1: Minimum gen0 " SIZE_FORMAT " Initial gen0 " SIZE_FORMAT " Maximum gen0 " SIZE_FORMAT, _min_gen0_size, _initial_gen0_size, _max_gen0_size); } DEBUG_ONLY(GenCollectorPolicy::assert_size_info();) }
void GenCollectorPolicy::initialize_flags() { CollectorPolicy::initialize_flags(); assert(_gen_alignment != 0, "Generation alignment not set up properly"); assert(_heap_alignment >= _gen_alignment, err_msg("heap_alignment: " SIZE_FORMAT " less than gen_alignment: " SIZE_FORMAT, _heap_alignment, _gen_alignment)); assert(_gen_alignment % _space_alignment == 0, err_msg("gen_alignment: " SIZE_FORMAT " not aligned by space_alignment: " SIZE_FORMAT, _gen_alignment, _space_alignment)); assert(_heap_alignment % _gen_alignment == 0, err_msg("heap_alignment: " SIZE_FORMAT " not aligned by gen_alignment: " SIZE_FORMAT, _heap_alignment, _gen_alignment)); // All generational heaps have a youngest gen; handle those flags here // Make sure the heap is large enough for two generations uintx smallest_new_size = young_gen_size_lower_bound(); uintx smallest_heap_size = align_size_up(smallest_new_size + align_size_up(_space_alignment, _gen_alignment), _heap_alignment); if (MaxHeapSize < smallest_heap_size) { FLAG_SET_ERGO(uintx, MaxHeapSize, smallest_heap_size); _max_heap_byte_size = MaxHeapSize; } // If needed, synchronize _min_heap_byte size and _initial_heap_byte_size if (_min_heap_byte_size < smallest_heap_size) { _min_heap_byte_size = smallest_heap_size; if (InitialHeapSize < _min_heap_byte_size) { FLAG_SET_ERGO(uintx, InitialHeapSize, smallest_heap_size); _initial_heap_byte_size = smallest_heap_size; } } // Now take the actual NewSize into account. We will silently increase NewSize // if the user specified a smaller or unaligned value. smallest_new_size = MAX2(smallest_new_size, (uintx)align_size_down(NewSize, _gen_alignment)); if (smallest_new_size != NewSize) { // Do not use FLAG_SET_ERGO to update NewSize here, since this will override // if NewSize was set on the command line or not. This information is needed // later when setting the initial and minimum young generation size. NewSize = smallest_new_size; } _initial_gen0_size = NewSize; if (!FLAG_IS_DEFAULT(MaxNewSize)) { uintx min_new_size = MAX2(_gen_alignment, _min_gen0_size); if (MaxNewSize >= MaxHeapSize) { // Make sure there is room for an old generation uintx smaller_max_new_size = MaxHeapSize - _gen_alignment; if (FLAG_IS_CMDLINE(MaxNewSize)) { warning("MaxNewSize (" SIZE_FORMAT "k) is equal to or greater than the entire " "heap (" SIZE_FORMAT "k). A new max generation size of " SIZE_FORMAT "k will be used.", MaxNewSize/K, MaxHeapSize/K, smaller_max_new_size/K); } FLAG_SET_ERGO(uintx, MaxNewSize, smaller_max_new_size); if (NewSize > MaxNewSize) { FLAG_SET_ERGO(uintx, NewSize, MaxNewSize); _initial_gen0_size = NewSize; } } else if (MaxNewSize < min_new_size) { FLAG_SET_ERGO(uintx, MaxNewSize, min_new_size); } else if (!is_size_aligned(MaxNewSize, _gen_alignment)) { FLAG_SET_ERGO(uintx, MaxNewSize, align_size_down(MaxNewSize, _gen_alignment)); } _max_gen0_size = MaxNewSize; } if (NewSize > MaxNewSize) { // At this point this should only happen if the user specifies a large NewSize and/or // a small (but not too small) MaxNewSize. if (FLAG_IS_CMDLINE(MaxNewSize)) { warning("NewSize (" SIZE_FORMAT "k) is greater than the MaxNewSize (" SIZE_FORMAT "k). " "A new max generation size of " SIZE_FORMAT "k will be used.", NewSize/K, MaxNewSize/K, NewSize/K); } FLAG_SET_ERGO(uintx, MaxNewSize, NewSize); _max_gen0_size = MaxNewSize; } if (SurvivorRatio < 1 || NewRatio < 1) { vm_exit_during_initialization("Invalid young gen ratio specified"); } DEBUG_ONLY(GenCollectorPolicy::assert_flags();) }
void ReservedSpace::initialize(size_t size, size_t alignment, bool large, char* requested_address, const size_t noaccess_prefix, bool executable) { const size_t granularity = os::vm_allocation_granularity(); assert((size & (granularity - 1)) == 0, "size not aligned to os::vm_allocation_granularity()"); assert((alignment & (granularity - 1)) == 0, "alignment not aligned to os::vm_allocation_granularity()"); assert(alignment == 0 || is_power_of_2((intptr_t)alignment), "not a power of 2"); alignment = MAX2(alignment, (size_t)os::vm_page_size()); // Assert that if noaccess_prefix is used, it is the same as alignment. assert(noaccess_prefix == 0 || noaccess_prefix == alignment, "noaccess prefix wrong"); _base = NULL; _size = 0; _special = false; _executable = executable; _alignment = 0; _noaccess_prefix = 0; if (size == 0) { return; } // If OS doesn't support demand paging for large page memory, we need // to use reserve_memory_special() to reserve and pin the entire region. bool special = large && !os::can_commit_large_page_memory(); char* base = NULL; if (requested_address != 0) { requested_address -= noaccess_prefix; // adjust requested address assert(requested_address != NULL, "huge noaccess prefix?"); } if (special) { base = os::reserve_memory_special(size, requested_address, executable); if (base != NULL) { if (failed_to_reserve_as_requested(base, requested_address, size, true)) { // OS ignored requested address. Try different address. return; } // Check alignment constraints assert((uintptr_t) base % alignment == 0, "Large pages returned a non-aligned address"); _special = true; } else { // failed; try to reserve regular memory below if (UseLargePages && (!FLAG_IS_DEFAULT(UseLargePages) || !FLAG_IS_DEFAULT(LargePageSizeInBytes))) { if (PrintCompressedOopsMode) { tty->cr(); tty->print_cr("Reserve regular memory without large pages."); } } } } if (base == NULL) { // Optimistically assume that the OSes returns an aligned base pointer. // When reserving a large address range, most OSes seem to align to at // least 64K. // If the memory was requested at a particular address, use // os::attempt_reserve_memory_at() to avoid over mapping something // important. If available space is not detected, return NULL. if (requested_address != 0) { base = os::attempt_reserve_memory_at(size, requested_address); if (failed_to_reserve_as_requested(base, requested_address, size, false)) { // OS ignored requested address. Try different address. base = NULL; } } else { base = os::reserve_memory(size, NULL, alignment); } if (base == NULL) return; // Check alignment constraints if ((((size_t)base + noaccess_prefix) & (alignment - 1)) != 0) { // Base not aligned, retry if (!os::release_memory(base, size)) fatal("os::release_memory failed"); // Make sure that size is aligned size = align_size_up(size, alignment); base = os::reserve_memory_aligned(size, alignment); if (requested_address != 0 && failed_to_reserve_as_requested(base, requested_address, size, false)) { // As a result of the alignment constraints, the allocated base differs // from the requested address. Return back to the caller who can // take remedial action (like try again without a requested address). assert(_base == NULL, "should be"); return; } } } // Done _base = base; _size = size; _alignment = alignment; _noaccess_prefix = noaccess_prefix; // Assert that if noaccess_prefix is used, it is the same as alignment. assert(noaccess_prefix == 0 || noaccess_prefix == _alignment, "noaccess prefix wrong"); assert(markOopDesc::encode_pointer_as_mark(_base)->decode_pointer() == _base, "area must be distinguisable from marks for mark-sweep"); assert(markOopDesc::encode_pointer_as_mark(&_base[size])->decode_pointer() == &_base[size], "area must be distinguisable from marks for mark-sweep"); }
void TwoGenerationCollectorPolicy::initialize_size_info() { GenCollectorPolicy::initialize_size_info(); // At this point the minimum, initial and maximum sizes // of the overall heap and of gen0 have been determined. // The maximum gen1 size can be determined from the maximum gen0 // and maximum heap size since not explicit flags exits // for setting the gen1 maximum. _max_gen1_size = max_heap_byte_size() - _max_gen0_size; _max_gen1_size = MAX2((size_t)align_size_down(_max_gen1_size, min_alignment()), min_alignment()); // If no explicit command line flag has been set for the // gen1 size, use what is left for gen1. if (FLAG_IS_DEFAULT(OldSize) || FLAG_IS_ERGO(OldSize)) { // The user has not specified any value or ergonomics // has chosen a value (which may or may not be consistent // with the overall heap size). In either case make // the minimum, maximum and initial sizes consistent // with the gen0 sizes and the overall heap sizes. assert(min_heap_byte_size() > _min_gen0_size, "gen0 has an unexpected minimum size"); set_min_gen1_size(min_heap_byte_size() - min_gen0_size()); set_min_gen1_size( MAX2((size_t)align_size_down(_min_gen1_size, min_alignment()), min_alignment())); set_initial_gen1_size(initial_heap_byte_size() - initial_gen0_size()); set_initial_gen1_size( MAX2((size_t)align_size_down(_initial_gen1_size, min_alignment()), min_alignment())); } else { // It's been explicitly set on the command line. Use the // OldSize and then determine the consequences. set_min_gen1_size(OldSize); set_initial_gen1_size(OldSize); // If the user has explicitly set an OldSize that is inconsistent // with other command line flags, issue a warning. // The generation minimums and the overall heap mimimum should // be within one heap alignment. if ((_min_gen1_size + _min_gen0_size + min_alignment()) < min_heap_byte_size()) { warning("Inconsistency between minimum heap size and minimum " "generation sizes: using minimum heap = " SIZE_FORMAT, min_heap_byte_size()); } if ((OldSize > _max_gen1_size)) { warning("Inconsistency between maximum heap size and maximum " "generation sizes: using maximum heap = " SIZE_FORMAT " -XX:OldSize flag is being ignored", max_heap_byte_size()); } // If there is an inconsistency between the OldSize and the minimum and/or // initial size of gen0, since OldSize was explicitly set, OldSize wins. if (adjust_gen0_sizes(&_min_gen0_size, &_min_gen1_size, min_heap_byte_size(), OldSize)) { if (PrintGCDetails && Verbose) { gclog_or_tty->print_cr("Minimum gen0 " SIZE_FORMAT " Initial gen0 " SIZE_FORMAT " Maximum gen0 " SIZE_FORMAT, min_gen0_size(), initial_gen0_size(), max_gen0_size()); } } // Initial size if (adjust_gen0_sizes(&_initial_gen0_size, &_initial_gen1_size, initial_heap_byte_size(), OldSize)) { if (PrintGCDetails && Verbose) { gclog_or_tty->print_cr("Minimum gen0 " SIZE_FORMAT " Initial gen0 " SIZE_FORMAT " Maximum gen0 " SIZE_FORMAT, min_gen0_size(), initial_gen0_size(), max_gen0_size()); } } } // Enforce the maximum gen1 size. set_min_gen1_size(MIN2(_min_gen1_size, _max_gen1_size)); // Check that min gen1 <= initial gen1 <= max gen1 set_initial_gen1_size(MAX2(_initial_gen1_size, _min_gen1_size)); set_initial_gen1_size(MIN2(_initial_gen1_size, _max_gen1_size)); if (PrintGCDetails && Verbose) { gclog_or_tty->print_cr("Minimum gen1 " SIZE_FORMAT " Initial gen1 " SIZE_FORMAT " Maximum gen1 " SIZE_FORMAT, min_gen1_size(), initial_gen1_size(), max_gen1_size()); } }
// Values set on the command line win over any ergonomically // set command line parameters. // Ergonomic choice of parameters are done before this // method is called. Values for command line parameters such as NewSize // and MaxNewSize feed those ergonomic choices into this method. // This method makes the final generation sizings consistent with // themselves and with overall heap sizings. // In the absence of explicitly set command line flags, policies // such as the use of NewRatio are used to size the generation. void GenCollectorPolicy::initialize_size_info() { CollectorPolicy::initialize_size_info(); // min_alignment() is used for alignment within a generation. // There is additional alignment done down stream for some // collectors that sometimes causes unwanted rounding up of // generations sizes. // Determine maximum size of gen0 size_t max_new_size = 0; if (FLAG_IS_CMDLINE(MaxNewSize)) { if (MaxNewSize < min_alignment()) { max_new_size = min_alignment(); } else if (MaxNewSize >= max_heap_byte_size()) { max_new_size = align_size_down(max_heap_byte_size() - min_alignment(), min_alignment()); warning("MaxNewSize (" SIZE_FORMAT "k) is equal to or " "greater than the entire heap (" SIZE_FORMAT "k). A " "new generation size of " SIZE_FORMAT "k will be used.", MaxNewSize/K, max_heap_byte_size()/K, max_new_size/K); } else { max_new_size = align_size_down(MaxNewSize, min_alignment()); } // The case for FLAG_IS_ERGO(MaxNewSize) could be treated // specially at this point to just use an ergonomically set // MaxNewSize to set max_new_size. For cases with small // heaps such a policy often did not work because the MaxNewSize // was larger than the entire heap. The interpretation given // to ergonomically set flags is that the flags are set // by different collectors for their own special needs but // are not allowed to badly shape the heap. This allows the // different collectors to decide what's best for themselves // without having to factor in the overall heap shape. It // can be the case in the future that the collectors would // only make "wise" ergonomics choices and this policy could // just accept those choices. The choices currently made are // not always "wise". } else { max_new_size = scale_by_NewRatio_aligned(max_heap_byte_size()); // Bound the maximum size by NewSize below (since it historically // would have been NewSize and because the NewRatio calculation could // yield a size that is too small) and bound it by MaxNewSize above. // Ergonomics plays here by previously calculating the desired // NewSize and MaxNewSize. max_new_size = MIN2(MAX2(max_new_size, (size_t)NewSize), (size_t)MaxNewSize); } assert(max_new_size > 0, "All paths should set max_new_size"); // Given the maximum gen0 size, determine the initial and // minimum sizes. if (max_heap_byte_size() == min_heap_byte_size()) { // The maximum and minimum heap sizes are the same so // the generations minimum and initial must be the // same as its maximum. set_min_gen0_size(max_new_size); set_initial_gen0_size(max_new_size); set_max_gen0_size(max_new_size); } else { size_t desired_new_size = 0; if (!FLAG_IS_DEFAULT(NewSize)) { // If NewSize is set ergonomically (for example by cms), it // would make sense to use it. If it is used, also use it // to set the initial size. Although there is no reason // the minimum size and the initial size have to be the same, // the current implementation gets into trouble during the calculation // of the tenured generation sizes if they are different. // Note that this makes the initial size and the minimum size // generally small compared to the NewRatio calculation. _min_gen0_size = NewSize; desired_new_size = NewSize; max_new_size = MAX2(max_new_size, (size_t) NewSize); } else { // For the case where NewSize is the default, use NewRatio // to size the minimum and initial generation sizes. // Use the default NewSize as the floor for these values. If // NewRatio is overly large, the resulting sizes can be too // small. _min_gen0_size = MAX2(scale_by_NewRatio_aligned(min_heap_byte_size()), (size_t) NewSize); desired_new_size = MAX2(scale_by_NewRatio_aligned(initial_heap_byte_size()), (size_t) NewSize); } assert(_min_gen0_size > 0, "Sanity check"); set_initial_gen0_size(desired_new_size); set_max_gen0_size(max_new_size); // At this point the desirable initial and minimum sizes have been // determined without regard to the maximum sizes. // Bound the sizes by the corresponding overall heap sizes. set_min_gen0_size( bound_minus_alignment(_min_gen0_size, min_heap_byte_size())); set_initial_gen0_size( bound_minus_alignment(_initial_gen0_size, initial_heap_byte_size())); set_max_gen0_size( bound_minus_alignment(_max_gen0_size, max_heap_byte_size())); // At this point all three sizes have been checked against the // maximum sizes but have not been checked for consistency // among the three. // Final check min <= initial <= max set_min_gen0_size(MIN2(_min_gen0_size, _max_gen0_size)); set_initial_gen0_size( MAX2(MIN2(_initial_gen0_size, _max_gen0_size), _min_gen0_size)); set_min_gen0_size(MIN2(_min_gen0_size, _initial_gen0_size)); } if (PrintGCDetails && Verbose) { gclog_or_tty->print_cr("Minimum gen0 " SIZE_FORMAT " Initial gen0 " SIZE_FORMAT " Maximum gen0 " SIZE_FORMAT, min_gen0_size(), initial_gen0_size(), max_gen0_size()); } }
void VM_Version::get_processor_features() { _supports_cx8 = true; _supports_atomic_getset4 = true; _supports_atomic_getadd4 = true; _supports_atomic_getset8 = true; _supports_atomic_getadd8 = true; if (FLAG_IS_DEFAULT(AllocatePrefetchDistance)) FLAG_SET_DEFAULT(AllocatePrefetchDistance, 256); if (FLAG_IS_DEFAULT(AllocatePrefetchStepSize)) FLAG_SET_DEFAULT(AllocatePrefetchStepSize, 64); FLAG_SET_DEFAULT(PrefetchScanIntervalInBytes, 256); FLAG_SET_DEFAULT(PrefetchFieldsAhead, 256); FLAG_SET_DEFAULT(PrefetchCopyIntervalInBytes, 256); FLAG_SET_DEFAULT(UseSSE42Intrinsics, true); unsigned long auxv = getauxval(AT_HWCAP); char buf[512]; _features = auxv; int cpu_lines = 0; if (FILE *f = fopen("/proc/cpuinfo", "r")) { char buf[128], *p; while (fgets(buf, sizeof (buf), f) != NULL) { if (p = strchr(buf, ':')) { long v = strtol(p+1, NULL, 0); if (strncmp(buf, "CPU implementer", sizeof "CPU implementer" - 1) == 0) { _cpu = v; cpu_lines++; } else if (strncmp(buf, "CPU variant", sizeof "CPU variant" - 1) == 0) { _variant = v; } else if (strncmp(buf, "CPU part", sizeof "CPU part" - 1) == 0) { if (_model != v) _model2 = _model; _model = v; } else if (strncmp(buf, "CPU revision", sizeof "CPU revision" - 1) == 0) { _revision = v; } } } fclose(f); } // Enable vendor specific features if (_cpu == CPU_CAVIUM && _variant == 0) _features |= CPU_DMB_ATOMICS; if (_cpu == CPU_ARM && (_model == 0xd03 || _model2 == 0xd03)) _features |= CPU_A53MAC; // If an olde style /proc/cpuinfo (cpu_lines == 1) then if _model is an A57 (0xd07) // we assume the worst and assume we could be on a big little system and have // undisclosed A53 cores which we could be swapped to at any stage if (_cpu == CPU_ARM && cpu_lines == 1 && _model == 0xd07) _features |= CPU_A53MAC; sprintf(buf, "0x%02x:0x%x:0x%03x:%d", _cpu, _variant, _model, _revision); if (_model2) sprintf(buf+strlen(buf), "(0x%03x)", _model2); if (auxv & HWCAP_ASIMD) strcat(buf, ", simd"); if (auxv & HWCAP_CRC32) strcat(buf, ", crc"); if (auxv & HWCAP_AES) strcat(buf, ", aes"); if (auxv & HWCAP_SHA1) strcat(buf, ", sha1"); if (auxv & HWCAP_SHA2) strcat(buf, ", sha256"); _features_string = os::strdup(buf); if (FLAG_IS_DEFAULT(UseCRC32)) { UseCRC32 = (auxv & HWCAP_CRC32) != 0; } if (UseCRC32 && (auxv & HWCAP_CRC32) == 0) { warning("UseCRC32 specified, but not supported on this CPU"); } if (FLAG_IS_DEFAULT(UseAdler32Intrinsics)) { FLAG_SET_DEFAULT(UseAdler32Intrinsics, true); } if (UseVectorizedMismatchIntrinsic) { warning("UseVectorizedMismatchIntrinsic specified, but not available on this CPU."); FLAG_SET_DEFAULT(UseVectorizedMismatchIntrinsic, false); } if (auxv & HWCAP_AES) { UseAES = UseAES || FLAG_IS_DEFAULT(UseAES); UseAESIntrinsics = UseAESIntrinsics || (UseAES && FLAG_IS_DEFAULT(UseAESIntrinsics)); if (UseAESIntrinsics && !UseAES) { warning("UseAESIntrinsics enabled, but UseAES not, enabling"); UseAES = true; } } else { if (UseAES) { warning("UseAES specified, but not supported on this CPU"); } if (UseAESIntrinsics) { warning("UseAESIntrinsics specified, but not supported on this CPU"); } } if (UseAESCTRIntrinsics) { warning("AES/CTR intrinsics are not available on this CPU"); FLAG_SET_DEFAULT(UseAESCTRIntrinsics, false); } if (FLAG_IS_DEFAULT(UseCRC32Intrinsics)) { UseCRC32Intrinsics = true; } if (auxv & HWCAP_CRC32) { if (FLAG_IS_DEFAULT(UseCRC32CIntrinsics)) { FLAG_SET_DEFAULT(UseCRC32CIntrinsics, true); } } else if (UseCRC32CIntrinsics) { warning("CRC32C is not available on the CPU"); FLAG_SET_DEFAULT(UseCRC32CIntrinsics, false); } if (auxv & (HWCAP_SHA1 | HWCAP_SHA2)) { if (FLAG_IS_DEFAULT(UseSHA)) { FLAG_SET_DEFAULT(UseSHA, true); } } else if (UseSHA) { warning("SHA instructions are not available on this CPU"); FLAG_SET_DEFAULT(UseSHA, false); } if (UseSHA && (auxv & HWCAP_SHA1)) { if (FLAG_IS_DEFAULT(UseSHA1Intrinsics)) { FLAG_SET_DEFAULT(UseSHA1Intrinsics, true); } } else if (UseSHA1Intrinsics) { warning("Intrinsics for SHA-1 crypto hash functions not available on this CPU."); FLAG_SET_DEFAULT(UseSHA1Intrinsics, false); } if (UseSHA && (auxv & HWCAP_SHA2)) { if (FLAG_IS_DEFAULT(UseSHA256Intrinsics)) { FLAG_SET_DEFAULT(UseSHA256Intrinsics, true); } } else if (UseSHA256Intrinsics) { warning("Intrinsics for SHA-224 and SHA-256 crypto hash functions not available on this CPU."); FLAG_SET_DEFAULT(UseSHA256Intrinsics, false); } if (UseSHA512Intrinsics) { warning("Intrinsics for SHA-384 and SHA-512 crypto hash functions not available on this CPU."); FLAG_SET_DEFAULT(UseSHA512Intrinsics, false); } if (!(UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics)) { FLAG_SET_DEFAULT(UseSHA, false); } if (auxv & HWCAP_PMULL) { if (FLAG_IS_DEFAULT(UseGHASHIntrinsics)) { FLAG_SET_DEFAULT(UseGHASHIntrinsics, true); } } else if (UseGHASHIntrinsics) { warning("GHASH intrinsics are not available on this CPU"); FLAG_SET_DEFAULT(UseGHASHIntrinsics, false); } // This machine allows unaligned memory accesses if (FLAG_IS_DEFAULT(UseUnalignedAccesses)) { FLAG_SET_DEFAULT(UseUnalignedAccesses, true); } if (FLAG_IS_DEFAULT(UseMultiplyToLenIntrinsic)) { UseMultiplyToLenIntrinsic = true; } if (FLAG_IS_DEFAULT(UseBarriersForVolatile)) { UseBarriersForVolatile = (_features & CPU_DMB_ATOMICS) != 0; } if (FLAG_IS_DEFAULT(UsePopCountInstruction)) { UsePopCountInstruction = true; } if (FLAG_IS_DEFAULT(UseMontgomeryMultiplyIntrinsic)) { UseMontgomeryMultiplyIntrinsic = true; } if (FLAG_IS_DEFAULT(UseMontgomerySquareIntrinsic)) { UseMontgomerySquareIntrinsic = true; } #ifdef COMPILER2 if (FLAG_IS_DEFAULT(OptoScheduling)) { OptoScheduling = true; } #endif }
void VM_Version::initialize() { _features = determine_features(); PrefetchCopyIntervalInBytes = prefetch_copy_interval_in_bytes(); PrefetchScanIntervalInBytes = prefetch_scan_interval_in_bytes(); PrefetchFieldsAhead = prefetch_fields_ahead(); // Allocation prefetch settings intx cache_line_size = prefetch_data_size(); if( cache_line_size > AllocatePrefetchStepSize ) AllocatePrefetchStepSize = cache_line_size; assert(AllocatePrefetchLines > 0, "invalid value"); if( AllocatePrefetchLines < 1 ) // set valid value in product VM AllocatePrefetchLines = 3; assert(AllocateInstancePrefetchLines > 0, "invalid value"); if( AllocateInstancePrefetchLines < 1 ) // set valid value in product VM AllocateInstancePrefetchLines = 1; 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); } guarantee(VM_Version::has_v9(), "only SPARC v9 is supported"); UseSSE = 0; // Only on x86 and x64 _supports_cx8 = has_v9(); _supports_atomic_getset4 = true; // swap instruction if (is_niagara()) { // Indirect branch is the same cost as direct if (FLAG_IS_DEFAULT(UseInlineCaches)) { FLAG_SET_DEFAULT(UseInlineCaches, false); } // Align loops on a single instruction boundary. if (FLAG_IS_DEFAULT(OptoLoopAlignment)) { FLAG_SET_DEFAULT(OptoLoopAlignment, 4); } #ifdef _LP64 // 32-bit oops don't make sense for the 64-bit VM on sparc // since the 32-bit VM has the same registers and smaller objects. Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes); Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes); #endif // _LP64 #ifdef COMPILER2 // Indirect branch is the same cost as direct if (FLAG_IS_DEFAULT(UseJumpTables)) { FLAG_SET_DEFAULT(UseJumpTables, true); } // Single-issue, so entry and loop tops are // aligned on a single instruction boundary if (FLAG_IS_DEFAULT(InteriorEntryAlignment)) { FLAG_SET_DEFAULT(InteriorEntryAlignment, 4); } if (is_niagara_plus()) { 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)) { // Use smaller prefetch distance with BIS FLAG_SET_DEFAULT(AllocatePrefetchDistance, 64); } } if (is_T4()) { // Double number of prefetched cache lines on T4 // since L2 cache line size is smaller (32 bytes). if (FLAG_IS_DEFAULT(AllocatePrefetchLines)) { FLAG_SET_ERGO(intx, AllocatePrefetchLines, AllocatePrefetchLines*2); } if (FLAG_IS_DEFAULT(AllocateInstancePrefetchLines)) { 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 a space at the end of TLAB for BIS since it // will fault when accessing memory outside of heap. // +1 for rounding up to next cache line, +1 to be safe int lines = AllocatePrefetchLines + 2; int step_size = AllocatePrefetchStepSize; int distance = AllocatePrefetchDistance; _reserve_for_allocation_prefetch = (distance + step_size*lines)/(int)HeapWordSize; } } #endif } // Use hardware population count instruction if available. if (has_hardware_popc()) { if (FLAG_IS_DEFAULT(UsePopCountInstruction)) { FLAG_SET_DEFAULT(UsePopCountInstruction, true); } } else if (UsePopCountInstruction) { warning("POPC instruction is not available on this CPU"); FLAG_SET_DEFAULT(UsePopCountInstruction, false); } // T4 and newer Sparc cpus have new compare and branch instruction. if (has_cbcond()) { if (FLAG_IS_DEFAULT(UseCBCond)) { FLAG_SET_DEFAULT(UseCBCond, true); } } else if (UseCBCond) { warning("CBCOND instruction is not available on this CPU"); FLAG_SET_DEFAULT(UseCBCond, false); } assert(BlockZeroingLowLimit > 0, "invalid value"); if (has_block_zeroing() && cache_line_size > 0) { if (FLAG_IS_DEFAULT(UseBlockZeroing)) { FLAG_SET_DEFAULT(UseBlockZeroing, true); } } else if (UseBlockZeroing) { warning("BIS zeroing instructions are not available on this CPU"); FLAG_SET_DEFAULT(UseBlockZeroing, false); } assert(BlockCopyLowLimit > 0, "invalid value"); if (has_block_zeroing() && cache_line_size > 0) { // has_blk_init() && is_T4(): core's local L2 cache if (FLAG_IS_DEFAULT(UseBlockCopy)) { FLAG_SET_DEFAULT(UseBlockCopy, true); } } else if (UseBlockCopy) { warning("BIS instructions are not available or expensive on this CPU"); FLAG_SET_DEFAULT(UseBlockCopy, false); } #ifdef COMPILER2 // T4 and newer Sparc cpus have fast RDPC. if (has_fast_rdpc() && FLAG_IS_DEFAULT(UseRDPCForConstantTableBase)) { FLAG_SET_DEFAULT(UseRDPCForConstantTableBase, true); } // Currently not supported anywhere. FLAG_SET_DEFAULT(UseFPUForSpilling, false); MaxVectorSize = 8; assert((InteriorEntryAlignment % relocInfo::addr_unit()) == 0, "alignment is not a multiple of NOP size"); #endif assert((CodeEntryAlignment % relocInfo::addr_unit()) == 0, "alignment is not a multiple of NOP size"); assert((OptoLoopAlignment % relocInfo::addr_unit()) == 0, "alignment is not a multiple of NOP size"); char buf[512]; jio_snprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", (has_v9() ? ", v9" : (has_v8() ? ", v8" : "")), (has_hardware_popc() ? ", popc" : ""), (has_vis1() ? ", vis1" : ""), (has_vis2() ? ", vis2" : ""), (has_vis3() ? ", vis3" : ""), (has_blk_init() ? ", blk_init" : ""), (has_cbcond() ? ", cbcond" : ""), (has_aes() ? ", aes" : ""), (has_sha1() ? ", sha1" : ""), (has_sha256() ? ", sha256" : ""), (has_sha512() ? ", sha512" : ""), (has_crc32c() ? ", crc32c" : ""), (is_ultra3() ? ", ultra3" : ""), (is_sun4v() ? ", sun4v" : ""), (is_niagara_plus() ? ", niagara_plus" : (is_niagara() ? ", niagara" : "")), (is_sparc64() ? ", sparc64" : ""), (!has_hardware_mul32() ? ", no-mul32" : ""), (!has_hardware_div32() ? ", no-div32" : ""), (!has_hardware_fsmuld() ? ", no-fsmuld" : "")); // buf is started with ", " or is empty _features_str = os::strdup(strlen(buf) > 2 ? buf + 2 : buf); // UseVIS is set to the smallest of what hardware supports and what // the command line requires. I.e., you cannot set UseVIS to 3 on // older UltraSparc which do not support it. if (UseVIS > 3) UseVIS=3; if (UseVIS < 0) UseVIS=0; if (!has_vis3()) // Drop to 2 if no VIS3 support UseVIS = MIN2((intx)2,UseVIS); if (!has_vis2()) // Drop to 1 if no VIS2 support UseVIS = MIN2((intx)1,UseVIS); if (!has_vis1()) // Drop to 0 if no VIS1 support UseVIS = 0; // SPARC T4 and above should have support for AES instructions if (has_aes()) { if (FLAG_IS_DEFAULT(UseAES)) { FLAG_SET_DEFAULT(UseAES, true); } if (!UseAES) { if (UseAESIntrinsics && !FLAG_IS_DEFAULT(UseAESIntrinsics)) { warning("AES intrinsics require UseAES flag to be enabled. Intrinsics will be disabled."); } FLAG_SET_DEFAULT(UseAESIntrinsics, false); } else { // The AES intrinsic stubs require AES instruction support (of course) // but also require VIS3 mode or higher for instructions it use. if (UseVIS > 2) { if (FLAG_IS_DEFAULT(UseAESIntrinsics)) { FLAG_SET_DEFAULT(UseAESIntrinsics, true); } } else { if (UseAESIntrinsics && !FLAG_IS_DEFAULT(UseAESIntrinsics)) { warning("SPARC AES intrinsics require VIS3 instructions. Intrinsics will be disabled."); } FLAG_SET_DEFAULT(UseAESIntrinsics, false); } } } else if (UseAES || UseAESIntrinsics) { if (UseAES && !FLAG_IS_DEFAULT(UseAES)) { warning("AES instructions are not available on this CPU"); FLAG_SET_DEFAULT(UseAES, false); } if (UseAESIntrinsics && !FLAG_IS_DEFAULT(UseAESIntrinsics)) { warning("AES intrinsics are not available on this CPU"); FLAG_SET_DEFAULT(UseAESIntrinsics, false); } } // GHASH/GCM intrinsics if (has_vis3() && (UseVIS > 2)) { if (FLAG_IS_DEFAULT(UseGHASHIntrinsics)) { UseGHASHIntrinsics = true; } } else if (UseGHASHIntrinsics) { if (!FLAG_IS_DEFAULT(UseGHASHIntrinsics)) warning("GHASH intrinsics require VIS3 instruction support. Intrinsics will be disabled"); FLAG_SET_DEFAULT(UseGHASHIntrinsics, false); } // SHA1, SHA256, and SHA512 instructions were added to SPARC T-series at different times if (has_sha1() || has_sha256() || has_sha512()) { if (UseVIS > 0) { // SHA intrinsics use VIS1 instructions if (FLAG_IS_DEFAULT(UseSHA)) { FLAG_SET_DEFAULT(UseSHA, true); } } else { if (UseSHA) { warning("SPARC SHA intrinsics require VIS1 instruction support. Intrinsics will be disabled."); FLAG_SET_DEFAULT(UseSHA, false); } } } else if (UseSHA) { warning("SHA instructions are not available on this CPU"); FLAG_SET_DEFAULT(UseSHA, false); } if (UseSHA && has_sha1()) { if (FLAG_IS_DEFAULT(UseSHA1Intrinsics)) { FLAG_SET_DEFAULT(UseSHA1Intrinsics, true); } } else if (UseSHA1Intrinsics) { warning("Intrinsics for SHA-1 crypto hash functions not available on this CPU."); FLAG_SET_DEFAULT(UseSHA1Intrinsics, false); } if (UseSHA && has_sha256()) { if (FLAG_IS_DEFAULT(UseSHA256Intrinsics)) { FLAG_SET_DEFAULT(UseSHA256Intrinsics, true); } } else if (UseSHA256Intrinsics) { warning("Intrinsics for SHA-224 and SHA-256 crypto hash functions not available on this CPU."); FLAG_SET_DEFAULT(UseSHA256Intrinsics, false); } if (UseSHA && has_sha512()) { if (FLAG_IS_DEFAULT(UseSHA512Intrinsics)) { FLAG_SET_DEFAULT(UseSHA512Intrinsics, true); } } else if (UseSHA512Intrinsics) { warning("Intrinsics for SHA-384 and SHA-512 crypto hash functions not available on this CPU."); FLAG_SET_DEFAULT(UseSHA512Intrinsics, false); } if (!(UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics)) { FLAG_SET_DEFAULT(UseSHA, false); } // SPARC T4 and above should have support for CRC32C instruction if (has_crc32c()) { if (UseVIS > 2) { // CRC32C intrinsics use VIS3 instructions if (FLAG_IS_DEFAULT(UseCRC32CIntrinsics)) { FLAG_SET_DEFAULT(UseCRC32CIntrinsics, true); } } else { if (UseCRC32CIntrinsics) { warning("SPARC CRC32C intrinsics require VIS3 instruction support. Intrinsics will be disabled."); FLAG_SET_DEFAULT(UseCRC32CIntrinsics, false); } } } else if (UseCRC32CIntrinsics) { warning("CRC32C instruction is not available on this CPU"); FLAG_SET_DEFAULT(UseCRC32CIntrinsics, false); } if (UseVIS > 2) { if (FLAG_IS_DEFAULT(UseAdler32Intrinsics)) { FLAG_SET_DEFAULT(UseAdler32Intrinsics, true); } } else if (UseAdler32Intrinsics) { warning("SPARC Adler32 intrinsics require VIS3 instruction support. Intrinsics will be disabled."); FLAG_SET_DEFAULT(UseAdler32Intrinsics, false); } if (UseVIS > 2) { if (FLAG_IS_DEFAULT(UseCRC32Intrinsics)) { FLAG_SET_DEFAULT(UseCRC32Intrinsics, true); } } else if (UseCRC32Intrinsics) { warning("SPARC CRC32 intrinsics require VIS3 insructions support. Intriniscs will be disabled"); FLAG_SET_DEFAULT(UseCRC32Intrinsics, false); } if (FLAG_IS_DEFAULT(ContendedPaddingWidth) && (cache_line_size > ContendedPaddingWidth)) ContendedPaddingWidth = cache_line_size; // This machine does not allow unaligned memory accesses if (UseUnalignedAccesses) { if (!FLAG_IS_DEFAULT(UseUnalignedAccesses)) warning("Unaligned memory access is not available on this CPU"); FLAG_SET_DEFAULT(UseUnalignedAccesses, false); } if (PrintMiscellaneous && Verbose) { tty->print_cr("L1 data cache line size: %u", L1_data_cache_line_size()); tty->print_cr("L2 data cache line size: %u", L2_data_cache_line_size()); tty->print("Allocation"); if (AllocatePrefetchStyle <= 0) { tty->print_cr(": no prefetching"); } else { tty->print(" prefetching: "); if (AllocatePrefetchInstr == 0) { tty->print("PREFETCH"); } else if (AllocatePrefetchInstr == 1) { tty->print("BIS"); } if (AllocatePrefetchLines > 1) { tty->print_cr(" at distance %d, %d lines of %d bytes", (int) AllocatePrefetchDistance, (int) AllocatePrefetchLines, (int) AllocatePrefetchStepSize); } else { tty->print_cr(" at distance %d, one line of %d bytes", (int) AllocatePrefetchDistance, (int) AllocatePrefetchStepSize); } } if (PrefetchCopyIntervalInBytes > 0) { tty->print_cr("PrefetchCopyIntervalInBytes %d", (int) PrefetchCopyIntervalInBytes); } if (PrefetchScanIntervalInBytes > 0) { tty->print_cr("PrefetchScanIntervalInBytes %d", (int) PrefetchScanIntervalInBytes); } if (PrefetchFieldsAhead > 0) { tty->print_cr("PrefetchFieldsAhead %d", (int) PrefetchFieldsAhead); } if (ContendedPaddingWidth > 0) { tty->print_cr("ContendedPaddingWidth %d", (int) ContendedPaddingWidth); } } }
void VM_Version::get_processor_features() { _cpu = 4; // 486 by default _model = 0; _stepping = 0; _cpuFeatures = 0; _logical_processors_per_package = 1; if (!Use486InstrsOnly) { // Get raw processor info getPsrInfo_stub(&_cpuid_info); assert_is_initialized(); _cpu = extended_cpu_family(); _model = extended_cpu_model(); _stepping = cpu_stepping(); if (cpu_family() > 4) { // it supports CPUID _cpuFeatures = feature_flags(); // Logical processors are only available on P4s and above, // and only if hyperthreading is available. _logical_processors_per_package = logical_processor_count(); } } _supports_cx8 = supports_cmpxchg8(); #ifdef _LP64 // OS should support SSE for x64 and hardware should support at least SSE2. if (!VM_Version::supports_sse2()) { vm_exit_during_initialization("Unknown x64 processor: SSE2 not supported"); } // in 64 bit the use of SSE2 is the minimum if (UseSSE < 2) UseSSE = 2; #endif #ifdef AMD64 // flush_icache_stub have to be generated first. // That is why Icache line size is hard coded in ICache class, // see icache_x86.hpp. It is also the reason why we can't use // clflush instruction in 32-bit VM since it could be running // on CPU which does not support it. // // The only thing we can do is to verify that flushed // ICache::line_size has correct value. guarantee(_cpuid_info.std_cpuid1_edx.bits.clflush != 0, "clflush is not supported"); // clflush_size is size in quadwords (8 bytes). guarantee(_cpuid_info.std_cpuid1_ebx.bits.clflush_size == 8, "such clflush size is not supported"); #endif // If the OS doesn't support SSE, we can't use this feature even if the HW does if (!os::supports_sse()) _cpuFeatures &= ~(CPU_SSE|CPU_SSE2|CPU_SSE3|CPU_SSSE3|CPU_SSE4A|CPU_SSE4_1|CPU_SSE4_2); if (UseSSE < 4) { _cpuFeatures &= ~CPU_SSE4_1; _cpuFeatures &= ~CPU_SSE4_2; } if (UseSSE < 3) { _cpuFeatures &= ~CPU_SSE3; _cpuFeatures &= ~CPU_SSSE3; _cpuFeatures &= ~CPU_SSE4A; } if (UseSSE < 2) _cpuFeatures &= ~CPU_SSE2; if (UseSSE < 1) _cpuFeatures &= ~CPU_SSE; if (UseAVX < 2) _cpuFeatures &= ~CPU_AVX2; if (UseAVX < 1) _cpuFeatures &= ~CPU_AVX; if (logical_processors_per_package() == 1) { // HT processor could be installed on a system which doesn't support HT. _cpuFeatures &= ~CPU_HT; } char buf[256]; jio_snprintf(buf, sizeof(buf), "(%u cores per cpu, %u threads per core) family %d model %d stepping %d%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", cores_per_cpu(), threads_per_core(), cpu_family(), _model, _stepping, (supports_cmov() ? ", cmov" : ""), (supports_cmpxchg8() ? ", cx8" : ""), (supports_fxsr() ? ", fxsr" : ""), (supports_mmx() ? ", mmx" : ""), (supports_sse() ? ", sse" : ""), (supports_sse2() ? ", sse2" : ""), (supports_sse3() ? ", sse3" : ""), (supports_ssse3()? ", ssse3": ""), (supports_sse4_1() ? ", sse4.1" : ""), (supports_sse4_2() ? ", sse4.2" : ""), (supports_popcnt() ? ", popcnt" : ""), (supports_avx() ? ", avx" : ""), (supports_avx2() ? ", avx2" : ""), (supports_mmx_ext() ? ", mmxext" : ""), (supports_3dnow_prefetch() ? ", 3dnowpref" : ""), (supports_lzcnt() ? ", lzcnt": ""), (supports_sse4a() ? ", sse4a": ""), (supports_ht() ? ", ht": ""), (supports_tsc() ? ", tsc": ""), (supports_tscinv_bit() ? ", tscinvbit": ""), (supports_tscinv() ? ", tscinv": "")); _features_str = strdup(buf); // UseSSE is set to the smaller of what hardware supports and what // the command line requires. I.e., you cannot set UseSSE to 2 on // older Pentiums which do not support it. if (UseSSE > 4) UseSSE=4; if (UseSSE < 0) UseSSE=0; if (!supports_sse4_1()) // Drop to 3 if no SSE4 support UseSSE = MIN2((intx)3,UseSSE); if (!supports_sse3()) // Drop to 2 if no SSE3 support UseSSE = MIN2((intx)2,UseSSE); if (!supports_sse2()) // Drop to 1 if no SSE2 support UseSSE = MIN2((intx)1,UseSSE); if (!supports_sse ()) // Drop to 0 if no SSE support UseSSE = 0; if (UseAVX > 2) UseAVX=2; if (UseAVX < 0) UseAVX=0; if (!supports_avx2()) // Drop to 1 if no AVX2 support UseAVX = MIN2((intx)1,UseAVX); if (!supports_avx ()) // Drop to 0 if no AVX support UseAVX = 0; // On new cpus instructions which update whole XMM register should be used // to prevent partial register stall due to dependencies on high half. // // UseXmmLoadAndClearUpper == true --> movsd(xmm, mem) // UseXmmLoadAndClearUpper == false --> movlpd(xmm, mem) // UseXmmRegToRegMoveAll == true --> movaps(xmm, xmm), movapd(xmm, xmm). // UseXmmRegToRegMoveAll == false --> movss(xmm, xmm), movsd(xmm, xmm). if( is_amd() ) { // AMD cpus specific settings if( supports_sse2() && FLAG_IS_DEFAULT(UseAddressNop) ) { // Use it on new AMD cpus starting from Opteron. UseAddressNop = true; } if( supports_sse2() && FLAG_IS_DEFAULT(UseNewLongLShift) ) { // Use it on new AMD cpus starting from Opteron. UseNewLongLShift = true; } if( FLAG_IS_DEFAULT(UseXmmLoadAndClearUpper) ) { if( supports_sse4a() ) { UseXmmLoadAndClearUpper = true; // use movsd only on '10h' Opteron } else { UseXmmLoadAndClearUpper = false; } } if( FLAG_IS_DEFAULT(UseXmmRegToRegMoveAll) ) { if( supports_sse4a() ) { UseXmmRegToRegMoveAll = true; // use movaps, movapd only on '10h' } else { UseXmmRegToRegMoveAll = false; } } if( FLAG_IS_DEFAULT(UseXmmI2F) ) { if( supports_sse4a() ) { UseXmmI2F = true; } else { UseXmmI2F = false; } } if( FLAG_IS_DEFAULT(UseXmmI2D) ) { if( supports_sse4a() ) { UseXmmI2D = true; } else { UseXmmI2D = false; } } if( FLAG_IS_DEFAULT(UseSSE42Intrinsics) ) { if( supports_sse4_2() && UseSSE >= 4 ) { UseSSE42Intrinsics = true; } } // Use count leading zeros count instruction if available. if (supports_lzcnt()) { if (FLAG_IS_DEFAULT(UseCountLeadingZerosInstruction)) { UseCountLeadingZerosInstruction = true; } } // some defaults for AMD family 15h if ( cpu_family() == 0x15 ) { // On family 15h processors default is no sw prefetch if (FLAG_IS_DEFAULT(AllocatePrefetchStyle)) { AllocatePrefetchStyle = 0; } // Also, if some other prefetch style is specified, default instruction type is PREFETCHW if (FLAG_IS_DEFAULT(AllocatePrefetchInstr)) { AllocatePrefetchInstr = 3; } // On family 15h processors use XMM and UnalignedLoadStores for Array Copy if( FLAG_IS_DEFAULT(UseXMMForArrayCopy) ) { UseXMMForArrayCopy = true; } if( FLAG_IS_DEFAULT(UseUnalignedLoadStores) && UseXMMForArrayCopy ) { UseUnalignedLoadStores = true; } } } if( is_intel() ) { // Intel cpus specific settings if( FLAG_IS_DEFAULT(UseStoreImmI16) ) { UseStoreImmI16 = false; // don't use it on Intel cpus } if( cpu_family() == 6 || cpu_family() == 15 ) { if( FLAG_IS_DEFAULT(UseAddressNop) ) { // Use it on all Intel cpus starting from PentiumPro UseAddressNop = true; } } if( FLAG_IS_DEFAULT(UseXmmLoadAndClearUpper) ) { UseXmmLoadAndClearUpper = true; // use movsd on all Intel cpus } if( FLAG_IS_DEFAULT(UseXmmRegToRegMoveAll) ) { if( supports_sse3() ) { UseXmmRegToRegMoveAll = true; // use movaps, movapd on new Intel cpus } else { UseXmmRegToRegMoveAll = false; } } if( cpu_family() == 6 && supports_sse3() ) { // New Intel cpus #ifdef COMPILER2 if( FLAG_IS_DEFAULT(MaxLoopPad) ) { // For new Intel cpus do the next optimization: // don't align the beginning of a loop if there are enough instructions // left (NumberOfLoopInstrToAlign defined in c2_globals.hpp) // in current fetch line (OptoLoopAlignment) or the padding // is big (> MaxLoopPad). // Set MaxLoopPad to 11 for new Intel cpus to reduce number of // generated NOP instructions. 11 is the largest size of one // address NOP instruction '0F 1F' (see Assembler::nop(i)). MaxLoopPad = 11; } #endif // COMPILER2 if( FLAG_IS_DEFAULT(UseXMMForArrayCopy) ) { UseXMMForArrayCopy = true; // use SSE2 movq on new Intel cpus } if( supports_sse4_2() && supports_ht() ) { // Newest Intel cpus if( FLAG_IS_DEFAULT(UseUnalignedLoadStores) && UseXMMForArrayCopy ) { UseUnalignedLoadStores = true; // use movdqu on newest Intel cpus } } if( supports_sse4_2() && UseSSE >= 4 ) { if( FLAG_IS_DEFAULT(UseSSE42Intrinsics)) { UseSSE42Intrinsics = true; } } } } // Use population count instruction if available. if (supports_popcnt()) { if (FLAG_IS_DEFAULT(UsePopCountInstruction)) { UsePopCountInstruction = true; } } else if (UsePopCountInstruction) { warning("POPCNT instruction is not available on this CPU"); FLAG_SET_DEFAULT(UsePopCountInstruction, false); } #ifdef COMPILER2 if (UseFPUForSpilling) { if (UseSSE < 2) { // Only supported with SSE2+ FLAG_SET_DEFAULT(UseFPUForSpilling, false); } } #endif assert(0 <= ReadPrefetchInstr && ReadPrefetchInstr <= 3, "invalid value"); assert(0 <= AllocatePrefetchInstr && AllocatePrefetchInstr <= 3, "invalid value"); // set valid Prefetch instruction if( ReadPrefetchInstr < 0 ) ReadPrefetchInstr = 0; if( ReadPrefetchInstr > 3 ) ReadPrefetchInstr = 3; if( ReadPrefetchInstr == 3 && !supports_3dnow_prefetch() ) ReadPrefetchInstr = 0; if( !supports_sse() && supports_3dnow_prefetch() ) ReadPrefetchInstr = 3; if( AllocatePrefetchInstr < 0 ) AllocatePrefetchInstr = 0; if( AllocatePrefetchInstr > 3 ) AllocatePrefetchInstr = 3; if( AllocatePrefetchInstr == 3 && !supports_3dnow_prefetch() ) AllocatePrefetchInstr=0; if( !supports_sse() && supports_3dnow_prefetch() ) AllocatePrefetchInstr = 3; // Allocation prefetch settings intx cache_line_size = prefetch_data_size(); if( cache_line_size > AllocatePrefetchStepSize ) AllocatePrefetchStepSize = cache_line_size; assert(AllocatePrefetchLines > 0, "invalid value"); if( AllocatePrefetchLines < 1 ) // set valid value in product VM AllocatePrefetchLines = 3; assert(AllocateInstancePrefetchLines > 0, "invalid value"); if( AllocateInstancePrefetchLines < 1 ) // set valid value in product VM AllocateInstancePrefetchLines = 1; AllocatePrefetchDistance = allocate_prefetch_distance(); AllocatePrefetchStyle = allocate_prefetch_style(); if( is_intel() && cpu_family() == 6 && supports_sse3() ) { if( AllocatePrefetchStyle == 2 ) { // watermark prefetching on Core #ifdef _LP64 AllocatePrefetchDistance = 384; #else AllocatePrefetchDistance = 320; #endif } if( supports_sse4_2() && supports_ht() ) { // Nehalem based cpus AllocatePrefetchDistance = 192; AllocatePrefetchLines = 4; #ifdef COMPILER2 if (AggressiveOpts && FLAG_IS_DEFAULT(UseFPUForSpilling)) { FLAG_SET_DEFAULT(UseFPUForSpilling, true); } #endif } } assert(AllocatePrefetchDistance % AllocatePrefetchStepSize == 0, "invalid value"); #ifdef _LP64 // Prefetch settings PrefetchCopyIntervalInBytes = prefetch_copy_interval_in_bytes(); PrefetchScanIntervalInBytes = prefetch_scan_interval_in_bytes(); PrefetchFieldsAhead = prefetch_fields_ahead(); #endif #ifndef PRODUCT if (PrintMiscellaneous && Verbose) { tty->print_cr("Logical CPUs per core: %u", logical_processors_per_package()); tty->print("UseSSE=%d",UseSSE); if (UseAVX > 0) { tty->print(" UseAVX=%d",UseAVX); } tty->cr(); tty->print("Allocation"); if (AllocatePrefetchStyle <= 0 || UseSSE == 0 && !supports_3dnow_prefetch()) { tty->print_cr(": no prefetching"); } else { tty->print(" prefetching: "); if (UseSSE == 0 && supports_3dnow_prefetch()) { tty->print("PREFETCHW"); } else if (UseSSE >= 1) { if (AllocatePrefetchInstr == 0) { tty->print("PREFETCHNTA"); } else if (AllocatePrefetchInstr == 1) { tty->print("PREFETCHT0"); } else if (AllocatePrefetchInstr == 2) { tty->print("PREFETCHT2"); } else if (AllocatePrefetchInstr == 3) { tty->print("PREFETCHW"); } } if (AllocatePrefetchLines > 1) { tty->print_cr(" at distance %d, %d lines of %d bytes", AllocatePrefetchDistance, AllocatePrefetchLines, AllocatePrefetchStepSize); } else { tty->print_cr(" at distance %d, one line of %d bytes", AllocatePrefetchDistance, AllocatePrefetchStepSize); } } if (PrefetchCopyIntervalInBytes > 0) { tty->print_cr("PrefetchCopyIntervalInBytes %d", PrefetchCopyIntervalInBytes); } if (PrefetchScanIntervalInBytes > 0) { tty->print_cr("PrefetchScanIntervalInBytes %d", PrefetchScanIntervalInBytes); } if (PrefetchFieldsAhead > 0) { tty->print_cr("PrefetchFieldsAhead %d", PrefetchFieldsAhead); } } #endif // !PRODUCT }
// Minimum sizes of the generations may be different than // the initial sizes. An inconsistency is permitted here // in the total size that can be specified explicitly by // command line specification of OldSize and NewSize and // also a command line specification of -Xms. Issue a warning // but allow the values to pass. void GenCollectorPolicy::initialize_size_info() { CollectorPolicy::initialize_size_info(); _initial_young_size = NewSize; _max_young_size = MaxNewSize; _initial_old_size = OldSize; // Determine maximum size of the young generation. if (FLAG_IS_DEFAULT(MaxNewSize)) { _max_young_size = scale_by_NewRatio_aligned(_max_heap_byte_size); // Bound the maximum size by NewSize below (since it historically // would have been NewSize and because the NewRatio calculation could // yield a size that is too small) and bound it by MaxNewSize above. // Ergonomics plays here by previously calculating the desired // NewSize and MaxNewSize. _max_young_size = MIN2(MAX2(_max_young_size, _initial_young_size), MaxNewSize); } // Given the maximum young size, determine the initial and // minimum young sizes. if (_max_heap_byte_size == _initial_heap_byte_size) { // The maximum and initial heap sizes are the same so the generation's // initial size must be the same as it maximum size. Use NewSize as the // size if set on command line. _max_young_size = FLAG_IS_CMDLINE(NewSize) ? NewSize : _max_young_size; _initial_young_size = _max_young_size; // Also update the minimum size if min == initial == max. if (_max_heap_byte_size == _min_heap_byte_size) { _min_young_size = _max_young_size; } } else { if (FLAG_IS_CMDLINE(NewSize)) { // If NewSize is set on the command line, we should use it as // the initial size, but make sure it is within the heap bounds. _initial_young_size = MIN2(_max_young_size, bound_minus_alignment(NewSize, _initial_heap_byte_size)); _min_young_size = bound_minus_alignment(_initial_young_size, _min_heap_byte_size); } else { // For the case where NewSize is not set on the command line, use // NewRatio to size the initial generation size. Use the current // NewSize as the floor, because if NewRatio is overly large, the resulting // size can be too small. _initial_young_size = MIN2(_max_young_size, MAX2(scale_by_NewRatio_aligned(_initial_heap_byte_size), NewSize)); } } log_trace(gc, heap)("1: Minimum young " SIZE_FORMAT " Initial young " SIZE_FORMAT " Maximum young " SIZE_FORMAT, _min_young_size, _initial_young_size, _max_young_size); // At this point the minimum, initial and maximum sizes // of the overall heap and of the young generation have been determined. // The maximum old size can be determined from the maximum young // and maximum heap size since no explicit flags exist // for setting the old generation maximum. _max_old_size = MAX2(_max_heap_byte_size - _max_young_size, _gen_alignment); // If no explicit command line flag has been set for the // old generation size, use what is left. if (!FLAG_IS_CMDLINE(OldSize)) { // The user has not specified any value but the ergonomics // may have chosen a value (which may or may not be consistent // with the overall heap size). In either case make // the minimum, maximum and initial sizes consistent // with the young sizes and the overall heap sizes. _min_old_size = _gen_alignment; _initial_old_size = MIN2(_max_old_size, MAX2(_initial_heap_byte_size - _initial_young_size, _min_old_size)); // _max_old_size has already been made consistent above. } else { // OldSize has been explicitly set on the command line. Use it // for the initial size but make sure the minimum allow a young // generation to fit as well. // If the user has explicitly set an OldSize that is inconsistent // with other command line flags, issue a warning. // The generation minimums and the overall heap minimum should // be within one generation alignment. if (_initial_old_size > _max_old_size) { log_warning(gc, ergo)("Inconsistency between maximum heap size and maximum " "generation sizes: using maximum heap = " SIZE_FORMAT ", -XX:OldSize flag is being ignored", _max_heap_byte_size); _initial_old_size = _max_old_size; } _min_old_size = MIN2(_initial_old_size, _min_heap_byte_size - _min_young_size); } // The initial generation sizes should match the initial heap size, // if not issue a warning and resize the generations. This behavior // differs from JDK8 where the generation sizes have higher priority // than the initial heap size. if ((_initial_old_size + _initial_young_size) != _initial_heap_byte_size) { log_warning(gc, ergo)("Inconsistency between generation sizes and heap size, resizing " "the generations to fit the heap."); size_t desired_young_size = _initial_heap_byte_size - _initial_old_size; if (_initial_heap_byte_size < _initial_old_size) { // Old want all memory, use minimum for young and rest for old _initial_young_size = _min_young_size; _initial_old_size = _initial_heap_byte_size - _min_young_size; } else if (desired_young_size > _max_young_size) { // Need to increase both young and old generation _initial_young_size = _max_young_size; _initial_old_size = _initial_heap_byte_size - _max_young_size; } else if (desired_young_size < _min_young_size) { // Need to decrease both young and old generation _initial_young_size = _min_young_size; _initial_old_size = _initial_heap_byte_size - _min_young_size; } else { // The young generation boundaries allow us to only update the // young generation. _initial_young_size = desired_young_size; } log_trace(gc, heap)("2: Minimum young " SIZE_FORMAT " Initial young " SIZE_FORMAT " Maximum young " SIZE_FORMAT, _min_young_size, _initial_young_size, _max_young_size); } // Write back to flags if necessary. if (NewSize != _initial_young_size) { FLAG_SET_ERGO(size_t, NewSize, _initial_young_size); } if (MaxNewSize != _max_young_size) { FLAG_SET_ERGO(size_t, MaxNewSize, _max_young_size); } if (OldSize != _initial_old_size) { FLAG_SET_ERGO(size_t, OldSize, _initial_old_size); } log_trace(gc, heap)("Minimum old " SIZE_FORMAT " Initial old " SIZE_FORMAT " Maximum old " SIZE_FORMAT, _min_old_size, _initial_old_size, _max_old_size); DEBUG_ONLY(GenCollectorPolicy::assert_size_info();) }
void GenCollectorPolicy::initialize_flags() { CollectorPolicy::initialize_flags(); assert(_gen_alignment != 0, "Generation alignment not set up properly"); assert(_heap_alignment >= _gen_alignment, "heap_alignment: " SIZE_FORMAT " less than gen_alignment: " SIZE_FORMAT, _heap_alignment, _gen_alignment); assert(_gen_alignment % _space_alignment == 0, "gen_alignment: " SIZE_FORMAT " not aligned by space_alignment: " SIZE_FORMAT, _gen_alignment, _space_alignment); assert(_heap_alignment % _gen_alignment == 0, "heap_alignment: " SIZE_FORMAT " not aligned by gen_alignment: " SIZE_FORMAT, _heap_alignment, _gen_alignment); // All generational heaps have a young gen; handle those flags here // Make sure the heap is large enough for two generations size_t smallest_new_size = young_gen_size_lower_bound(); size_t smallest_heap_size = align_size_up(smallest_new_size + old_gen_size_lower_bound(), _heap_alignment); if (MaxHeapSize < smallest_heap_size) { FLAG_SET_ERGO(size_t, MaxHeapSize, smallest_heap_size); _max_heap_byte_size = MaxHeapSize; } // If needed, synchronize _min_heap_byte size and _initial_heap_byte_size if (_min_heap_byte_size < smallest_heap_size) { _min_heap_byte_size = smallest_heap_size; if (InitialHeapSize < _min_heap_byte_size) { FLAG_SET_ERGO(size_t, InitialHeapSize, smallest_heap_size); _initial_heap_byte_size = smallest_heap_size; } } // Make sure NewSize allows an old generation to fit even if set on the command line if (FLAG_IS_CMDLINE(NewSize) && NewSize >= _initial_heap_byte_size) { log_warning(gc, ergo)("NewSize was set larger than initial heap size, will use initial heap size."); FLAG_SET_ERGO(size_t, NewSize, bound_minus_alignment(NewSize, _initial_heap_byte_size)); } // Now take the actual NewSize into account. We will silently increase NewSize // if the user specified a smaller or unaligned value. size_t bounded_new_size = bound_minus_alignment(NewSize, MaxHeapSize); bounded_new_size = MAX2(smallest_new_size, (size_t)align_size_down(bounded_new_size, _gen_alignment)); if (bounded_new_size != NewSize) { FLAG_SET_ERGO(size_t, NewSize, bounded_new_size); } _min_young_size = smallest_new_size; _initial_young_size = NewSize; if (!FLAG_IS_DEFAULT(MaxNewSize)) { if (MaxNewSize >= MaxHeapSize) { // Make sure there is room for an old generation size_t smaller_max_new_size = MaxHeapSize - _gen_alignment; if (FLAG_IS_CMDLINE(MaxNewSize)) { log_warning(gc, ergo)("MaxNewSize (" SIZE_FORMAT "k) is equal to or greater than the entire " "heap (" SIZE_FORMAT "k). A new max generation size of " SIZE_FORMAT "k will be used.", MaxNewSize/K, MaxHeapSize/K, smaller_max_new_size/K); } FLAG_SET_ERGO(size_t, MaxNewSize, smaller_max_new_size); if (NewSize > MaxNewSize) { FLAG_SET_ERGO(size_t, NewSize, MaxNewSize); _initial_young_size = NewSize; } } else if (MaxNewSize < _initial_young_size) { FLAG_SET_ERGO(size_t, MaxNewSize, _initial_young_size); } else if (!is_size_aligned(MaxNewSize, _gen_alignment)) { FLAG_SET_ERGO(size_t, MaxNewSize, align_size_down(MaxNewSize, _gen_alignment)); } _max_young_size = MaxNewSize; } if (NewSize > MaxNewSize) { // At this point this should only happen if the user specifies a large NewSize and/or // a small (but not too small) MaxNewSize. if (FLAG_IS_CMDLINE(MaxNewSize)) { log_warning(gc, ergo)("NewSize (" SIZE_FORMAT "k) is greater than the MaxNewSize (" SIZE_FORMAT "k). " "A new max generation size of " SIZE_FORMAT "k will be used.", NewSize/K, MaxNewSize/K, NewSize/K); } FLAG_SET_ERGO(size_t, MaxNewSize, NewSize); _max_young_size = MaxNewSize; } if (SurvivorRatio < 1 || NewRatio < 1) { vm_exit_during_initialization("Invalid young gen ratio specified"); } if (OldSize < old_gen_size_lower_bound()) { FLAG_SET_ERGO(size_t, OldSize, old_gen_size_lower_bound()); } if (!is_size_aligned(OldSize, _gen_alignment)) { FLAG_SET_ERGO(size_t, OldSize, align_size_down(OldSize, _gen_alignment)); } if (FLAG_IS_CMDLINE(OldSize) && FLAG_IS_DEFAULT(MaxHeapSize)) { // NewRatio will be used later to set the young generation size so we use // it to calculate how big the heap should be based on the requested OldSize // and NewRatio. assert(NewRatio > 0, "NewRatio should have been set up earlier"); size_t calculated_heapsize = (OldSize / NewRatio) * (NewRatio + 1); calculated_heapsize = align_size_up(calculated_heapsize, _heap_alignment); FLAG_SET_ERGO(size_t, MaxHeapSize, calculated_heapsize); _max_heap_byte_size = MaxHeapSize; FLAG_SET_ERGO(size_t, InitialHeapSize, calculated_heapsize); _initial_heap_byte_size = InitialHeapSize; } // Adjust NewSize and OldSize or MaxHeapSize to match each other if (NewSize + OldSize > MaxHeapSize) { if (FLAG_IS_CMDLINE(MaxHeapSize)) { // Somebody has set a maximum heap size with the intention that we should not // exceed it. Adjust New/OldSize as necessary. size_t calculated_size = NewSize + OldSize; double shrink_factor = (double) MaxHeapSize / calculated_size; size_t smaller_new_size = align_size_down((size_t)(NewSize * shrink_factor), _gen_alignment); FLAG_SET_ERGO(size_t, NewSize, MAX2(young_gen_size_lower_bound(), smaller_new_size)); _initial_young_size = NewSize; // OldSize is already aligned because above we aligned MaxHeapSize to // _heap_alignment, and we just made sure that NewSize is aligned to // _gen_alignment. In initialize_flags() we verified that _heap_alignment // is a multiple of _gen_alignment. FLAG_SET_ERGO(size_t, OldSize, MaxHeapSize - NewSize); } else { FLAG_SET_ERGO(size_t, MaxHeapSize, align_size_up(NewSize + OldSize, _heap_alignment)); _max_heap_byte_size = MaxHeapSize; } } // Update NewSize, if possible, to avoid sizing the young gen too small when only // OldSize is set on the command line. if (FLAG_IS_CMDLINE(OldSize) && !FLAG_IS_CMDLINE(NewSize)) { if (OldSize < _initial_heap_byte_size) { size_t new_size = _initial_heap_byte_size - OldSize; // Need to compare against the flag value for max since _max_young_size // might not have been set yet. if (new_size >= _min_young_size && new_size <= MaxNewSize) { FLAG_SET_ERGO(size_t, NewSize, new_size); _initial_young_size = NewSize; } } } always_do_update_barrier = UseConcMarkSweepGC; DEBUG_ONLY(GenCollectorPolicy::assert_flags();) }