当前位置: 首页>>代码示例>>Java>>正文


Java Utils类代码示例

本文整理汇总了Java中com.oracle.java.testlibrary.Utils的典型用法代码示例。如果您正苦于以下问题:Java Utils类的具体用法?Java Utils怎么用?Java Utils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Utils类属于com.oracle.java.testlibrary包,在下文中一共展示了Utils类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: canPtraceAttachLinux

import com.oracle.java.testlibrary.Utils; //导入依赖的package包/类
/**
 * On Linux, first check the SELinux boolean "deny_ptrace" and return false
 * as we expect to be denied if that is "1".  Then expect permission to attach
 * if we are root, so return true.  Then return false for an expected denial
 * if "ptrace_scope" is 1, and true otherwise.
 */
public static boolean canPtraceAttachLinux() throws Exception {

    // SELinux deny_ptrace:
    String deny_ptrace = Utils.fileAsString("/sys/fs/selinux/booleans/deny_ptrace");
    if (deny_ptrace != null && deny_ptrace.contains("1")) {
        // ptrace will be denied:
        return false;
    }

    if (userName.equals("root")) {
        return true;
    }

    // ptrace_scope:
    String ptrace_scope = Utils.fileAsString("/proc/sys/kernel/yama/ptrace_scope");
    if (ptrace_scope != null && ptrace_scope.contains("1")) {
        // ptrace will be denied:
        return false;
    }

    // Otherwise expect to be permitted:
    return true;
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:30,代码来源:Platform.java

示例2: test

import com.oracle.java.testlibrary.Utils; //导入依赖的package包/类
protected void test() throws Exception {
    ArrayList<String> vmOpts = new ArrayList();
    Collections.addAll(vmOpts, initialOpts);

    int maxCacheSize = Math.max(0, Math.min(31, getMaxCacheSize()));
    if (maxCacheSize < hotCardTableSize) {
        System.out.format("Skiping test for %d cache size due max cache size %d",
                hotCardTableSize, maxCacheSize
        );
        return;
    }

    printTestInfo(maxCacheSize);

    vmOpts.add("-XX:G1ConcRSLogCacheSize=" + hotCardTableSize);
    vmOpts.addAll(Arrays.asList(Utils.getTestJavaOpts()));

    // for 32 bits ObjectAlignmentInBytes is not a option
    if (Platform.is32bit()) {
        ArrayList<String> vmOptsWithoutAlign = new ArrayList(vmOpts);
        vmOptsWithoutAlign.add(ShrinkAuxiliaryDataTest.class.getName());
        performTest(vmOptsWithoutAlign);
        return;
    }

    for (int alignment = 3; alignment <= 8; alignment++) {
        ArrayList<String> vmOptsWithAlign = new ArrayList(vmOpts);
        vmOptsWithAlign.add("-XX:ObjectAlignmentInBytes="
                + (int) Math.pow(2, alignment));
        vmOptsWithAlign.add(ShrinkAuxiliaryDataTest.class.getName());

        performTest(vmOptsWithAlign);
    }
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:35,代码来源:TestShrinkAuxiliaryData.java

示例3: prepareFilteredTestOptions

import com.oracle.java.testlibrary.Utils; //导入依赖的package包/类
/**
 * Prepares VM options for test execution.
 * This method get test java options, filter out all RTM-related options
 * and all options that matches regexps in {@code additionalFilters},
 * adds CompileCommand=compileonly,method_name options for each method
 * from {@code methodToCompile} and finally appends all {@code vmOpts}.
 *
 * @param test test case whose methods that should be compiled.
 *             If {@code null} then no additional <i>compileonly</i>
 *             commands will be added to VM options.
 * @param additionalFilters array with regular expression that will be
 *                          used to filter out test java options.
 *                          If {@code null} then no additional filters
 *                          will be used.
 * @param vmOpts additional options to pass to VM.
 * @return array with VM options.
 */
private static String[] prepareFilteredTestOptions(CompilableTest test,
        String[] additionalFilters, String... vmOpts) {
    List<String> finalVMOpts = new LinkedList<>();
    String[] filters;

    if (additionalFilters != null) {
        filters = Arrays.copyOf(additionalFilters,
                additionalFilters.length + 1);
    } else {
        filters = new String[1];
    }

    filters[filters.length - 1] = "RTM";
    String[] filteredVMOpts = Utils.getFilteredTestJavaOpts(filters);
    Collections.addAll(finalVMOpts, filteredVMOpts);
    Collections.addAll(finalVMOpts, "-Xcomp", "-server",
            "-XX:-TieredCompilation", "-XX:+UseRTMLocking",
            CommandLineOptionTest.UNLOCK_DIAGNOSTIC_VM_OPTIONS,
            CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS,
            "-Xbootclasspath/a:.", "-XX:+WhiteBoxAPI");

    if (test != null) {
        for (String method : test.getMethodsToCompileNames()) {
            finalVMOpts.add("-XX:CompileCommand=compileonly," + method);
        }
    }
    Collections.addAll(finalVMOpts, vmOpts);
    return finalVMOpts.toArray(new String[finalVMOpts.size()]);
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:47,代码来源:RTMTestBase.java

示例4: checkEmittedCode

import com.oracle.java.testlibrary.Utils; //导入依赖的package包/类
protected void checkEmittedCode(Executable executable) {
    final byte[] nativeCode = NMethod.get(executable, false).insts;
    if (!((BmiTestCase) testCase).verifyPositive(nativeCode)) {
        throw new AssertionError(testCase.name() + "CPU instructions expected not found: " + Utils.toHexString(nativeCode));
    } else {
        System.out.println("CPU instructions found, PASSED");
    }
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:9,代码来源:BmiIntrinsicBase.java

示例5: test

import com.oracle.java.testlibrary.Utils; //导入依赖的package包/类
protected void test() throws Exception {
    ArrayList<String> vmOpts = new ArrayList();
    Collections.addAll(vmOpts, initialOpts);

    int maxCacheSize = Math.max(0, Math.min(31, getMaxCacheSize()));
    if (maxCacheSize < RSetCacheSize) {
        System.out.format("Skiping test for %d cache size due max cache size %d",
                RSetCacheSize, maxCacheSize
        );
        return;
    }

    printTestInfo(maxCacheSize);

    vmOpts.add("-XX:G1ConcRSLogCacheSize=" + RSetCacheSize);

    vmOpts.addAll(Arrays.asList(Utils.getFilteredTestJavaOpts(
            ShrinkAuxiliaryDataTest.prohibitedVmOptions)));

    // for 32 bits ObjectAlignmentInBytes is not a option
    if (Platform.is32bit()) {
        ArrayList<String> vmOptsWithoutAlign = new ArrayList(vmOpts);
        vmOptsWithoutAlign.add(ShrinkAuxiliaryDataTest.class.getName());
        performTest(vmOptsWithoutAlign);
        return;
    }

    for (int alignment = 3; alignment <= 8; alignment++) {
        ArrayList<String> vmOptsWithAlign = new ArrayList(vmOpts);
        vmOptsWithAlign.add("-XX:ObjectAlignmentInBytes="
                + (int) Math.pow(2, alignment));
        vmOptsWithAlign.add(ShrinkAuxiliaryDataTest.class.getName());

        performTest(vmOptsWithAlign);
    }
}
 
开发者ID:infobip,项目名称:infobip-open-jdk-8,代码行数:37,代码来源:TestShrinkAuxiliaryData.java

示例6: inflateMonitor

import com.oracle.java.testlibrary.Utils; //导入依赖的package包/类
/**
 * Inflates monitor associated with object {@code monitor}.
 * Inflation is forced by entering the same monitor from
 * two different threads.
 *
 * @param monitor monitor to be inflated.
 * @return inflated monitor.
 * @throws Exception if something went wrong.
 */
public static Object inflateMonitor(Object monitor) throws Exception {
    Unsafe unsafe = Utils.getUnsafe();
    CyclicBarrier barrier = new CyclicBarrier(2);

    Runnable inflatingRunnable = () -> {
        unsafe.monitorEnter(monitor);
        try {
            barrier.await();
            barrier.await();
        } catch (InterruptedException | BrokenBarrierException e) {
            throw new RuntimeException(
                    "Synchronization issue occurred.", e);
        } finally {
            unsafe.monitorExit(monitor);
        }
    };

    Thread t = new Thread(inflatingRunnable);
    t.start();
    // Wait until thread t enters the monitor.
    barrier.await();
    // At this point monitor will be owned by thread t,
    // so our attempt to enter the same monitor will force
    // monitor inflation.
    Asserts.assertFalse(unsafe.tryMonitorEnter(monitor),
                        "Not supposed to enter the monitor first");
    barrier.await();
    t.join();
    return monitor;
}
 
开发者ID:infobip,项目名称:infobip-open-jdk-8,代码行数:40,代码来源:AbortProvoker.java

示例7: prepareFilteredTestOptions

import com.oracle.java.testlibrary.Utils; //导入依赖的package包/类
/**
 * Prepares VM options for test execution.
 * This method get test java options, filter out all RTM-related options
 * and all options that matches regexps in {@code additionalFilters},
 * adds CompileCommand=compileonly,method_name options for each method
 * from {@code methodToCompile} and finally appends all {@code vmOpts}.
 *
 * @param test test case whose methods that should be compiled.
 *             If {@code null} then no additional <i>compileonly</i>
 *             commands will be added to VM options.
 * @param additionalFilters array with regular expression that will be
 *                          used to filter out test java options.
 *                          If {@code null} then no additional filters
 *                          will be used.
 * @param vmOpts additional options to pass to VM.
 * @return array with VM options.
 */
private static String[] prepareFilteredTestOptions(CompilableTest test,
        String[] additionalFilters, String... vmOpts) {
    List<String> finalVMOpts = new LinkedList<>();
    String[] filters;

    if (additionalFilters != null) {
        filters = Arrays.copyOf(additionalFilters,
                additionalFilters.length + 1);
    } else {
        filters = new String[1];
    }

    filters[filters.length - 1] = "RTM";
    String[] filteredVMOpts = Utils.getFilteredTestJavaOpts(filters);
    Collections.addAll(finalVMOpts, filteredVMOpts);
    Collections.addAll(finalVMOpts, "-Xcomp", "-server",
            "-XX:-TieredCompilation",
            CommandLineOptionTest.UNLOCK_DIAGNOSTIC_VM_OPTIONS,
            CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS,
            "-XX:+UseRTMLocking");

    if (test != null) {
        for (String method : test.getMethodsToCompileNames()) {
            finalVMOpts.add("-XX:CompileCommand=compileonly," + method);
        }
    }
    Collections.addAll(finalVMOpts, vmOpts);
    return finalVMOpts.toArray(new String[finalVMOpts.size()]);
}
 
开发者ID:infobip,项目名称:infobip-open-jdk-8,代码行数:47,代码来源:RTMTestBase.java

示例8: main

import com.oracle.java.testlibrary.Utils; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
  sun.misc.Unsafe unsafe = Utils.getUnsafe();
  final int array_size = 128;
  final int element_size = 4;
  final int magic = 0x12345678;

  Random rnd = new Random();

  long array = unsafe.allocateMemory(array_size * element_size); // 128 ints
  long addr = array + array_size * element_size / 2; // something in the middle to work with
  unsafe.putInt(addr, magic);
  for (int j = 0; j < 100000; j++) {
     if (Tests.int_index(unsafe, addr, 0) != magic) throw new Exception();
     if (Tests.long_index(unsafe, addr, 0) != magic) throw new Exception();
     if (Tests.int_index_mul(unsafe, addr, 0) != magic) throw new Exception();
     if (Tests.long_index_mul(unsafe, addr, 0) != magic) throw new Exception();
     {
       long idx1 = rnd.nextLong();
       long addr1 = addr - (idx1 << 2);
       if (Tests.long_index(unsafe, addr1, idx1) != magic) throw new Exception();
     }
     {
       long idx2 = rnd.nextLong();
       long addr2 = addr - (idx2 >> 2);
       if (Tests.long_index_back_ashift(unsafe, addr2, idx2) != magic) throw new Exception();
     }
     {
       long idx3 = rnd.nextLong();
       long addr3 = addr - (idx3 >>> 2);
       if (Tests.long_index_back_lshift(unsafe, addr3, idx3) != magic) throw new Exception();
     }
     {
       long idx4 = 0x12345678;
       long addr4 = addr - idx4;
       if (Tests.int_const_12345678_index(unsafe, addr4) != magic) throw new Exception();
     }
     {
       long idx5 = 0x1234567890abcdefL;
       long addr5 = addr - idx5;
       if (Tests.long_const_1234567890abcdef_index(unsafe, addr5) != magic) throw new Exception();
     }
     {
       int idx6 = rnd.nextInt();
       long addr6 = addr - (idx6 >> 2);
       if (Tests.int_index_back_ashift(unsafe, addr6, idx6) != magic) throw new Exception();
     }
     {
       int idx7 = rnd.nextInt();
       long addr7 = addr - (idx7 >>> 2);
       if (Tests.int_index_back_lshift(unsafe, addr7, idx7) != magic) throw new Exception();
     }
     {
       int idx8 = rnd.nextInt();
       long addr8 = addr - (idx8 * 16);
       if (Tests.int_index_mul_scale_16(unsafe, addr8, idx8) != magic) throw new Exception();
     }
     {
       long idx9 = rnd.nextLong();
       long addr9 = addr - (idx9 * 16);
       if (Tests.long_index_mul_scale_16(unsafe, addr9, idx9) != magic) throw new Exception();
     }
  }
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:64,代码来源:UnsafeRaw.java


注:本文中的com.oracle.java.testlibrary.Utils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。