hotspot/test/compiler/jvmci/compilerToVM/InitializeConfigurationTest.java
author dsamersoff
Sun, 01 May 2016 12:47:00 +0300
changeset 38152 80e5da81fb2c
parent 36508 5f9eee6b383b
child 39291 a4efe145313d
child 39423 0f8dc3693499
permissions -rw-r--r--
8154258: [TESTBUG] Various serviceability tests fail compilation Summary: Replace sun.misc.Unsafe with jdk.internal.misc.Unsafe Reviewed-by: chegar, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     1
/*
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     4
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     8
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    13
 * accompanied this code).
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    14
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    18
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    21
 * questions.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    22
 */
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    23
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    24
/*
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    25
 * @test
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    26
 * @bug 8136421
35148
5cfafc99d791 8143072: [JVMCI] Port JVMCI to AArch64
twisti
parents: 33632
diff changeset
    27
 * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9" | os.simpleArch == "aarch64")
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    28
 * @library / /testlibrary
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35148
diff changeset
    29
 * @library ../common/patches
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 36508
diff changeset
    30
 * @modules java.base/jdk.internal.misc
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35148
diff changeset
    31
 * @modules jdk.vm.ci/jdk.vm.ci.hotspot
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35148
diff changeset
    32
 * @build jdk.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    33
 * @build compiler.jvmci.compilerToVM.InitializeConfigurationTest
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35148
diff changeset
    34
 * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35148
diff changeset
    35
 *                   compiler.jvmci.compilerToVM.InitializeConfigurationTest
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    36
 */
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    37
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    38
package compiler.jvmci.compilerToVM;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    39
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    40
import java.util.ArrayList;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    41
import java.util.Iterator;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    42
import java.util.List;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    43
import java.util.NoSuchElementException;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    44
import java.util.Objects;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    45
import java.util.function.Consumer;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    46
import jdk.vm.ci.hotspot.CompilerToVMHelper;
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    47
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    48
import jdk.test.lib.Asserts;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    49
import jdk.test.lib.Utils;
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 36508
diff changeset
    50
