< prev index next >

test/lib/sun/hotspot/WhiteBox.java

Print this page




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  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.management.MemoryUsage;
  28 import java.lang.reflect.Executable;

  29 import java.util.Arrays;
  30 import java.util.List;
  31 import java.util.function.BiFunction;
  32 import java.util.function.Function;
  33 import java.util.stream.Stream;
  34 import java.security.BasicPermission;
  35 import java.util.Objects;
  36 
  37 import sun.hotspot.parser.DiagnosticCommand;
  38 
  39 public class WhiteBox {
  40 
  41   @SuppressWarnings("serial")
  42   public static class WhiteBoxPermission extends BasicPermission {
  43     public WhiteBoxPermission(String s) {
  44       super(s);
  45     }
  46   }
  47 
  48   private WhiteBox() {}
  49   private static final WhiteBox instance = new WhiteBox();
  50   private static native void registerNatives();
  51 
  52   /**
  53    * Returns the singleton WhiteBox instance.
  54    *
  55    * The returned WhiteBox object should be carefully guarded
  56    * by the caller, since it can be used to read and write data
  57    * at arbitrary memory addresses. It must never be passed to
  58    * untrusted code.
  59    */
  60   public synchronized static WhiteBox getWhiteBox() {


 344     return offset;
 345   }
 346   public native Boolean getMethodBooleanOption(Executable method, String name);
 347   public native Long    getMethodIntxOption(Executable method, String name);
 348   public native Long    getMethodUintxOption(Executable method, String name);
 349   public native Double  getMethodDoubleOption(Executable method, String name);
 350   public native String  getMethodStringOption(Executable method, String name);
 351   private final List<BiFunction<Executable,String,Object>> methodOptionGetters
 352       = Arrays.asList(this::getMethodBooleanOption, this::getMethodIntxOption,
 353           this::getMethodUintxOption, this::getMethodDoubleOption,
 354           this::getMethodStringOption);
 355 
 356   public Object getMethodOption(Executable method, String name) {
 357     return methodOptionGetters.stream()
 358                               .map(f -> f.apply(method, name))
 359                               .filter(x -> x != null)
 360                               .findAny()
 361                               .orElse(null);
 362   }
 363 

















 364   // Safepoint Checking
 365   public native void assertMatchingSafepointCalls(boolean mutexSafepointValue, boolean attemptedNoSafepointValue);
 366 
 367   // Sharing
 368   public native boolean isShared(Object o);
 369   public native boolean areSharedStringsIgnored();
 370 }


   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  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.management.MemoryUsage;
  28 import java.lang.reflect.Executable;
  29 import java.nio.ByteBuffer;
  30 import java.util.Arrays;
  31 import java.util.List;
  32 import java.util.function.BiFunction;
  33 import java.util.function.Function;
  34 import java.util.stream.Stream;
  35 import java.security.BasicPermission;
  36 import java.util.Objects;
  37 
  38 import sun.hotspot.parser.DiagnosticCommand;
  39 
  40 public class WhiteBox {

  41   @SuppressWarnings("serial")
  42   public static class WhiteBoxPermission extends BasicPermission {
  43     public WhiteBoxPermission(String s) {
  44       super(s);
  45     }
  46   }
  47 
  48   private WhiteBox() {}
  49   private static final WhiteBox instance = new WhiteBox();
  50   private static native void registerNatives();
  51 
  52   /**
  53    * Returns the singleton WhiteBox instance.
  54    *
  55    * The returned WhiteBox object should be carefully guarded
  56    * by the caller, since it can be used to read and write data
  57    * at arbitrary memory addresses. It must never be passed to
  58    * untrusted code.
  59    */
  60   public synchronized static WhiteBox getWhiteBox() {


 344     return offset;
 345   }
 346   public native Boolean getMethodBooleanOption(Executable method, String name);
 347   public native Long    getMethodIntxOption(Executable method, String name);
 348   public native Long    getMethodUintxOption(Executable method, String name);
 349   public native Double  getMethodDoubleOption(Executable method, String name);
 350   public native String  getMethodStringOption(Executable method, String name);
 351   private final List<BiFunction<Executable,String,Object>> methodOptionGetters
 352       = Arrays.asList(this::getMethodBooleanOption, this::getMethodIntxOption,
 353           this::getMethodUintxOption, this::getMethodDoubleOption,
 354           this::getMethodStringOption);
 355 
 356   public Object getMethodOption(Executable method, String name) {
 357     return methodOptionGetters.stream()
 358                               .map(f -> f.apply(method, name))
 359                               .filter(x -> x != null)
 360                               .findAny()
 361                               .orElse(null);
 362   }
 363 
 364   public native boolean readImageFile(String imagePath);
 365   public native long imageOpenImage(String imagePath, boolean bigEndian);
 366   public native void imageCloseImage(long id);
 367   public native long imageGetIndexAddress(long id);
 368   public native long imageGetDataAddress(long id);
 369   public native boolean imageReadCompressed(long id, long offset,
 370     ByteBuffer compressedBuffer, long compressedSize,
 371     ByteBuffer uncompressedBuffer, long uncompressedSize);
 372   public native boolean imageRead(long id, long offset,
 373     ByteBuffer uncompressedBuffer, long uncompressedSize);
 374   public native byte[] imageGetStringBytes(long id, int offset);
 375   public native long imageGetStringsSize(long id);
 376   public native long[] imageGetAttributes(long id, int offset);
 377   public native long[] imageFindAttributes(long id, byte[] path);
 378   public native int[] imageAttributeOffsets(long id);
 379   public native int imageGetIntAtAddress(long address, int offset, boolean big_endian);
 380 
 381   // Safepoint Checking
 382   public native void assertMatchingSafepointCalls(boolean mutexSafepointValue, boolean attemptedNoSafepointValue);
 383 
 384   // Sharing
 385   public native boolean isShared(Object o);
 386   public native boolean areSharedStringsIgnored();
 387 }
< prev index next >