vm_version_sparc.cpp revision 1499:e9ff18c4ace7
11541Srgrimes/*
21541Srgrimes * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
31541Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41541Srgrimes *
51541Srgrimes * This code is free software; you can redistribute it and/or modify it
61541Srgrimes * under the terms of the GNU General Public License version 2 only, as
71541Srgrimes * published by the Free Software Foundation.
81541Srgrimes *
91541Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT
101541Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
111541Srgrimes * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
121541Srgrimes * version 2 for more details (a copy is included in the LICENSE file that
131541Srgrimes * accompanied this code).
141541Srgrimes *
151541Srgrimes * You should have received a copy of the GNU General Public License version
161541Srgrimes * 2 along with this work; if not, write to the Free Software Foundation,
171541Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
181541Srgrimes *
191541Srgrimes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
201541Srgrimes * or visit www.oracle.com if you need additional information or have any
211541Srgrimes * questions.
221541Srgrimes *
231541Srgrimes */
241541Srgrimes
251541Srgrimes# include "incls/_precompiled.incl"
261541Srgrimes# include "incls/_vm_version_sparc.cpp.incl"
271541Srgrimes
281541Srgrimesint VM_Version::_features = VM_Version::unknown_m;
291541Srgrimesconst char* VM_Version::_features_str = "";
301541Srgrimes
311541Srgrimesbool VM_Version::is_niagara1_plus() {
321541Srgrimes  // This is a placeholder until the real test is determined.
331541Srgrimes  return is_niagara1() &&
3444510Swollman    (os::processor_count() > maximum_niagara1_processor_count());
351541Srgrimes}
361541Srgrimes
37116182Sobrienvoid VM_Version::initialize() {
38116182Sobrien  _features = determine_features();
39116182Sobrien  PrefetchCopyIntervalInBytes = prefetch_copy_interval_in_bytes();
40247777Sdavide  PrefetchScanIntervalInBytes = prefetch_scan_interval_in_bytes();
41187664Srwatson  PrefetchFieldsAhead         = prefetch_fields_ahead();
42247777Sdavide
43247777Sdavide  // Allocation prefetch settings
44247777Sdavide  intx cache_line_size = L1_data_cache_line_size();
45187664Srwatson  if( cache_line_size > AllocatePrefetchStepSize )
461541Srgrimes    AllocatePrefetchStepSize = cache_line_size;
471541Srgrimes  if( FLAG_IS_DEFAULT(AllocatePrefetchLines) )
48177859Sjeff    AllocatePrefetchLines = 3; // Optimistic value
4933392Sphk  assert( AllocatePrefetchLines > 0, "invalid value");
50248031Sandre  if( AllocatePrefetchLines < 1 ) // set valid value in product VM
51177859Sjeff    AllocatePrefetchLines = 1; // Conservative value
521541Srgrimes
53133229Srwatson  AllocatePrefetchDistance = allocate_prefetch_distance();
5474914Sjhb  AllocatePrefetchStyle    = allocate_prefetch_style();
55177859Sjeff
5668840Sjhb  assert(AllocatePrefetchDistance % AllocatePrefetchStepSize == 0, "invalid value");
57150188Sjhb
58187664Srwatson  UseSSE = 0; // Only on x86 and x64
59171053Sattilio
60115810Sphk  _supports_cx8               = has_v9();
61177859Sjeff
621541Srgrimes  if (is_niagara1()) {
63220456Sattilio    // Indirect branch is the same cost as direct
64220456Sattilio    if (FLAG_IS_DEFAULT(UseInlineCaches)) {
65220456Sattilio      FLAG_SET_DEFAULT(UseInlineCaches, false);
66220456Sattilio    }
67247777Sdavide#ifdef _LP64
68247777Sdavide    // 32-bit oops don't make sense for the 64-bit VM on sparc
69247777Sdavide    // since the 32-bit VM has the same registers and smaller objects.
70247777Sdavide    Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes);
71187664Srwatson#endif // _LP64
72260817Savg#ifdef COMPILER2
73187664Srwatson    // Indirect branch is the same cost as direct
74260817Savg    if (FLAG_IS_DEFAULT(UseJumpTables)) {
75187664Srwatson      FLAG_SET_DEFAULT(UseJumpTables, true);
76187664Srwatson    }
77247777Sdavide    // Single-issue, so entry and loop tops are
78115810Sphk    // aligned on a single instruction boundary
79115810Sphk    if (FLAG_IS_DEFAULT(InteriorEntryAlignment)) {
80115810Sphk      FLAG_SET_DEFAULT(InteriorEntryAlignment, 4);
81115810Sphk    }
82115810Sphk    if (is_niagara1_plus()) {
83115810Sphk      if (AllocatePrefetchStyle > 0 && FLAG_IS_DEFAULT(AllocatePrefetchStyle)) {
84173760Sattilio        // Use BIS instruction for allocation prefetch.
85173760Sattilio        FLAG_SET_DEFAULT(AllocatePrefetchStyle, 3);
86173760Sattilio        if (FLAG_IS_DEFAULT(AllocatePrefetchDistance)) {
87115810Sphk          // Use smaller prefetch distance on N2 with BIS
88115810Sphk          FLAG_SET_DEFAULT(AllocatePrefetchDistance, 64);
89115810Sphk        }
90247777Sdavide      }
91247777Sdavide      if (AllocatePrefetchStyle != 3 && FLAG_IS_DEFAULT(AllocatePrefetchDistance)) {
92247777Sdavide        // Use different prefetch distance without BIS
93247777Sdavide        FLAG_SET_DEFAULT(AllocatePrefetchDistance, 256);
94247777Sdavide      }
95247777Sdavide    }
96247777Sdavide#endif
97247777Sdavide    if (FLAG_IS_DEFAULT(OptoLoopAlignment)) {
98247777Sdavide      FLAG_SET_DEFAULT(OptoLoopAlignment, 4);
99247777Sdavide    }
100247777Sdavide    // When using CMS, we cannot use memset() in BOT updates because
101247777Sdavide    // the sun4v/CMT version in libc_psr uses BIS which exposes
102247777Sdavide    // "phantom zeros" to concurrent readers. See 6948537.
103248031Sandre    if (FLAG_IS_DEFAULT(UseMemSetInBOT) && UseConcMarkSweepGC) {
104248031Sandre      FLAG_SET_DEFAULT(UseMemSetInBOT, false);
105248031Sandre    }
106248031Sandre  }
107248031Sandre
10833392Sphk  // Use hardware population count instruction if available.
10933392Sphk  if (has_hardware_popc()) {
11033392Sphk    if (FLAG_IS_DEFAULT(UsePopCountInstruction)) {
11133392Sphk      FLAG_SET_DEFAULT(UsePopCountInstruction, true);
112247715Sdavide    }
1132112Swollman  }
114200510Sluigi
115247777Sdavide  char buf[512];
116247777Sdavide  jio_snprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s%s%s%s%s%s",
117247777Sdavide               (has_v8() ? ", has_v8" : ""),
118247777Sdavide               (has_v9() ? ", has_v9" : ""),
119247777Sdavide               (has_hardware_popc() ? ", popc" : ""),
120247777Sdavide               (has_vis1() ? ", has_vis1" : ""),
121220456Sattilio               (has_vis2() ? ", has_vis2" : ""),
122220456Sattilio               (is_ultra3() ? ", is_ultra3" : ""),
123220456Sattilio               (is_sun4v() ? ", is_sun4v" : ""),
124247777Sdavide               (is_niagara1() ? ", is_niagara1" : ""),
125247777Sdavide               (is_niagara1_plus() ? ", is_niagara1_plus" : ""),
126247777Sdavide               (!has_hardware_mul32() ? ", no-mul32" : ""),
127220456Sattilio               (!has_hardware_div32() ? ", no-div32" : ""),
128247777Sdavide               (!has_hardware_fsmuld() ? ", no-fsmuld" : ""));
129247777Sdavide
130247777Sdavide  // buf is started with ", " or is empty
131247777Sdavide  _features_str = strdup(strlen(buf) > 2 ? buf + 2 : buf);
132248699Sdavide
133220456Sattilio#ifndef PRODUCT
134247813Sdavide  if (PrintMiscellaneous && Verbose) {
135247813Sdavide    tty->print("Allocation: ");
136220456Sattilio    if (AllocatePrefetchStyle <= 0) {
137247467Sdavide      tty->print_cr("no prefetching");
138220456Sattilio    } else {
139200510Sluigi      if (AllocatePrefetchLines > 1) {
140200510Sluigi        tty->print_cr("PREFETCH %d, %d lines of size %d bytes", AllocatePrefetchDistance, AllocatePrefetchLines, AllocatePrefetchStepSize);
141200510Sluigi      } else {
142177859Sjeff        tty->print_cr("PREFETCH %d, one line", AllocatePrefetchDistance);
143242402Sattilio      }
144247777Sdavide    }
145177859Sjeff    if (PrefetchCopyIntervalInBytes > 0) {
146247777Sdavide      tty->print_cr("PrefetchCopyIntervalInBytes %d", PrefetchCopyIntervalInBytes);
147247777Sdavide    }
148247777Sdavide    if (PrefetchScanIntervalInBytes > 0) {
149247777Sdavide      tty->print_cr("PrefetchScanIntervalInBytes %d", PrefetchScanIntervalInBytes);
150247777Sdavide    }
151177859Sjeff    if (PrefetchFieldsAhead > 0) {
152247777Sdavide      tty->print_cr("PrefetchFieldsAhead %d", PrefetchFieldsAhead);
153278694Ssbruno    }
154177859Sjeff  }
155128024Scperciva#endif // PRODUCT
156247777Sdavide}
157247777Sdavide
158247777Sdavidevoid VM_Version::print_features() {
159247777Sdavide  tty->print_cr("Version:%s", cpu_features());
160247777Sdavide}
161247777Sdavide
162247777Sdavideint VM_Version::determine_features() {
163247777Sdavide  if (UseV8InstrsOnly) {
164247777Sdavide    NOT_PRODUCT(if (PrintMiscellaneous && Verbose) tty->print_cr("Version is Forced-V8");)
165177859Sjeff    return generic_v8_m;
166247777Sdavide  }
167247777Sdavide
168247777Sdavide  int features = platform_features(unknown_m); // platform_features() is os_arch specific
169247777Sdavide
170248699Sdavide  if (features == unknown_m) {
171247777Sdavide    features = generic_v9_m;
172247777Sdavide    warning("Cannot recognize SPARC version. Default to V9");
173247777Sdavide  }
174247777Sdavide
175248699Sdavide  if (UseNiagaraInstrs) {
176220456Sattilio    if (is_niagara1(features)) {
177177859Sjeff      // Happy to accomodate...
178220456Sattilio    } else {
179177859Sjeff      NOT_PRODUCT(if (PrintMiscellaneous && Verbose) tty->print_cr("Version is Forced-Niagara");)
180177859Sjeff      features = niagara1_m;
181177859Sjeff    }
182177859Sjeff  } else {
183177859Sjeff    if (is_niagara1(features) && !FLAG_IS_DEFAULT(UseNiagaraInstrs)) {
184177859Sjeff      NOT_PRODUCT(if (PrintMiscellaneous && Verbose) tty->print_cr("Version is Forced-Not-Niagara");)
185177859Sjeff      features &= ~niagara1_unique_m;
186177859Sjeff    } else {
187177859Sjeff      // Happy to accomodate...
188220456Sattilio    }
189177859Sjeff  }
190177859Sjeff
191177859Sjeff  return features;
192278694Ssbruno}
193247777Sdavide
194247777Sdavidestatic int saved_features = 0;
195247777Sdavide
196247777Sdavidevoid VM_Version::allow_all() {
197247777Sdavide  saved_features = _features;
198247777Sdavide  _features      = all_features_m;
199227293Sed}
200177859Sjeff
201139831Scpercivavoid VM_Version::revert() {
202177859Sjeff  _features = saved_features;
203247777Sdavide}
204247777Sdavide
205177859Sjeffunsigned int VM_Version::calc_parallel_worker_threads() {
206127969Scperciva  unsigned int result;
207247777Sdavide  if (is_niagara1_plus()) {
208141428Siedowse    result = nof_parallel_worker_threads(5, 16, 8);
209141428Siedowse  } else {
210173760Sattilio    result = nof_parallel_worker_threads(5, 8, 8);
211155957Sjhb  }
212247777Sdavide  return result;
213177859Sjeff}
214155957Sjhb