Skip to content
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

8271583: [lworld] primitive records can't be reference favoring #533

Show file tree
Hide file tree
Changes from all commits
File filter

Filter by extension

Filter by extension

Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -2526,7 +2526,8 @@ JCTree generateRecordMethod(JCClassDecl tree, Name name, List<VarSymbol> vars, M
staticArgsValues, bootstrapName, name, false);

VarSymbol _this = new VarSymbol(SYNTHETIC, names._this, tree.sym.type, tree.sym);
Type receiverType = tree.sym.type.isPrimitiveReferenceType() ? tree.sym.type.asValueType() : tree.sym.type;
VarSymbol _this = new VarSymbol(SYNTHETIC, names._this, receiverType, tree.sym);

JCMethodInvocation proxyCall;
if (!isEquals) {
@@ -2610,8 +2611,9 @@ JCFieldAccess makeIndyQualifier(
bootstrapName, staticArgTypes, List.nil());

MethodType indyType = msym.type.asMethodType();
Type receiverType = tree.sym.type.isPrimitiveReferenceType() ? tree.sym.type.asValueType() : tree.sym.type;
indyType = new MethodType(
isStatic ? List.nil() : indyType.argtypes.prepend(tree.sym.type),
isStatic ? List.nil() : indyType.argtypes.prepend(receiverType),
@@ -4062,6 +4062,15 @@ protected JCClassDecl recordDeclaration(JCModifiers mods, Comment dc) {
mods.flags |= Flags.RECORD;
Name name = typeName();
if ((mods.flags & Flags.PRIMITIVE_CLASS) != 0) {
if (token.kind == DOT) {
final Token pastDot = S.token(1);
if (pastDot.kind == IDENTIFIER && == names.val) {
nextToken(); nextToken(); // discard .val
mods.flags |= Flags.REFERENCE_FAVORING;

List<JCTypeParameter> typarams = typeParametersOpt();

@@ -4497,6 +4506,7 @@ protected boolean isRecordStart() {
if (token.kind == IDENTIFIER && == names.record &&
(peekToken(TokenKind.IDENTIFIER, TokenKind.LPAREN) ||
peekToken(TokenKind.IDENTIFIER, TokenKind.EOF) ||
peekToken(TokenKind.IDENTIFIER, TokenKind.DOT) ||
peekToken(TokenKind.IDENTIFIER, TokenKind.LT))) {
return true;
@@ -0,0 +1,42 @@
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* 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 if you need additional information or have any
* questions.

* @test
* @bug 8271583
* @summary [lworld] primitive records can't be reference favoring
* @run main/othervm RefFlavoredRecord
Copy link

@sadayapalam sadayapalam Aug 23, 2021

Choose a reason for hiding this comment

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

I think this test should not require XDallowWithFieldOperator and also likely "othervm" in the run tag.

And you should also be able to condense the @compile and @run into just @run ??

public primitive record RefFlavoredRecord.val(int theInteger, String theString) {
public static void main(String[] args) {
RefFlavoredRecord rec = RefFlavoredRecord.default;
if (rec != null) {
throw new AssertionError("Ref-favoring record .default should be null?");

if (! new RefFlavoredRecord(42, "Fortytwo").equals(new RefFlavoredRecord(42, "Fortytwo"))) {
throw new AssertionError("Records should be equal");