Skip to content
Permalink
Browse files
8275825: [lworld] Unnecessary buffering because trivial accessor meth…
…ods are not C2 compiled
  • Loading branch information
TobiHartmann committed Oct 26, 2021
1 parent e7ddeb2 commit 9c886f310d94a66c3bc481a6484ecee4b8274e65
@@ -870,6 +870,11 @@ bool Method::is_getter() const {
default:
return false;
}
if (InlineTypeReturnedAsFields && result_type() == T_INLINE_TYPE) {
// Don't treat this as (trivial) getter method because the
// inline type should be returned in a scalarized form.
return false;
}
return true;
}

@@ -891,6 +896,11 @@ bool Method::is_setter() const {
}
if (java_code_at(2) != Bytecodes::_putfield) return false;
if (java_code_at(5) != Bytecodes::_return) return false;
if (has_scalarized_args()) {
// Don't treat this as (trivial) setter method because the
// inline type argument should be passed in a scalarized form.
return false;
}
return true;
}

@@ -887,7 +887,7 @@ class Method : public Metadata {
_flags = x ? (_flags | _reserved_stack_access) : (_flags & ~_reserved_stack_access);
}

bool has_scalarized_args() {
bool has_scalarized_args() const {
return (_flags & _scalarized_args) != 0;
}

@@ -924,23 +924,16 @@ void ThreadSafepointState::handle_polling_page_exception() {

GrowableArray<Handle> return_values;
InlineKlass* vk = NULL;

if (return_oop && InlineTypeReturnedAsFields) {
SignatureStream ss(method->signature());
while (!ss.at_return_type()) {
ss.next();
}
if (ss.type() == T_INLINE_TYPE) {
// Check if inline type is returned as fields
vk = InlineKlass::returned_inline_klass(map);
if (vk != NULL) {
// We're at a safepoint at the return of a method that returns
// multiple values. We must make sure we preserve the oop values
// across the safepoint.
assert(vk == method->returned_inline_type(thread()), "bad inline klass");
vk->save_oop_fields(map, return_values);
return_oop = false;
}
if (return_oop && InlineTypeReturnedAsFields && method->result_type() == T_INLINE_TYPE) {
// Check if inline type is returned as fields
vk = InlineKlass::returned_inline_klass(map);
if (vk != NULL) {
// We're at a safepoint at the return of a method that returns
// multiple values. We must make sure we preserve the oop values
// across the safepoint.
assert(vk == method->returned_inline_type(thread()), "bad inline klass");
vk->save_oop_fields(map, return_values);
return_oop = false;
}
}

@@ -2553,14 +2553,10 @@ class AdapterFingerPrint : public CHeapObj<mtCode> {
} else {
st.print("L");
}
}
switch (v) {
case T_INT: st.print("I"); break;
case T_LONG: long_prev = true; break;
case T_FLOAT: st.print("F"); break;
case T_DOUBLE: st.print("D"); break;
case T_VOID: break;
default: ShouldNotReachHere();
} else if (v == T_LONG) {
long_prev = true;
} else if (v != T_VOID){
st.print("%c", type2char((BasicType)v));
}
}
}
@@ -25,7 +25,7 @@
* @test
* @key randomness
* @summary Test inline type calling convention with compiled to compiled calls.
* @library /test/lib /test/lib /compiler/whitebox /
* @library /test/lib /compiler/whitebox /
* @compile TestC2CCalls.java
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
@@ -0,0 +1,104 @@
/*
* Copyright (c) 2021, 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 8275825
* @summary Verify that trivial accessor methods operating on an inline type
* field are C2 compiled to enable scalarization of the arg/return value.
* @requires vm.compiler2.enabled
* @library /test/lib /compiler/whitebox /
* @compile TestTrivialMethods.java
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbatch
* -XX:+InlineTypePassFieldsAsArgs -XX:+InlineTypeReturnedAsFields
* -XX:CompileCommand=dontinline,*::getter* -XX:CompileCommand=dontinline,*::setter*
* compiler.valhalla.inlinetypes.TestTrivialMethods
*/

package compiler.valhalla.inlinetypes;

import compiler.whitebox.CompilerWhiteBoxTest;

import java.lang.reflect.Method;

import jdk.test.lib.Asserts;
import jdk.test.lib.Utils;

import sun.hotspot.WhiteBox;

public class TestTrivialMethods {
public static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();

static MyValue3 staticField = MyValue3.create();
MyValue3 field = MyValue3.create();

public MyValue3 getter1() {
return staticField;
}

public static MyValue3 getter2() {
return staticField;
}

public MyValue3 getter3() {
return field;
}

public void setter1(MyValue3 val) {
staticField = val;
}

public static void setter2(MyValue3 val) {
staticField = val;
}

public void setter3(MyValue3 val) {
field = val;
}

public static void main(String[] args) throws Exception {
TestTrivialMethods t = new TestTrivialMethods();
// Warmup to trigger compilation
for (int i = 0; i < 100_000; ++i) {
t.getter1();
t.getter2();
t.getter3();
t.setter1(staticField);
t.setter2(staticField);
t.setter3(staticField);
}
Method m = TestTrivialMethods.class.getMethod("getter1");
Asserts.assertEQ(WHITE_BOX.getMethodCompilationLevel(m, false), CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION, "getter1 is not C2 compiled");
m = TestTrivialMethods.class.getMethod("getter2");
Asserts.assertEQ(WHITE_BOX.getMethodCompilationLevel(m, false), CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION, "getter2 is not C2 compiled");
m = TestTrivialMethods.class.getMethod("getter3");
Asserts.assertEQ(WHITE_BOX.getMethodCompilationLevel(m, false), CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION, "getter3 is not C2 compiled");
m = TestTrivialMethods.class.getMethod("setter1", MyValue3.class.asValueType());
Asserts.assertEQ(WHITE_BOX.getMethodCompilationLevel(m, false), CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION, "setter1 is not C2 compiled");
m = TestTrivialMethods.class.getMethod("setter2", MyValue3.class.asValueType());
Asserts.assertEQ(WHITE_BOX.getMethodCompilationLevel(m, false), CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION, "setter2 is not C2 compiled");
m = TestTrivialMethods.class.getMethod("setter3", MyValue3.class.asValueType());
Asserts.assertEQ(WHITE_BOX.getMethodCompilationLevel(m, false), CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION, "setter3 is not C2 compiled");
}
}

0 comments on commit 9c886f3

Please sign in to comment.