Array initializer aastores missing BMAs
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Sat Jan 10 22:17:19 UTC 2015
On 10/01/15 20:46, Brian Goetz wrote:
> Good catch. The specialized *should* be ready to act on these if they
> are present, so hopefully this is a compiler-only fix.
Thanks - as you can see not all the possible paths are adequately
covered; this is very useful feedback, please keep at it!
Maurizio
>
> On 1/10/2015 12:50 PM, Peter Levart wrote:
>> Hi,
>>
>> The following:
>>
>> public class Pair<any A> {
>>
>> A[] array;
>>
>> public Pair(A v1, A v2) {
>> array = new A[]{v1, v2};
>> }
>> }
>>
>> vs.
>>
>> public class Pair<any A> {
>>
>> A[] array;
>>
>> public Pair(A v1, A v2) {
>> array = new A[2];
>> array[0] = v1;
>> array[1] = v2;
>> }
>> }
>>
>> Produces the following constructor:
>>
>> public Pair(A, A);
>> descriptor: (Ljava/lang/Object;Ljava/lang/Object;)V
>> flags: ACC_PUBLIC
>> Code:
>> stack=5, locals=3, args_size=3
>> 0: aload_0
>> 1: invokespecial #1 // Method
>> java/lang/Object."<init>":()V
>> 4: aload_0
>> 5: iconst_2
>> 6: anewarray #2 // class java/lang/Object
>> 9: dup
>> 10: iconst_0
>> 11: aload_1
>> 12: aastore
>> 13: dup
>> 14: iconst_1
>> 15: aload_2
>> 16: aastore
>> 17: putfield #3 // Field
>> array:[Ljava/lang/Object;
>> 20: return
>> LineNumberTable:
>> line 8: 0
>> line 9: 4
>> line 10: 20
>> BytecodeMapping:
>> Code_idx Signature
>> 6: [TA;
>> 11: TA;
>> 15: TA;
>> 17: LPair<TA;>;::[TA;
>> Signature: #25 // (TA;TA;)V
>>
>> vs.
>>
>> public Pair(A, A);
>> descriptor: (Ljava/lang/Object;Ljava/lang/Object;)V
>> flags: ACC_PUBLIC
>> Code:
>> stack=3, locals=3, args_size=3
>> 0: aload_0
>> 1: invokespecial #1 // Method
>> java/lang/Object."<init>":()V
>> 4: aload_0
>> 5: iconst_2
>> 6: anewarray #2 // class java/lang/Object
>> 9: putfield #3 // Field
>> array:[Ljava/lang/Object;
>> 12: aload_0
>> 13: getfield #3 // Field
>> array:[Ljava/lang/Object;
>> 16: iconst_0
>> 17: aload_1
>> 18: aastore
>> 19: aload_0
>> 20: getfield #3 // Field
>> array:[Ljava/lang/Object;
>> 23: iconst_1
>> 24: aload_2
>> 25: aastore
>> 26: return
>> LineNumberTable:
>> line 8: 0
>> line 9: 4
>> line 10: 12
>> line 11: 19
>> line 12: 26
>> BytecodeMapping:
>> Code_idx Signature
>> 6: [TA;
>> 9: LPair<TA;>;::[TA;
>> 13: LPair<TA;>;::[TA;
>> 17: TA;
>> 18: TA;
>> 20: LPair<TA;>;::[TA;
>> 24: TA;
>> 25: TA;
>> Signature: #25 // (TA;TA;)V
>>
>>
>>
>> Seems like aastore(s) at BCI(s) 12 & 16 are missing BMA(s) in the
>> variant using array initializer...
>>
>>
>> Regards, Peter
>>
>> On 01/10/2015 03:20 PM, Peter Levart wrote:
>>>
>>> On 01/09/2015 10:44 PM, brian.goetz at oracle.com wrote:
>>>> Changeset: 7a3e4270521d
>>>> Author: briangoetz
>>>> Date: 2015-01-09 16:44 -0500
>>>> URL:http://hg.openjdk.java.net/valhalla/valhalla/jdk/rev/7a3e4270521d
>>>>
>>>> Fix specializer bug reported by Peter Levart related to improper
>>>> handling of not-fully-instantiated class literals
>>>>
>>>> ! src/java.base/share/classes/valhalla/specializer/Specializer.java
>>>> ! test/valhalla/test/valhalla/specializer/GenericMethodsTest.java
>>>>
>>>
>>> Thanks, I have another one. This time I think there's a problem with
>>> array initializer in specialized code:
>>>
>>> public class Pair<any T> {
>>>
>>> T[] array;
>>>
>>> public Pair(T v1, T v2) {
>>> array = new T[]{v1, v2};
>>> System.out.println("Ok for " + getClass());
>>> }
>>>
>>> public static void main(String[] args) {
>>> new Pair<String>("aaa", "bbb");
>>> new Pair<int>(1, 2);
>>> new Pair<float>(1.1f, 2.2f);
>>> }
>>> }
>>>
>>>
>>> This is the runtime failure:
>>>
>>> Ok for class Pair
>>> Specializing Pair${0=I}; searching for Pair.class (not found)
>>> Specializing Pair${0=I}; searching for Pair.class (found)
>>> Exception in thread "main" java.lang.VerifyError: Bad type on operand
>>> stack
>>> Exception Details:
>>> Location:
>>> Pair${0=I}.<init>(II)V @11: aastore
>>> Reason:
>>> Type integer (current frame, stack[4]) is not assignable to
>>> 'java/lang/Object'
>>> Current Frame:
>>> bci: @11
>>> flags: { }
>>> locals: { 'Pair${0=I}', integer, integer }
>>> stack: { 'Pair${0=I}', '[I', '[I', integer, integer }
>>> Bytecode:
>>> 0000000: 2ab7 000d 2a05 bc0a 5903 1b53 5904 1c53
>>> 0000010: b500 0fb2 0015 bb00 1759 b700 1812 1ab6
>>> 0000020: 001e 2ab6 0022 b600 25b6 0029 b600 2fb1
>>> 0000030:
>>>
>>> at Pair.main(Pair.java:15)
>>>
>>>
>>> Regards, Peter
>>>
>>
More information about the valhalla-dev
mailing list