Skip to content

8255067: Restore Copyright line in file modified by 8253191 #771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 49 additions & 44 deletions test/hotspot/jtreg/compiler/c2/TestUnsignedByteCompare.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 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
Expand All @@ -23,67 +23,72 @@

/*
* @test
* @bug 8204479 8253191
* @bug 8204479
* @summary Bitwise AND on byte value sometimes produces wrong result
*
* @library /test/lib
* @modules java.base/jdk.internal.vm.annotation
*
* @run main/bootclasspath/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation compiler.c2.TestUnsignedByteCompare
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation
* -XX:-UseOnStackReplacement -XX:-BackgroundCompilation -Xcomp -XX:-Inline
* compiler.c2.TestUnsignedByteCompare
*/
package compiler.c2;

import java.lang.invoke.*;
import jdk.internal.vm.annotation.DontInline;
import jdk.test.lib.Asserts;
package compiler.c2;

public class TestUnsignedByteCompare {

@DontInline static boolean testByteGT0(byte[] val) { return (val[0] & mask()) > 0; }
@DontInline static boolean testByteGE0(byte[] val) { return (val[0] & mask()) >= 0; }
@DontInline static boolean testByteEQ0(byte[] val) { return (val[0] & mask()) == 0; }
@DontInline static boolean testByteNE0(byte[] val) { return (val[0] & mask()) != 0; }
@DontInline static boolean testByteLE0(byte[] val) { return (val[0] & mask()) <= 0; }
@DontInline static boolean testByteLT0(byte[] val) { return (val[0] & mask()) < 0; }
static int p, n;

static void testValue(byte b) {
byte[] bs = new byte[] { b };
Asserts.assertEquals(((b & mask()) > 0), testByteGT0(bs), errorMessage(b, "GT0"));
Asserts.assertEquals(((b & mask()) >= 0), testByteGE0(bs), errorMessage(b, "GE0"));
Asserts.assertEquals(((b & mask()) == 0), testByteEQ0(bs), errorMessage(b, "EQ0"));
Asserts.assertEquals(((b & mask()) != 0), testByteNE0(bs), errorMessage(b, "NE0"));
Asserts.assertEquals(((b & mask()) <= 0), testByteLE0(bs), errorMessage(b, "LE0"));
Asserts.assertEquals(((b & mask()) < 0), testByteLT0(bs), errorMessage(b, "LT0"));
static void report(byte[] ba, int i, boolean failed) {
// Enable for debugging:
// System.out.println((failed ? "Failed" : "Passed") + " with: " + ba[i] + " at " + i);
}

public static void main(String[] args) {
for (int mask = 0; mask <= 0xFF; mask++) {
setMask(mask);
for (int i = 0; i < 20_000; i++) {
testValue((byte) i);
static void m1(byte[] ba) {
for (int i = 0; i < ba.length; i++) {
if ((ba[i] & 0xFF) < 0x10) {
p++;
report(ba, i, true);
} else {
n++;
report(ba, i, false);
}
}
System.out.println("TEST PASSED");
}

static String errorMessage(byte b, String type) {
return String.format("%s: val=0x%x mask=0x%x", type, b, mask());
static void m2(byte[] ba) {
for (int i = 0; i < ba.length; i++) {
if (((ba[i] & 0xFF) & 0x80) < 0) {
p++;
report(ba, i, true);
} else {
n++;
report(ba, i, false);
}
}
}

// Mutable mask as a compile-time constant.
static public void main(String[] args) {
final int tries = 1_000;
final int count = 1_000;

private static final CallSite MASK_CS = new MutableCallSite(MethodType.methodType(int.class));
private static final MethodHandle MASK_MH = MASK_CS.dynamicInvoker();
byte[] ba = new byte[count];

static int mask() {
try {
return (int) MASK_MH.invokeExact();
} catch (Throwable t) {
throw new InternalError(t); // should NOT happen
for (int i = 0; i < count; i++) {
int v = -(i % 126 + 1);
ba[i] = (byte)v;
}
}

static void setMask(int mask) {
MethodHandle constant = MethodHandles.constant(int.class, mask);
MASK_CS.setTarget(constant);
for (int t = 0; t < tries; t++) {
m1(ba);
if (p != 0) {
throw new IllegalStateException("m1 error: p = " + p + ", n = " + n);
}
}

for (int t = 0; t < tries; t++) {
m2(ba);
if (p != 0) {
throw new IllegalStateException("m2 error: p = " + p + ", n = " + n);
}
}
}
}
89 changes: 89 additions & 0 deletions test/hotspot/jtreg/compiler/c2/TestUnsignedByteCompare1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright (c) 2020, 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
* 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.
*/

/*
* @test
* @bug 8253191
*
* @library /test/lib
* @modules java.base/jdk.internal.vm.annotation
*
* @run main/bootclasspath/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation compiler.c2.TestUnsignedByteCompare1
*/
package compiler.c2;

import java.lang.invoke.*;
import jdk.internal.vm.annotation.DontInline;
import jdk.test.lib.Asserts;

public class TestUnsignedByteCompare1 {

@DontInline static boolean testByteGT0(byte[] val) { return (val[0] & mask()) > 0; }
@DontInline static boolean testByteGE0(byte[] val) { return (val[0] & mask()) >= 0; }
@DontInline static boolean testByteEQ0(byte[] val) { return (val[0] & mask()) == 0; }
@DontInline static boolean testByteNE0(byte[] val) { return (val[0] & mask()) != 0; }
@DontInline static boolean testByteLE0(byte[] val) { return (val[0] & mask()) <= 0; }
@DontInline static boolean testByteLT0(byte[] val) { return (val[0] & mask()) < 0; }

static void testValue(byte b) {
byte[] bs = new byte[] { b };
Asserts.assertEquals(((b & mask()) > 0), testByteGT0(bs), errorMessage(b, "GT0"));
Asserts.assertEquals(((b & mask()) >= 0), testByteGE0(bs), errorMessage(b, "GE0"));
Asserts.assertEquals(((b & mask()) == 0), testByteEQ0(bs), errorMessage(b, "EQ0"));
Asserts.assertEquals(((b & mask()) != 0), testByteNE0(bs), errorMessage(b, "NE0"));
Asserts.assertEquals(((b & mask()) <= 0), testByteLE0(bs), errorMessage(b, "LE0"));
Asserts.assertEquals(((b & mask()) < 0), testByteLT0(bs), errorMessage(b, "LT0"));
}

public static void main(String[] args) {
for (int mask = 0; mask <= 0xFF; mask++) {
setMask(mask);
for (int i = 0; i < 20_000; i++) {
testValue((byte) i);
}
}
System.out.println("TEST PASSED");
}

static String errorMessage(byte b, String type) {
return String.format("%s: val=0x%x mask=0x%x", type, b, mask());
}

// Mutable mask as a compile-time constant.

private static final CallSite MASK_CS = new MutableCallSite(MethodType.methodType(int.class));
private static final MethodHandle MASK_MH = MASK_CS.dynamicInvoker();

static int mask() {
try {
return (int) MASK_MH.invokeExact();
} catch (Throwable t) {
throw new InternalError(t); // should NOT happen
}
}

static void setMask(int mask) {
MethodHandle constant = MethodHandles.constant(int.class, mask);
MASK_CS.setTarget(constant);
}
}