Skip to content

Commit 770e5f3

Browse files
author
Harold Seigel
committedJun 29, 2021
8269274: [lworld] Withfield instruction fails to verify when operand stack contains LPrimitiveClass;
1 parent 4d064ba commit 770e5f3

File tree

3 files changed

+145
-11
lines changed

3 files changed

+145
-11
lines changed
 

‎src/hotspot/share/classfile/verifier.cpp

+2-10
Original file line numberDiff line numberDiff line change
@@ -2413,18 +2413,10 @@ void ClassVerifier::verify_field_instructions(RawBytecodeStream* bcs,
24132413
for (int i = n - 1; i >= 0; i--) {
24142414
current_frame->pop_stack(field_type[i], CHECK_VERIFY(this));
24152415
}
2416-
// stack_object_type and target_class_type must be the same inline type.
2417-
stack_object_type =
2418-
current_frame->pop_stack(VerificationType::inline_type_check(), CHECK_VERIFY(this));
2416+
// Check that the receiver is a subtype of the referenced class.
2417+
current_frame->pop_stack(target_class_type, CHECK_VERIFY(this));
24192418
VerificationType target_inline_type =
24202419
VerificationType::change_ref_to_inline_type(target_class_type);
2421-
if (!stack_object_type.equals(target_inline_type)) {
2422-
verify_error(ErrorContext::bad_inline_type(bci,
2423-
current_frame->stack_top_ctx(),
2424-
TypeOrigin::cp(index, target_class_type)),
2425-
"Invalid type on operand stack in withfield instruction");
2426-
return;
2427-
}
24282420
current_frame->push_stack(target_inline_type, CHECK_VERIFY(this));
24292421
break;
24302422
}

‎test/hotspot/jtreg/runtime/valhalla/inlinetypes/verifier/VerifierInlineTypes.java

