test/lib/sun/hotspot/WhiteBox.java
author iignatyev
Thu, 12 Mar 2015 19:11:17 +0300
changeset 29440 87390f81c75d
parent 28351 bbdca807711d
child 29563 2b603c351758
child 29665 b4ef48f9374f
permissions -rw-r--r--
8074980: add WhiteBox API to get a flag value for a method Reviewed-by: kvn, fzhinkin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28154
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
     1
/*
29440
87390f81c75d 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents: 28351
diff changeset
     2
 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
28154
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
     4
 *
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
     7
 * published by the Free Software Foundation.
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
     8
 *
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    13
 * accompanied this code).
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    14
 *
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    18
 *
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    21
 * questions.
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    22
 *
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    23
 */
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    24
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    25
package sun.hotspot;
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    26
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    27
import java.lang.reflect.Executable;
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    28
import java.util.Arrays;
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    29
import java.util.List;
29440
87390f81c75d 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents: 28351
diff changeset
    30
import java.util.function.BiFunction;
28154
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    31
import java.util.function.Function;
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    32
import java.util.stream.Stream;
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    33
import java.security.BasicPermission;
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    34
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    35
import sun.hotspot.parser.DiagnosticCommand;
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    36
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    37
public class WhiteBox {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    38
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    39
  @SuppressWarnings("serial")
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    40
  public static class WhiteBoxPermission extends BasicPermission {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    41
    public WhiteBoxPermission(String s) {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    42
      super(s);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    43
    }
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    44
  }
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    45
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    46
  private WhiteBox() {}
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    47
  private static final WhiteBox instance = new WhiteBox();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    48
  private static native void registerNatives();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    49
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    50
  /**
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    51
   * Returns the singleton WhiteBox instance.
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    52
   *
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    53
   * The returned WhiteBox object should be carefully guarded
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    54
   * by the caller, since it can be used to read and write data
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    55
   * at arbitrary memory addresses. It must never be passed to
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    56
   * untrusted code.
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    57
   */
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    58
  public synchronized static WhiteBox getWhiteBox() {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    59
    SecurityManager sm = System.getSecurityManager();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    60
    if (sm != null) {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    61
      sm.checkPermission(new WhiteBoxPermission("getInstance"));
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    62
    }
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    63
    return instance;
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    64
  }
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    65
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    66
  static {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    67
    registerNatives();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    68
  }
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    69
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    70
  // Get the maximum heap size supporting COOPs
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    71
  public native long getCompressedOopsMaxHeapSize();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    72
  // Arguments
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    73
  public native void printHeapSizes();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    74
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    75
  // Memory
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    76
  public native long getObjectAddress(Object o);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    77
  public native int  getHeapOopSize();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    78
  public native int  getVMPageSize();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    79
  public native boolean isObjectInOldGen(Object o);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    80
  public native long getObjectSize(Object o);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    81
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    82
  // Runtime
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    83
  // Make sure class name is in the correct format
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    84
  public boolean isClassAlive(String name) {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    85
    return isClassAlive0(name.replace('.', '/'));
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    86
  }
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    87
  private native boolean isClassAlive0(String name);
28351
bbdca807711d 8068272: Extend WhiteBox API with methods that check monitor state and force safepoint
fzhinkin
parents: 28159
diff changeset
    88
  public native boolean isMonitorInflated(Object obj);
bbdca807711d 8068272: Extend WhiteBox API with methods that check monitor state and force safepoint
fzhinkin
parents: 28159
diff changeset
    89
  public native void forceSafepoint();
28154
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    90
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    91
  // JVMTI
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    92
  public native void addToBootstrapClassLoaderSearch(String segment);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    93
  public native void addToSystemClassLoaderSearch(String segment);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    94
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    95
  // G1
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    96
  public native boolean g1InConcurrentMark();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    97
  public native boolean g1IsHumongous(Object o);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    98
  public native long    g1NumFreeRegions();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    99
  public native int     g1RegionSize();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   100
  public native Object[]    parseCommandLine(String commandline, char delim, DiagnosticCommand[] args);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   101
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   102
  // NMT
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   103
  public native long NMTMalloc(long size);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   104
  public native void NMTFree(long mem);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   105
  public native long NMTReserveMemory(long size);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   106
  public native void NMTCommitMemory(long addr, long size);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   107
  public native void NMTUncommitMemory(long addr, long size);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   108
  public native void NMTReleaseMemory(long addr, long size);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   109
  public native long NMTMallocWithPseudoStack(long size, int index);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   110
  public native boolean NMTIsDetailSupported();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   111
  public native boolean NMTChangeTrackingLevel();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   112
  public native int NMTGetHashSize();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   113
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   114
  // Compiler
28157
1305bf148a19 8028595: WhiteBox API for stress testing of TieredCompilation
iignatyev
parents: 28154
diff changeset
   115
  public native int     deoptimizeFrames(boolean makeNotEntrant);
28154
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   116
  public native void    deoptimizeAll();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   117
  public        boolean isMethodCompiled(Executable method) {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   118
    return isMethodCompiled(method, false /*not osr*/);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   119
  }
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   120
  public native boolean isMethodCompiled(Executable method, boolean isOsr);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   121
  public        boolean isMethodCompilable(Executable method) {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   122
    return isMethodCompilable(method, -1 /*any*/);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   123
  }
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   124
  public        boolean isMethodCompilable(Executable method, int compLevel) {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   125
    return isMethodCompilable(method, compLevel, false /*not osr*/);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   126
  }
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   127
  public native boolean isMethodCompilable(Executable method, int compLevel, boolean isOsr);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   128
  public native boolean isMethodQueuedForCompilation(Executable method);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   129
  public        int     deoptimizeMethod(Executable method) {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   130
    return deoptimizeMethod(method, false /*not osr*/);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   131
  }
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   132
  public native int     deoptimizeMethod(Executable method, boolean isOsr);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   133
  public        void    makeMethodNotCompilable(Executable method) {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   134
    makeMethodNotCompilable(method, -1 /*any*/);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   135
  }
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   136
  public        void    makeMethodNotCompilable(Executable method, int compLevel) {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   137
    makeMethodNotCompilable(method, compLevel, false /*not osr*/);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   138
  }
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   139
  public native void    makeMethodNotCompilable(Executable method, int compLevel, boolean isOsr);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   140
  public        int     getMethodCompilationLevel(Executable method) {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   141
    return getMethodCompilationLevel(method, false /*not ost*/);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   142
  }
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   143
  public native int     getMethodCompilationLevel(Executable method, boolean isOsr);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   144
  public native boolean testSetDontInlineMethod(Executable method, boolean value);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   145
  public        int     getCompileQueuesSize() {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   146
    return getCompileQueueSize(-1 /*any*/);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   147
  }
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   148
  public native int     getCompileQueueSize(int compLevel);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   149
  public native boolean testSetForceInlineMethod(Executable method, boolean value);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   150
  public        boolean enqueueMethodForCompilation(Executable method, int compLevel) {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   151
    return enqueueMethodForCompilation(method, compLevel, -1 /*InvocationEntryBci*/);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   152
  }
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   153
  public native boolean enqueueMethodForCompilation(Executable method, int compLevel, int entry_bci);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   154
  public native void    clearMethodState(Executable method);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   155
  public native void    lockCompilation();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   156
  public native void    unlockCompilation();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   157
  public native int     getMethodEntryBci(Executable method);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   158
  public native Object[] getNMethod(Executable method, boolean isOsr);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   159
  public native long    allocateCodeBlob(int size, int type);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   160
  public        long    allocateCodeBlob(long size, int type) {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   161
      int intSize = (int) size;
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   162
      if ((long) intSize != size || size < 0) {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   163
          throw new IllegalArgumentException(
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   164
                "size argument has illegal value " + size);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   165
      }
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   166
      return allocateCodeBlob( intSize, type);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   167
  }
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   168
  public native void    freeCodeBlob(long addr);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   169
  public        void    forceNMethodSweep() {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   170
    try {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   171
        forceNMethodSweep0().join();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   172
    } catch (InterruptedException e) {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   173
        Thread.currentThread().interrupt();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   174
    }
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   175
  }
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   176
  public native Thread  forceNMethodSweep0();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   177
  public native Object[] getCodeHeapEntries(int type);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   178
  public native int     getCompilationActivityMode();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   179
  public native Object[] getCodeBlob(long addr);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   180
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   181
  // Intered strings
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   182
  public native boolean isInStringTable(String str);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   183
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   184
  // Memory
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   185
  public native void readReservedMemory();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   186
  public native long allocateMetaspace(ClassLoader classLoader, long size);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   187
  public native void freeMetaspace(ClassLoader classLoader, long addr, long size);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   188
  public native long incMetaspaceCapacityUntilGC(long increment);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   189
  public native long metaspaceCapacityUntilGC();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   190
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   191
  // Force Young GC
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   192
  public native void youngGC();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   193
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   194
  // Force Full GC
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   195
  public native void fullGC();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   196
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   197
  // Method tries to start concurrent mark cycle.
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   198
  // It returns false if CM Thread is always in concurrent cycle.
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   199
  public native boolean g1StartConcMarkCycle();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   200
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   201
  // Tests on ReservedSpace/VirtualSpace classes
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   202
  public native int stressVirtualSpaceResize(long reservedSpaceSize, long magnitude, long iterations);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   203
  public native void runMemoryUnitTests();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   204
  public native void readFromNoaccessArea();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   205
  public native long getThreadStackSize();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   206
  public native long getThreadRemainingStackSize();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   207
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   208
  // CPU features
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   209
  public native String getCPUFeatures();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   210
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   211
  // Native extensions
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   212
  public native long getHeapUsageForContext(int context);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   213
  public native long getHeapRegionCountForContext(int context);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   214
  public native int getContextForObject(Object obj);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   215
  public native void printRegionInfo(int context);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   216
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   217
  // VM flags
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   218
  public native boolean isConstantVMFlag(String name);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   219
  public native boolean isLockedVMFlag(String name);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   220
  public native void    setBooleanVMFlag(String name, boolean value);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   221
  public native void    setIntxVMFlag(String name, long value);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   222
  public native void    setUintxVMFlag(String name, long value);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   223
  public native void    setUint64VMFlag(String name, long value);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   224
  public native void    setSizeTVMFlag(String name, long value);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   225
  public native void    setStringVMFlag(String name, String value);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   226
  public native void    setDoubleVMFlag(String name, double value);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   227
  public native Boolean getBooleanVMFlag(String name);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   228
  public native Long    getIntxVMFlag(String name);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   229
  public native Long    getUintxVMFlag(String name);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   230
  public native Long    getUint64VMFlag(String name);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   231
  public native Long    getSizeTVMFlag(String name);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   232
  public native String  getStringVMFlag(String name);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   233
  public native Double  getDoubleVMFlag(String name);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   234
  private final List<Function<String,Object>> flagsGetters = Arrays.asList(
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   235
    this::getBooleanVMFlag, this::getIntxVMFlag, this::getUintxVMFlag,
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   236
    this::getUint64VMFlag, this::getSizeTVMFlag, this::getStringVMFlag,
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   237
    this::getDoubleVMFlag);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   238
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   239
  public Object getVMFlag(String name) {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   240
    return flagsGetters.stream()
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   241
                       .map(f -> f.apply(name))
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   242
                       .filter(x -> x != null)
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   243
                       .findAny()
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   244
                       .orElse(null);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   245
  }
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   246
  public native int getOffsetForName0(String name);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   247
  public int getOffsetForName(String name) throws Exception {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   248
    int offset = getOffsetForName0(name);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   249
    if (offset == -1) {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   250
      throw new RuntimeException(name + " not found");
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   251
    }
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   252
    return offset;
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   253
  }
29440
87390f81c75d 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents: 28351
diff changeset
   254
  public native Boolean getMethodBooleanOption(Executable method, String name);
87390f81c75d 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents: 28351
diff changeset
   255
  public native Long    getMethodIntxOption(Executable method, String name);
87390f81c75d 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents: 28351
diff changeset
   256
  public native Long    getMethodUintxOption(Executable method, String name);
87390f81c75d 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents: 28351
diff changeset
   257
  public native Double  getMethodDoubleOption(Executable method, String name);
87390f81c75d 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents: 28351
diff changeset
   258
  public native String  getMethodStringOption(Executable method, String name);
87390f81c75d 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents: 28351
diff changeset
   259
  private final List<BiFunction<Executable,String,Object>> methodOptionGetters
87390f81c75d 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents: 28351
diff changeset
   260
      = Arrays.asList(this::getMethodBooleanOption, this::getMethodIntxOption,
87390f81c75d 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents: 28351
diff changeset
   261
          this::getMethodUintxOption, this::getMethodDoubleOption,
87390f81c75d 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents: 28351
diff changeset
   262
          this::getMethodStringOption);
87390f81c75d 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents: 28351
diff changeset
   263
87390f81c75d 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents: 28351
diff changeset
   264
  public Object getMethodOption(Executable method, String name) {
87390f81c75d 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents: 28351
diff changeset
   265
    return methodOptionGetters.stream()
87390f81c75d 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents: 28351
diff changeset
   266
                              .map(f -> f.apply(method, name))
87390f81c75d 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents: 28351
diff changeset
   267
                              .filter(x -> x != null)
87390f81c75d 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents: 28351
diff changeset
   268
                              .findAny()
87390f81c75d 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents: 28351
diff changeset
   269
                              .orElse(null);
87390f81c75d 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents: 28351
diff changeset
   270
  }
28154
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   271
28159
d5940675c190 8067972: Bring changes made to WhiteBox.java in 8047290 to that file new location in the top repo
kvn
parents: 28157
diff changeset
   272
  // Safepoint Checking
d5940675c190 8067972: Bring changes made to WhiteBox.java in 8047290 to that file new location in the top repo
kvn
parents: 28157
diff changeset
   273
  public native void assertMatchingSafepointCalls(boolean mutexSafepointValue, boolean attemptedNoSafepointValue);
28154
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
   274
}