import jdk.internal.misc.Unsafe;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    51
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    52
public class InitializeConfigurationTest {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    53
    private static final Unsafe UNSAFE = Utils.getUnsafe();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    54
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    55
    public static void main(String args[]) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    56
        new InitializeConfigurationTest().runTest(generateTestCases());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    57
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    58
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    59
    private static List<TestCase> generateTestCases() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    60
        List<TestCase> result = new ArrayList<>();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    61
        result.add(new TestCase("CodeCache", "_high_bound", "address",
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    62
                InitializeConfigurationTest::verifyLongIsNotZero));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    63
        result.add(new TestCase("StubRoutines", "_jint_arraycopy", "address",
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    64
                InitializeConfigurationTest::verifyLongIsNotZero));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    65
        return result;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    66
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    67
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    68
    private static void verifyLongIsNotZero(Object o) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    69
        Asserts.assertNotNull(o, "Got null value");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    70
        Asserts.assertEQ(o.getClass(), Long.class, "Unexpected value type");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    71
        Asserts.assertNE(o, 0L, "Got null address");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    72
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    73
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    74
    private void runTest(List<TestCase> tcases) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    75
        VMStructDataReader reader = new VMStructDataReader(
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    76
                CompilerToVMHelper.initializeConfiguration(HotSpotJVMCIRuntime.runtime().getConfig()));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    77
        while (reader.hasNext()) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    78
            VMFieldData data = reader.next();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    79
            for (TestCase tcase : tcases) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    80
                tcase.check(data);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    81
            }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    82
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    83
        // now check if all passed
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    84
        for (TestCase tcase: tcases) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    85
            Asserts.assertTrue(tcase.isFound(), "Case failed: " + tcase);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    86
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    87
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    88
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    89
    private static class VMStructDataReader implements Iterator<VMFieldData> {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    90
        // see jvmciCompilerToVM:105 static uintptr_t ciHotSpotVMData[28];
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    91
        private static final int HOTSPOT_VM_DATA_INDEX_COUNT = 28;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    92
        private final long addresses[];
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    93
        private final long vmStructsBase;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    94
        private final long entityNameFieldOffset;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    95
        private final long nameFieldOffset;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    96
        private final long typeStringFieldOffset;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    97
        private final long addressOffset;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    98
        private final long entrySize;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    99
        private long nextElementAddress;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   100
        private VMFieldData nextElement;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   101
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   102
        public VMStructDataReader(long gHotSpotVMData) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   103
            Asserts.assertNE(gHotSpotVMData, 0L, "Got null base address");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   104
            addresses = new long[HOTSPOT_VM_DATA_INDEX_COUNT];
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   105
            for (int i = 0; i < HOTSPOT_VM_DATA_INDEX_COUNT; i++) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   106
                addresses[i] = UNSAFE.getAddress(
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   107
                        gHotSpotVMData + Unsafe.ADDRESS_SIZE * i);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   108
            }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   109
            vmStructsBase = addresses[0];
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   110
            entityNameFieldOffset = addresses[1];
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   111
            nameFieldOffset = addresses[2];
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   112
            typeStringFieldOffset = addresses[3];
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   113
            addressOffset = addresses[6];
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   114
            entrySize = addresses[7];
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   115
            nextElementAddress = vmStructsBase;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   116
            nextElement = read();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   117
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   118
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   119
        @Override
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   120
        public boolean hasNext() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   121
            return nextElement != null;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   122
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   123
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   124
        @Override
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   125
        public VMFieldData next() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   126
            if (nextElement == null) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   127
                throw new NoSuchElementException("Next element is null");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   128
            }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   129
            VMFieldData toReturn = nextElement;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   130
            nextElementAddress += entrySize;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   131
            nextElement = read();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   132
            return toReturn;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   133
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   134
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   135
        private VMFieldData read() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   136
            String entityFieldName = readCString(
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   137
                    UNSAFE.getAddress(nextElementAddress + nameFieldOffset));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   138
            if (entityFieldName == null) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   139
                return null;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   140
            }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   141
            String fieldType = readCString(UNSAFE.getAddress(
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   142
                    nextElementAddress + typeStringFieldOffset));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   143
            String entityName = readCString(UNSAFE.getAddress(
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   144
                    nextElementAddress + entityNameFieldOffset));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   145
            Object value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   146
            if ("address".equals(fieldType)) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   147
                long address = UNSAFE.getAddress(
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   148
                        nextElementAddress + addressOffset);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   149
                value = address;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   150
            } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   151
                // non-address cases are not supported
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   152
                value = null;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   153
            }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   154
            return new VMFieldData(entityName, entityFieldName, fieldType,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   155
                    value);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   156
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   157
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   158
        private static String readCString(long address) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   159
            if (address == 0) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   160
                return null;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   161
            }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   162
            StringBuilder sb = new StringBuilder();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   163
            for (int i = 0;; i++) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   164
                char c = (char) UNSAFE.getByte(address + i);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   165
                if (c == 0) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   166
                    break;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   167
                }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   168
                sb.append(c);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   169
            }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   170
            return sb.toString();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   171
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   172
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   173
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   174
    private static class VMFieldData {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   175
        public final String entityFieldName;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   176
        public final String entityName;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   177
        public final String fieldType;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   178
        public final Object value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   179
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   180
        private VMFieldData(String entityName, String entityFieldName,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   181
                String fieldType, Object value) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   182
            this.entityName = entityName;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   183
            this.entityFieldName = entityFieldName;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   184
            this.fieldType = fieldType;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   185
            this.value = value;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   186
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   187
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   188
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   189
    private static class TestCase {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   190
        public final String entityName;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   191
        public final String fieldType;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   192
        public final String entityFieldName;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   193
        public final Consumer consumer;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   194
        private boolean found;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   195
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   196
        public TestCase(String entityName, String entityFieldName,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   197
                String fieldType, Consumer predicate) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   198
            Objects.requireNonNull(entityName, "Got null entityName");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   199
            Objects.requireNonNull(entityFieldName, "Got null entityFieldName");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   200
            Objects.requireNonNull(fieldType, "Got null type");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   201
            if (!"address".equals(fieldType)) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   202
                throw new Error("TESTBUG: unsupported testcase with fieldType="
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   203
                        + fieldType);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   204
            }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   205
            this.entityName = entityName;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   206
            this.fieldType = fieldType;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   207
            this.entityFieldName = entityFieldName;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   208
            this.consumer = predicate;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   209
            this.found = false;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   210
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   211
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   212
        public void check(VMFieldData data) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   213
            if (entityFieldName.equals(data.entityFieldName)
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   214
                    && entityName.equals(data.entityName)
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   215
                    && fieldType.equals(data.fieldType)) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   216
                Asserts.assertFalse(found, "Found 2 entries of " + this);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   217
                found = true;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   218
                consumer.accept(data.value);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   219
            }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   220
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   221
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   222
        @Override
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   223
        public String toString() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   224
            return "CASE: entityName=" + entityName + " entityFieldName="
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   225
                    + entityFieldName + " fieldType=" + fieldType;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   226
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   227
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   228
        public boolean isFound() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   229
            return found;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   230
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   231
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   232
}