+3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ public static void main(String[] args) throws Exception {
7373
// Test VerifyError is thrown if a defaultvalue's cp entry is not a class.
7474
runTestVerifyError("defValWrongCPType", "Illegal type at constant pool entry");
7575

76+
// Test that the verifier doesn't require that a withfield bytecode has a Q type operand.
77+
Class newClass = Class.forName("withfieldL");
78+
7679
/*
7780
// Test that a withfield opcode with an out of bounds cp index causes a VerifyError.
7881
runTestVerifyError("wthFldBadCP", "Illegal constant pool index");

‎test/hotspot/jtreg/runtime/valhalla/inlinetypes/verifier/verifierTests.jcod

+140-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1632,3 +1632,142 @@ class withfieldObj {
16321632
} // end ValueTypes
16331633
} // Attributes
16341634
} // end class withfieldObj
1635+
1636+
1637+
// This class has a withfield opcode with a non-Q type operand.
1638+
class withfieldL {
1639+
0xCAFEBABE;
1640+
0; // minor version
1641+
62; // version
1642+
[28] { // Constant Pool
1643+
; // first element is empty
1644+
class #2; // #1 at 0x0A
1645+
Utf8 "withfieldL"; // #2 at 0x0D
1646+
class #2; // #3 at 0x17
1647+
Field #1 #5; // #4 at 0x1A
1648+
NameAndType #6 #7; // #5 at 0x1F
1649+
Utf8 "x"; // #6 at 0x24
1650+
Utf8 "I"; // #7 at 0x28
1651+
Field #1 #9; // #8 at 0x2C
1652+
NameAndType #10 #7; // #9 at 0x31
1653+
Utf8 "y"; // #10 at 0x36
1654+
class #12; // #11 at 0x3A
1655+
Utf8 "QwithfieldL;"; // #12 at 0x3D
1656+
class #14; // #13 at 0x49
1657+
Utf8 "java/lang/Object"; // #14 at 0x4C
1658+
Utf8 "makePoint"; // #15 at 0x5F
1659+
Utf8 "(II)QwithfieldL;"; // #16 at 0x6B
1660+
Utf8 "Code"; // #17 at 0x7B
1661+
Utf8 "LineNumberTable"; // #18 at 0x82
1662+
Utf8 "<init>"; // #19 at 0x94
1663+
Utf8 "()QwithfieldL;"; // #20 at 0x9D
1664+
Utf8 "SourceFile"; // #21 at 0xAB
1665+
Utf8 "X.java"; // #22 at 0xB8
1666+
Utf8 "NestHost"; // #23 at 0xC1
1667+
class #25; // #24 at 0xCC
1668+
Utf8 "X"; // #25 at 0xCF
1669+
Utf8 "InnerClasses"; // #26 at 0xD3
1670+
Utf8 "Point"; // #27 at 0xE2
1671+
} // Constant Pool
1672+
1673+
0x0130; // access [ ACC_SUPER ACC_FINAL ]
1674+
#1;// this_cpx
1675+
#13;// super_cpx
1676+
1677+
[0] { // Interfaces
1678+
} // Interfaces
1679+
1680+
[2] { // Fields
1681+
{ // field at 0xF4
1682+
0x0010; // access
1683+
#6; // name_index : x
1684+
#7; // descriptor_index : I
1685+
[0] { // Attributes
1686+
} // Attributes
1687+
}
1688+
;
1689+
{ // field at 0xFC
1690+
0x0010; // access
1691+
#10; // name_index : y
1692+
#7; // descriptor_index : I
1693+
[0] { // Attributes
1694+
} // Attributes
1695+
}
1696+
} // Fields
1697+
1698+
[2] { // Methods
1699+
{ // method at 0x0106
1700+
0x0008; // access
1701+
#15; // name_index : makePoint
1702+
#16; // descriptor_index : (II)QwithfieldL;
1703+
[1] { // Attributes
1704+
Attr(#17, 62) { // Code at 0x010E
1705+
2; // max_stack
1706+
3; // max_locals
1707+
Bytes[26]{
1708+
0xCB0001C000034D1A;
1709+
0x2C5FCC00044D1B2C;
1710+
0x5FCC00084D2CC000;
1711+
0x0BB0;
1712+
}
1713+
[0] { // Traps
1714+
} // end Traps
1715+
[1] { // Attributes
1716+
Attr(#18, 18) { // LineNumberTable at 0x013A
1717+
[4] { // line_number_table
1718+
0 4; // at 0x0146
1719+
7 5; // at 0x014A
1720+
14 6; // at 0x014E
1721+
21 7; // at 0x0152
1722+
}
1723+
} // end LineNumberTable
1724+
} // Attributes
1725+
} // end Code
1726+
} // Attributes
1727+
}
1728+
;
1729+
{ // method at 0x0152
1730+
0x000A; // access
1731+
#19; // name_index : <init>
1732+
#20; // descriptor_index : ()QwithfieldL;
1733+
[1] { // Attributes
1734+
Attr(#17, 55) { // Code at 0x015A
1735+
2; // max_stack
1736+
1; // max_locals
1737+
Bytes[23]{
1738+
0xCB00014B032A5FCC;
1739+
0x0008594BB400082A;
1740+
0x5FCC00044B2AB0;
1741+
}
1742+
[0] { // Traps
1743+
} // end Traps
1744+
[1] { // Attributes
1745+
Attr(#18, 14) { // LineNumberTable at 0x0183
1746+
[3] { // line_number_table
1747+
0 9; // at 0x018F
1748+
4 10; // at 0x0193
1749+
21 11; // at 0x0197
1750+
}
1751+
} // end LineNumberTable
1752+
} // Attributes
1753+
} // end Code
1754+
} // Attributes
1755+
}
1756+
} // Methods
1757+
1758+
[3] { // Attributes
1759+
Attr(#21, 2) { // SourceFile at 0x0199
1760+
#22;
1761+
} // end SourceFile
1762+
;
1763+
Attr(#23, 2) { // NestHost at 0x01A1
1764+
#24; // X at 0x01A9
1765+
} // end NestHost
1766+
;
1767+
Attr(#26, 10) { // InnerClasses at 0x01A9
1768+
[1] { // classes
1769+
#1 #24 #27 280; // at 0x01B9
1770+
}
1771+
} // end InnerClasses
1772+
} // Attributes
1773+
} // end class withfieldL

0 commit comments

Comments
 (0)
Please sign in to comment.