experiences with prototype
Peter Levart
peter.levart at gmail.com
Tue Feb 3 21:05:14 UTC 2015
Hi Maurizio,
I see. I thought this could be a nice idiom for boxing, since the following:
(Object) 42
...is legal and results in an Integer object at runtime.
But I don't know if a checkcast is actually inserted for (Object). Could
javac redundantly do it in case casting to Object is from expression of
<any> type and also equip checkcast with BMA indicating the type of
expression so that specialization could replace it with boxing code?
Regards, Peter
On 02/03/2015 08:09 PM, Maurizio Cimadamore wrote:
>
> On 03/02/15 18:46, Maurizio Cimadamore wrote:
>> I will also investigate on the crash you are getting...
> Hi Peter,
> the crash is coming from this code in AbstractCollection (see code in
> bold):
>
> public boolean contains(Object o) {
> __WhereVal(E) {
> Iterator<E> it = iterator();
> if (o == null) {
> return false;
> } else {
> while (it.hasNext())
> *if (o.equals((Object) it.next()))*
> return true;
> }
> return false;
> }
> __WhereRef(E) {
> Iterator<E> it = iterator();
> if (o == null) {
> while (it.hasNext())
> if (it.next() == null)
> return true;
> } else {
> while (it.hasNext())
> if (o.equals(it.next()))
> return true;
> }
> return false;
> }
> }
>
> I believe that, apart from the obvious javac bug, the code has an
> issue, as it.next() is supposed to return a value there, but you are
> casting to Object?
>
> For the records - a simpler test case for the bug is this:
>
> class Foo<any E> {
> E e;
> E get() { return e; }
>
> void test() {
> __WhereVal(E) {
> Object o = (Object)get();
> }
> }
> }
>
> Maurizio
More information about the valhalla-dev
mailing list