Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8247832: [Graal] Many Javafuzzer tests failures with Graal, due to un…
…expected results, after last update JDK-8243380

Cherry-picking GR-24281

Reviewed-by: roland, kvn
  • Loading branch information
TobiHartmann committed Jun 29, 2020
1 parent f44f885 commit 97cdfb92f8ac195b9c8a872a34ffa8b19fd74860
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 62 deletions.
@@ -195,45 +195,6 @@ public void test08() {
verifyMembars("volatileFieldStore", membarsExpected());
}

// Unused field load should be optimized out and leave no barrier behind
@SuppressWarnings("unused")
public static void volatileFieldStoreUnusedVolatileFieldLoadVolatileFieldStore(int v2) {
VolatileAccess2.field = v2;
int v1 = VolatileAccess.field;
VolatileAccess2.field = v2;
}

@Test
public void test09() {
StructuredGraph graph = getFinalGraph(getResolvedJavaMethod("volatileFieldStoreUnusedVolatileFieldLoadVolatileFieldStore"));
List<TypePair> accesses = getAccesses(graph);

Assert.assertEquals(accesses.size(), 2);
Assert.assertEquals(accesses.get(0).getType(), volatileAccess2Type);
Assert.assertEquals(accesses.get(1).getType(), volatileAccess2Type);
Assert.assertTrue(accesses.get(0).isWrite());
Assert.assertTrue(accesses.get(1).isWrite());
Assert.assertEquals(membarsExpected() ? 4 : 0, getMembars(graph).size());
}

// Unused field load should be optimized out and leave no barrier behind
@SuppressWarnings("unused")
public static void unusedVolatileFieldLoadVolatileFieldStore(int v2) {
int v1 = VolatileAccess.field;
VolatileAccess2.field = v2;
}

@Test
public void test10() {
StructuredGraph graph = getFinalGraph(getResolvedJavaMethod("unusedVolatileFieldLoadVolatileFieldStore"));
List<TypePair> accesses = getAccesses(graph);

Assert.assertEquals(accesses.size(), 1);
Assert.assertEquals(accesses.get(0).getType(), volatileAccess2Type);
Assert.assertTrue(accesses.get(0).isWrite());
Assert.assertEquals(membarsExpected() ? 2 : 0, getMembars(graph).size());
}

public static int unsafeVolatileFieldLoad(Object o, long offset) {
return UNSAFE.getIntVolatile(o, offset);
}
@@ -346,11 +307,4 @@ private ResolvedJavaType classForAccess(FixedAccessNode n) {
return javaType;
}

private static List<Node> getMembars(StructuredGraph graph) {
StructuredGraph.ScheduleResult schedule = graph.getLastSchedule();
ControlFlowGraph cfg = schedule.getCFG();
Block[] blocks = cfg.getBlocks();

return Arrays.stream(blocks).flatMap(b -> schedule.nodesFor(b).stream()).filter(n -> n instanceof MembarNode).collect(Collectors.toList());
}
}
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, Red Hat Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/


package org.graalvm.compiler.core.test;

import org.junit.Test;

// See https://bugs.openjdk.java.net/browse/JDK-8247832
public class VolatileReadEliminateWrongMemoryStateTest extends GraalCompilerTest {

private static volatile int volatileField;
private static int field;

@SuppressWarnings("unused")
public static int testMethod() {
field = 0;
int v = volatileField;
field += 1;
v = volatileField;
field += 1;
return field;
}

@Test
public void test1() {
test("testMethod");
}

public static void testMethod2(Object obj) {
synchronized (obj) {
volatileField++;
}
}

@Test
public void test2() {
test("testMethod2", new Object());
}
}
@@ -33,8 +33,6 @@
import org.graalvm.compiler.core.common.LIRKind;
import org.graalvm.compiler.core.common.type.Stamp;
import org.graalvm.compiler.graph.NodeClass;
import org.graalvm.compiler.graph.spi.Simplifiable;
import org.graalvm.compiler.graph.spi.SimplifierTool;
import org.graalvm.compiler.nodeinfo.NodeInfo;
import org.graalvm.compiler.nodes.NodeView;
import org.graalvm.compiler.nodes.memory.address.AddressNode;
@@ -43,20 +41,11 @@
import jdk.internal.vm.compiler.word.LocationIdentity;

@NodeInfo(nameTemplate = "VolatileRead#{p#location/s}", allowedUsageTypes = Memory, cycles = CYCLES_2, size = SIZE_1)
public class VolatileReadNode extends ReadNode implements SingleMemoryKill, Lowerable, Simplifiable {
public class VolatileReadNode extends ReadNode implements SingleMemoryKill, Lowerable {
public static final NodeClass<VolatileReadNode> TYPE = NodeClass.create(VolatileReadNode.class);

public VolatileReadNode(AddressNode address, LocationIdentity location, Stamp stamp, BarrierType barrierType) {
super(TYPE, address, location, stamp, null, barrierType, false, null);
}

@Override
public void simplify(SimplifierTool tool) {
if (lastLocationAccess != null && hasOnlyUsagesOfType(Memory)) {
replaceAtUsages(lastLocationAccess.asNode(), Memory);
assert hasNoUsages();
graph().removeFixed(this);
}
public VolatileReadNode(AddressNode address, Stamp stamp, BarrierType barrierType) {
super(TYPE, address, LocationIdentity.any(), stamp, null, barrierType, false, null);
}

@Override
@@ -475,7 +475,7 @@ protected void lowerLoadFieldNode(LoadFieldNode loadField, LoweringTool tool) {
ReadNode memoryRead = null;
BarrierType barrierType = barrierSet.fieldLoadBarrierType(field, getStorageKind(field));
if (loadField.isVolatile()) {
memoryRead = graph.add(new VolatileReadNode(address, fieldLocationIdentity(field), loadStamp, barrierType));
memoryRead = graph.add(new VolatileReadNode(address, loadStamp, barrierType));
} else {
memoryRead = graph.add(new ReadNode(address, fieldLocationIdentity(field), loadStamp, barrierType));
}
@@ -767,7 +767,7 @@ protected ReadNode createUnsafeRead(StructuredGraph graph, RawLoadNode load, Gua
AddressNode address = createUnsafeAddress(graph, load.object(), load.offset());
ReadNode memoryRead = null;
if (load.isVolatile()) {
memoryRead = new VolatileReadNode(address, load.getLocationIdentity(), loadStamp, barrierSet.readBarrierType(load));
memoryRead = new VolatileReadNode(address, loadStamp, barrierSet.readBarrierType(load));
} else {
memoryRead = new ReadNode(address, load.getLocationIdentity(), loadStamp, barrierSet.readBarrierType(load));
}

0 comments on commit 97cdfb9

Please sign in to comment.