Skip to content

Commit 89242ee

Browse files
author
Igor Veresov
committed
8356885: Don't emit C1 profiling for casts if TypeProfileCasts is off
Reviewed-by: vlivanov, kvn
1 parent e149bd3 commit 89242ee

File tree

2 files changed

+90
-3
lines changed

2 files changed

+90
-3
lines changed

src/hotspot/share/c1/c1_LIR.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,7 @@ void LIR_List::checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass,
14441444
ciMethod* profiled_method, int profiled_bci) {
14451445
LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_checkcast, result, object, klass,
14461446
tmp1, tmp2, tmp3, fast_check, info_for_exception, info_for_patch, stub);
1447-
if (profiled_method != nullptr) {
1447+
if (profiled_method != nullptr && TypeProfileCasts) {
14481448
c->set_profiled_method(profiled_method);
14491449
c->set_profiled_bci(profiled_bci);
14501450
c->set_should_profile(true);
@@ -1454,7 +1454,7 @@ void LIR_List::checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass,
14541454

14551455
void LIR_List::instanceof(LIR_Opr result, LIR_Opr object, ciKlass* klass, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check, CodeEmitInfo* info_for_patch, ciMethod* profiled_method, int profiled_bci) {
14561456
LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_instanceof, result, object, klass, tmp1, tmp2, tmp3, fast_check, nullptr, info_for_patch, nullptr);
1457-
if (profiled_method != nullptr) {
1457+
if (profiled_method != nullptr && TypeProfileCasts) {
14581458
c->set_profiled_method(profiled_method);
14591459
c->set_profiled_bci(profiled_bci);
14601460
c->set_should_profile(true);
@@ -1466,7 +1466,7 @@ void LIR_List::instanceof(LIR_Opr result, LIR_Opr object, ciKlass* klass, LIR_Op
14661466
void LIR_List::store_check(LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3,
14671467
CodeEmitInfo* info_for_exception, ciMethod* profiled_method, int profiled_bci) {
14681468
LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_store_check, object, array, tmp1, tmp2, tmp3, info_for_exception);
1469-
if (profiled_method != nullptr) {
1469+
if (profiled_method != nullptr && TypeProfileCasts) {
14701470
c->set_profiled_method(profiled_method);
14711471
c->set_profiled_bci(profiled_bci);
14721472
c->set_should_profile(true);
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/**
25+
* @test TypeProfileCasts
26+
* @summary Check that turning of TypeProfileCasts is tolerated
27+
* @requires vm.debug == true
28+
* @modules java.base/jdk.internal.misc
29+
* java.management
30+
*
31+
* @run main/othervm -XX:+TieredCompilation -XX:-BackgroundCompilation -XX:-TypeProfileCasts
32+
* -XX:CompileCommand=compileonly,compiler.tiered.TypeProfileCasts::test_instanceof
33+
* compiler.tiered.TypeProfileCasts
34+
* @run main/othervm -XX:+TieredCompilation -XX:-BackgroundCompilation -XX:+TypeProfileCasts
35+
* -XX:CompileCommand=compileonly,compiler.tiered.TypeProfileCasts::test_instanceof
36+
* compiler.tiered.TypeProfileCasts
37+
* @run main/othervm -XX:+TieredCompilation -XX:-BackgroundCompilation -XX:-TypeProfileCasts
38+
* -XX:CompileCommand=compileonly,compiler.tiered.TypeProfileCasts::test_checkcast
39+
* compiler.tiered.TypeProfileCasts
40+
* @run main/othervm -XX:+TieredCompilation -XX:-BackgroundCompilation -XX:+TypeProfileCasts
41+
* -XX:CompileCommand=compileonly,compiler.tiered.TypeProfileCasts::test_checkcast
42+
* compiler.tiered.TypeProfileCasts
43+
* @run main/othervm -XX:+TieredCompilation -XX:-BackgroundCompilation -XX:-TypeProfileCasts
44+
* -XX:CompileCommand=compileonly,compiler.tiered.TypeProfileCasts::test_array_store
45+
* compiler.tiered.TypeProfileCasts
46+
* @run main/othervm -XX:+TieredCompilation -XX:-BackgroundCompilation -XX:+TypeProfileCasts
47+
* -XX:CompileCommand=compileonly,compiler.tiered.TypeProfileCasts::test_array_store
48+
* compiler.tiered.TypeProfileCasts
49+
*/
50+
51+
package compiler.tiered;
52+
53+
public class TypeProfileCasts {
54+
static class Foo { }
55+
public static int sideEffect = 0;
56+
57+
private static void test_instanceof(Object o) {
58+
// instanceof
59+
if (o instanceof Foo) {
60+
sideEffect++;
61+
}
62+
}
63+
64+
private static void test_checkcast(Object o) {
65+
// checkcast
66+
Foo f = (Foo) o;
67+
68+
sideEffect++;
69+
}
70+
71+
private static void test_array_store(Object o) {
72+
// array store type check
73+
Foo[] fs = new Foo[1];
74+
Object[] os = fs;
75+
os[0] = o;
76+
77+
sideEffect++;
78+
}
79+
80+
public static void main(String... args) {
81+
for (int i = 0; i < 100_000; i++) {
82+
test_instanceof(new Foo());
83+
test_checkcast(new Foo());
84+
test_array_store(new Foo());
85+
}
86+
}
87+
}

0 commit comments

Comments
 (0)