Skip to content

Commit

Permalink
8279619: [JVMCI] improve EncodedSpeculationReason
Browse files Browse the repository at this point in the history
Reviewed-by: never
  • Loading branch information
Doug Simon committed Mar 3, 2023
1 parent 7449e1c commit 80739e1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. 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
Expand Down Expand Up @@ -61,6 +61,7 @@ public SpeculationLog.SpeculationReasonEncoding encode(Supplier<SpeculationLog.S
if (encoding == null) {
encoding = encodingSupplier.get();
encoding.addInt(groupId);
encoding.addInt(groupName.hashCode());
for (Object o : context) {
if (o == null) {
encoding.addInt(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. 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
Expand All @@ -20,6 +20,19 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/**
* @test
* @requires vm.jvmci
* @library ../../../../../
* @modules java.base/jdk.internal.reflect
* jdk.internal.vm.ci/jdk.vm.ci.meta
* jdk.internal.vm.ci/jdk.vm.ci.code
* jdk.internal.vm.ci/jdk.vm.ci.runtime
* jdk.internal.vm.ci/jdk.vm.ci.common
* java.base/jdk.internal.misc
* @run junit/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:-UseJVMCICompiler jdk.vm.ci.runtime.test.TestSpeculationLog
*/
package jdk.vm.ci.runtime.test;

import java.util.ArrayList;
Expand All @@ -31,7 +44,9 @@
import org.junit.Test;

import jdk.vm.ci.code.CodeCacheProvider;
import jdk.vm.ci.meta.EncodedSpeculationReason;
import jdk.vm.ci.meta.JavaConstant;
import jdk.vm.ci.meta.MetaAccessProvider;
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.ResolvedJavaType;
import jdk.vm.ci.meta.SpeculationLog;
Expand Down Expand Up @@ -128,4 +143,28 @@ public synchronized void testSpeculationIdentity() {
JavaConstant e2 = metaAccess.encodeSpeculation(s2);
Assert.assertTrue("speculation encoding should maintain identity", e1.equals(e2));
}

@Test
public void testEncodedSpeculationReasonIncludesGroupName() {
MetaAccessProvider metaAccess = JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess();
CodeCacheProvider codeCache = JVMCI.getRuntime().getHostJVMCIBackend().getCodeCache();
SpeculationLog log = codeCache.createSpeculationLog();
Object[] context = {"context"};
SpeculationLog.SpeculationReason sr1 = new EncodedSpeculationReason(0, "group0", context);
SpeculationLog.SpeculationReason sr2 = new EncodedSpeculationReason(0, "group1", context);
SpeculationLog.Speculation s1 = log.speculate(sr1);
SpeculationLog.Speculation s2 = log.speculate(sr2);
JavaConstant es1 = metaAccess.encodeSpeculation(s1);
JavaConstant es2 = metaAccess.encodeSpeculation(s2);
if (es1.equals(es2)) {
Assert.fail(
String.format("EncodedSpeculationReasons with different groupName should produce unique encoded speculations:%n" +
" Reason 1: %s%n" +
" Reason 2: %s%n" +
" Speculation 1: %s%n" +
" Speculation 2: %s%n" +
" Encoded speculation 1: %s%n" +
" Encoded speculation 2: %s%n", sr1, sr2, s1, s2, es1, es2));
}
}
}

1 comment on commit 80739e1

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.