< prev index next >

test/lib/sun/hotspot/WhiteBox.java

Print this page
rev 1371 : 8074980: add WhiteBox API to get a flag value for a method
Reviewed-by:


  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 package sun.hotspot;
  26 
  27 import java.lang.reflect.Executable;
  28 import java.util.Arrays;
  29 import java.util.List;

  30 import java.util.function.Function;
  31 import java.util.stream.Stream;
  32 import java.security.BasicPermission;
  33 
  34 import sun.hotspot.parser.DiagnosticCommand;
  35 
  36 public class WhiteBox {
  37 
  38   @SuppressWarnings("serial")
  39   public static class WhiteBoxPermission extends BasicPermission {
  40     public WhiteBoxPermission(String s) {
  41       super(s);
  42     }
  43   }
  44 
  45   private WhiteBox() {}
  46   private static final WhiteBox instance = new WhiteBox();
  47   private static native void registerNatives();
  48 
  49   /**


 232   public native Double  getDoubleVMFlag(String name);
 233   private final List<Function<String,Object>> flagsGetters = Arrays.asList(
 234     this::getBooleanVMFlag, this::getIntxVMFlag, this::getUintxVMFlag,
 235     this::getUint64VMFlag, this::getSizeTVMFlag, this::getStringVMFlag,
 236     this::getDoubleVMFlag);
 237 
 238   public Object getVMFlag(String name) {
 239     return flagsGetters.stream()
 240                        .map(f -> f.apply(name))
 241                        .filter(x -> x != null)
 242                        .findAny()
 243                        .orElse(null);
 244   }
 245   public native int getOffsetForName0(String name);
 246   public int getOffsetForName(String name) throws Exception {
 247     int offset = getOffsetForName0(name);
 248     if (offset == -1) {
 249       throw new RuntimeException(name + " not found");
 250     }
 251     return offset;

















 252   }
 253 
 254   // Safepoint Checking
 255   public native void assertMatchingSafepointCalls(boolean mutexSafepointValue, boolean attemptedNoSafepointValue);
 256 }


  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 package sun.hotspot;
  26 
  27 import java.lang.reflect.Executable;
  28 import java.util.Arrays;
  29 import java.util.List;
  30 import java.util.function.BiFunction;
  31 import java.util.function.Function;
  32 import java.util.stream.Stream;
  33 import java.security.BasicPermission;
  34 
  35 import sun.hotspot.parser.DiagnosticCommand;
  36 
  37 public class WhiteBox {
  38 
  39   @SuppressWarnings("serial")
  40   public static class WhiteBoxPermission extends BasicPermission {
  41     public WhiteBoxPermission(String s) {
  42       super(s);
  43     }
  44   }
  45 
  46   private WhiteBox() {}
  47   private static final WhiteBox instance = new WhiteBox();
  48   private static native void registerNatives();
  49 
  50   /**


 233   public native Double  getDoubleVMFlag(String name);
 234   private final List<Function<String,Object>> flagsGetters = Arrays.asList(
 235     this::getBooleanVMFlag, this::getIntxVMFlag, this::getUintxVMFlag,
 236     this::getUint64VMFlag, this::getSizeTVMFlag, this::getStringVMFlag,
 237     this::getDoubleVMFlag);
 238 
 239   public Object getVMFlag(String name) {
 240     return flagsGetters.stream()
 241                        .map(f -> f.apply(name))
 242                        .filter(x -> x != null)
 243                        .findAny()
 244                        .orElse(null);
 245   }
 246   public native int getOffsetForName0(String name);
 247   public int getOffsetForName(String name) throws Exception {
 248     int offset = getOffsetForName0(name);
 249     if (offset == -1) {
 250       throw new RuntimeException(name + " not found");
 251     }
 252     return offset;
 253   }
 254   public native Boolean getMethodBooleanOption(Executable method, String name);
 255   public native Long    getMethodIntxOption(Executable method, String name);
 256   public native Long    getMethodUintxOption(Executable method, String name);
 257   public native Double  getMethodDoubleOption(Executable method, String name);
 258   public native String  getMethodStringOption(Executable method, String name);
 259   private final List<BiFunction<Executable,String,Object>> methodOptionGetters
 260       = Arrays.asList(this::getMethodBooleanOption, this::getMethodIntxOption,
 261           this::getMethodUintxOption, this::getMethodDoubleOption,
 262           this::getMethodStringOption);
 263 
 264   public Object getMethodOption(Executable method, String name) {
 265     return methodOptionGetters.stream()
 266                               .map(f -> f.apply(method, name))
 267                               .filter(x -> x != null)
 268                               .findAny()
 269                               .orElse(null);
 270   }
 271 
 272   // Safepoint Checking
 273   public native void assertMatchingSafepointCalls(boolean mutexSafepointValue, boolean attemptedNoSafepointValue);
 274 }
< prev index next >