Skip to content

Commit

Permalink
Merge pull request #18317 from theresa-m/valuetypetests_1
Browse files Browse the repository at this point in the history
Split ValueTypeTests for lw5 and enable basic value type tests
  • Loading branch information
hangshao0 committed Oct 23, 2023
2 parents fadb895 + b4dc372 commit 50cad9e
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 2 deletions.
4 changes: 3 additions & 1 deletion runtime/vm/resolvefield.cpp
Expand Up @@ -1105,7 +1105,9 @@ fieldOffsetsFindNext(J9ROMFieldOffsetWalkState *state, J9ROMFieldShape *field)
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
J9UTF8 *fieldSig = J9ROMFIELDSHAPE_SIGNATURE(field);
U_8 *fieldSigBytes = J9UTF8_DATA(fieldSig);
if ('Q' == *fieldSigBytes) {
if (('Q' == *fieldSigBytes)
|| J9_ARE_ALL_BITS_SET(modifiers, J9FieldFlagIsNullRestricted)
) {
J9Class *fieldClass = NULL;
fieldClass = findJ9ClassInFlattenedClassCache(state->flattenedClassCache, fieldSigBytes + 1, J9UTF8_LENGTH(fieldSig) - 2);
if (!J9_IS_FIELD_FLATTENED(fieldClass, field)) {
Expand Down
3 changes: 2 additions & 1 deletion test/functional/Valhalla/build.xml
Expand Up @@ -57,11 +57,12 @@
<echo>===destdir: ${DEST}</echo>
<javac srcdir="${src}" destdir="${build}" debug="true" fork="true" executable="${compiler.javac}" encoding="ISO-8859-1">
<src path="${src}"/>
<!-- uncomment when running with the latest Valhalla compiler (currently in lw5 branch but will eventually be merged)-->
<!-- uncomment when running with the latest Valhalla compiler (currently in lw5 branch but will eventually be merged) -->
<src path="${src_qtypes}"/>
<!-- <src path="${src_lw5}"/> -->
<src path="${transformerListener}" />
<compilerarg line='--add-exports java.base/jdk.internal.misc=ALL-UNNAMED --add-exports java.base/jdk.internal.value=ALL-UNNAMED' />
<!-- Also remove this line when running lw5 -->
<compilerarg line='-source 22 -XDenablePrimitiveClasses' />
<classpath>
<pathelement location="${LIB_DIR}/testng.jar"/>
Expand Down
@@ -0,0 +1,206 @@
/*******************************************************************************
* Copyright IBM Corp. and others 2023
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] https://openjdk.org/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
*******************************************************************************/
package org.openj9.test.lworld;

import static org.testng.Assert.*;
import org.testng.annotations.Test;

/*
* Instructions to run this test:
*
* 1) Build the JDK with the '--enable-inline-types' configure flag
* 2) cd [openj9-openjdk-dir]/openj9/test
* 3) git clone https://github.com/adoptium/TKG.git
* 4) cd TKG
* 5) export TEST_JDK_HOME=[openj9-openjdk-dir]/build/linux-x86_64-server-release/images/jdk
* 6) export JDK_VERSION=Valhalla
* 7) export SPEC=linux_x86-64_cmprssptrs
* 8) export BUILD_LIST=functional/Valhalla
* 9) export AUTO_DETECT=false
* 10) export JDK_IMPL=openj9
* 11) make -f run_configure.mk && make compile && make _sanity
*/

@Test(groups = { "level.sanity" })
public class ValueTypeTests {
/* default values */
static int[] defaultPointPositions1 = {0xFFEEFFEE, 0xAABBAABB};
static int[] defaultPointPositions2 = {0xCCDDCCDD, 0x33443344};
static int[] defaultPointPositions3 = {0x43211234, 0xABCDDCBA};
static int[][] defaultLinePositions1 = {defaultPointPositions1, defaultPointPositions2};
static int[][] defaultLinePositions2 = {defaultPointPositions2, defaultPointPositions3};
static int[][] defaultLinePositions3 = {defaultPointPositions1, defaultPointPositions3};
static int[][][] defaultTrianglePositions = {defaultLinePositions1, defaultLinePositions2, defaultLinePositions3};

static value class Point2D {
int x;
int y;

public implicit Point2D();

Point2D(int x, int y) {
this.x = x;
this.y = y;
}
}

static value class Point2DComplex {
double d;
long l;

Point2DComplex(double d, long l) {
this.d = d;
this.l = l;
}
}

static value class Line2D {
Point2D st;
Point2D en;

Line2D(Point2D st, Point2D en) {
this.st = st;
this.en = en;
}
}

static value class FlattenedLine2D {
Point2D! st;
Point2D! en;

public implicit FlattenedLine2D();

FlattenedLine2D(Point2D! st, Point2D! en) {
this.st = st;
this.en = en;
}
}

static value class Triangle2D {
FlattenedLine2D! v1;
FlattenedLine2D! v2;
FlattenedLine2D! v3;

public implicit Triangle2D();

Triangle2D(FlattenedLine2D! v1, FlattenedLine2D! v2, FlattenedLine2D! v3) {
this.v1 = v1;
this.v2 = v2;
this.v3 = v3;
}

Triangle2D(int[][][] positions) {
this(new FlattenedLine2D(new Point2D(positions[0][0][0], positions[0][0][1]),
new Point2D(positions[0][1][0], positions[0][1][1])),
new FlattenedLine2D(new Point2D(positions[1][0][0], positions[1][0][1]),
new Point2D(positions[1][1][0], positions[1][1][1])),
new FlattenedLine2D(new Point2D(positions[2][0][0], positions[2][0][1]),
new Point2D(positions[2][1][0], positions[2][1][1])));
}
}

@Test(priority=1)
static public void testCreatePoint2D() throws Throwable {
int x = 0xFFEEFFEE;
int y = 0xAABBAABB;

Point2D point2D = new Point2D(x, y);

assertEquals(point2D.x, x);
assertEquals(point2D.y, y);

// TODO add putfield tests once withfield is replaced
}

@Test(priority=1)
static public void testCreatePoint2DComplex() throws Throwable {
double d = Double.MAX_VALUE;
long l = Long.MAX_VALUE;

Point2DComplex p = new Point2DComplex(d, l);

assertEquals(p.d, d);
assertEquals(p.l, l);

// TODO add putfield tests once withfield is replaced
}

@Test(priority=2)
static public void testCreateLine2D() throws Throwable {
int x = 0xFFEEFFEE;
int y = 0xAABBAABB;
int x2 = 0xCCDDCCDD;
int y2 = 0xAAFFAAFF;

Point2D st = new Point2D(x, y);
Point2D en = new Point2D(x2, y2);
Line2D line2D = new Line2D(st, en);

assertEquals(line2D.st.x, x);
assertEquals(line2D.st.y, y);
assertEquals(line2D.en.x, x2);
assertEquals(line2D.en.y, y2);

// TODO add putfield tests once withfield is replaced
}

@Test(priority=2)
static public void testCreateFlattenedLine2D() throws Throwable {
int x = 0xFFEEFFEE;
int y = 0xAABBAABB;
int x2 = 0xCCDDCCDD;
int y2 = 0xAAFFAAFF;

Point2D! st = new Point2D(x, y);
Point2D! en = new Point2D(x2, y2);
FlattenedLine2D line2D = new FlattenedLine2D(st, en);

assertEquals(line2D.st.x, x);
assertEquals(line2D.st.y, y);
assertEquals(line2D.en.x, x2);
assertEquals(line2D.en.y, y2);

// TODO add putfield tests once withfield is replaced
}

@Test(priority=3)
static public void testCreateTriangle2D() throws Throwable {
Triangle2D triangle2D = new Triangle2D(defaultTrianglePositions);
checkEqualTriangle2D(triangle2D, defaultTrianglePositions);
}

static void checkEqualPoint2D(Point2D point, int[] positions) throws Throwable {
assertEquals(point.x, positions[0]);
assertEquals(point.y, positions[1]);
}

static void checkEqualFlattenedLine2D(FlattenedLine2D line, int[][] positions) throws Throwable {
checkEqualPoint2D(line.st, positions[0]);
checkEqualPoint2D(line.en, positions[1]);
}

static void checkEqualTriangle2D(Triangle2D triangle, int[][][] positions) throws Throwable {
checkEqualFlattenedLine2D(triangle.v1, positions[0]);
checkEqualFlattenedLine2D(triangle.v2, positions[1]);
checkEqualFlattenedLine2D(triangle.v3, positions[2]);
}
}

0 comments on commit 50cad9e

Please sign in to comment.