src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/ObjectHashCodeInliningTest.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58299 6df94ce3ab2f
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54601
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
     1
/*
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
     4
 *
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
     8
 *
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    13
 * accompanied this code).
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    14
 *
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    18
 *
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    21
 * questions.
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    22
 */
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    23
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    24
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    25
package org.graalvm.compiler.hotspot.test;
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    26
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    27
import org.graalvm.compiler.core.test.GraalCompilerTest;
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 55509
diff changeset
    28
import org.graalvm.compiler.java.BytecodeParserOptions;
54601
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    29
import org.graalvm.compiler.nodes.StructuredGraph;
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    30
import org.graalvm.compiler.nodes.extended.ForeignCallNode;
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    31
import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    32
import org.graalvm.compiler.nodes.memory.ReadNode;
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 55509
diff changeset
    33
import org.graalvm.compiler.options.OptionValues;
54601
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    34
import org.junit.Test;
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    35
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 55509
diff changeset
    36
import jdk.vm.ci.meta.JavaTypeProfile;
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 55509
diff changeset
    37
import jdk.vm.ci.meta.JavaTypeProfile.ProfiledType;
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 55509
diff changeset
    38
import jdk.vm.ci.meta.MetaAccessProvider;
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 55509
diff changeset
    39
import jdk.vm.ci.meta.ResolvedJavaMethod;
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 55509
diff changeset
    40
import jdk.vm.ci.meta.TriState;
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 55509
diff changeset
    41
54601
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    42
public class ObjectHashCodeInliningTest extends GraalCompilerTest {
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    43
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    44
    public static int getHash(Object obj) {
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    45
        return obj.hashCode();
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    46
    }
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    47
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    48
    @Test
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 55509
diff changeset
    49
    public void testGetHash() {
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 55509
diff changeset
    50
        MetaAccessProvider metaAccess = getMetaAccess();
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 55509
diff changeset
    51
        ProfiledType[] injectedProfile = {
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 55509
diff changeset
    52
                        new ProfiledType(metaAccess.lookupJavaType(String.class), 0.9D),
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 55509
diff changeset
    53
                        new ProfiledType(metaAccess.lookupJavaType(Object.class), 0.1D)};
54601
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    54
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    55
        ResolvedJavaMethod method = getResolvedJavaMethod("getHash");
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 55509
diff changeset
    56
        StructuredGraph graph = parseForCompile(method,
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 55509
diff changeset
    57
                        new OptionValues(getInitialOptions(), BytecodeParserOptions.InlineDuringParsing, false, BytecodeParserOptions.InlineIntrinsicsDuringParsing, false));
54601
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    58
        for (MethodCallTargetNode callTargetNode : graph.getNodes(MethodCallTargetNode.TYPE)) {
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    59
            if ("Object.hashCode".equals(callTargetNode.targetName())) {
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 55509
diff changeset
    60
                callTargetNode.setJavaTypeProfile(new JavaTypeProfile(TriState.FALSE, 0.0D, injectedProfile));
54601
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    61
            }
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    62
        }
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 55509
diff changeset
    63
54601
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    64
        compile(method, graph);
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    65
    }
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    66
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    67
    private static boolean containsForeignCallToIdentityHashCode(StructuredGraph graph) {
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    68
        for (ForeignCallNode foreignCallNode : graph.getNodes().filter(ForeignCallNode.class)) {
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    69
            if ("identity_hashcode".equals(foreignCallNode.getDescriptor().getName())) {
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    70
                return true;
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    71
            }
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    72
        }
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    73
        return false;
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    74
    }
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    75
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    76
    private static boolean containsReadStringHash(StructuredGraph graph) {
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    77
        for (ReadNode readNode : graph.getNodes().filter(ReadNode.class)) {
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    78
            if ("String.hash".equals(readNode.getLocationIdentity().toString())) {
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    79
                return true;
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    80
            }
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    81
        }
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    82
        return false;
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    83
    }
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    84
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    85
    @Override
55509
d58442b8abc1 8225497: Update Graal
jwilhelm
parents: 54601
diff changeset
    86
    protected void checkHighTierGraph(StructuredGraph graph) {
d58442b8abc1 8225497: Update Graal
jwilhelm
parents: 54601
diff changeset
    87
        assert containsForeignCallToIdentityHashCode(graph) : "expected a foreign call to identity_hashcode";
d58442b8abc1 8225497: Update Graal
jwilhelm
parents: 54601
diff changeset
    88
        assert containsReadStringHash(graph) : "expected a read from String.hash";
54601
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    89
    }
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    90
c40b2a190173 8221598: Update Graal
jwilhelm
parents:
diff changeset
    91
}