31.08.2013 Views

Dynamic Type Checking in Jalapeño - Usenix

Dynamic Type Checking in Jalapeño - Usenix

Dynamic Type Checking in Jalapeño - Usenix

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Abstract<br />

<strong>Dynamic</strong> <strong>Type</strong> <strong>Check<strong>in</strong>g</strong> <strong>in</strong> Jalape~no<br />

Bowen Alpern Anthony Cocchi David Grove<br />

IBMT.J.Watson Research Center<br />

Yorktown Heights, NY, 10598<br />

alpern@watson.ibm.com tony@watson.ibm.com groved@us.ibm.com<br />

http://www.research.ibm.com/jalapeno<br />

AJava virtual mach<strong>in</strong>e (JVM) must sometimes<br />

check whether a value of one type can<br />

be can be treated as a value of another type.<br />

The overhead for such dynamic type check<strong>in</strong>g<br />

can be a signi cant factor <strong>in</strong> the runn<strong>in</strong>g time<br />

of some Java programs. This paper presents<br />

avariety of techniques for perform<strong>in</strong>g these<br />

checks, each tailored to a particular restricted<br />

case that commonly arises <strong>in</strong> Java programs.<br />

By exploit<strong>in</strong>g compile-time <strong>in</strong>formation to select<br />

the most applicable technique to implement<br />

each dynamic type check, the run-time<br />

overhead of dynamic type check<strong>in</strong>gcanbesigni<br />

cantly reduced.<br />

This paper suggests ma<strong>in</strong>ta<strong>in</strong><strong>in</strong>g three data<br />

structures operationally close to every Java<br />

object. The most important of these is a display<br />

ofidenti ers for the superclasses of the<br />

object's class. With this array, most dynamic<br />

type checks can be performed <strong>in</strong> four <strong>in</strong>structions.<br />

It also suggests that an equality test of<br />

the run-time typeofanarray and the declared<br />

type of the variable that conta<strong>in</strong>sitcanbe<br />

an important short-circuit check for object array<br />

stores. Together these techniques result <strong>in</strong><br />

signi cant performance improvements on some<br />

benchmarks.<br />

1 Introduction<br />

A type check is the determ<strong>in</strong>ation of whether<br />

avalue of one type, hereafter the right-hand<br />

side or RHS type, can legally be assigned to<br />

avariable of a second type, hereafter the lefthand<br />

side or LHS type. If so, the RHS type<br />

is said to be a subtype of (or consistent with)<br />

the LHS type and the LHS type is said to be<br />

a supertype of the RHS type. More <strong>in</strong>formally,<br />

the types are said to match.<br />

Java [9] is a strongly-typed programm<strong>in</strong>g<br />

language. Almost all type check<strong>in</strong>g is static:<br />

done rst by aJava source-to-bytecode compiler<br />

and then veri ed by a Java virtual<br />

mach<strong>in</strong>e (JVM) when classes are loaded.<br />

However, Java's object oriented type system<br />

makes provision for some run-time type<br />

check<strong>in</strong>g. Explicitly cast<strong>in</strong>g a value of one<br />

type to another (the checkcast bytecode),<br />

or test<strong>in</strong>g whether such a cast would succeed<br />

(<strong>in</strong>stanceof), clearly requires such a<br />

check. So does stor<strong>in</strong>g an object <strong>in</strong> an array<br />

(aastore), dispatch<strong>in</strong>g a method through an<br />

<strong>in</strong>terface (<strong>in</strong>voke<strong>in</strong>terface), or catch<strong>in</strong>g an<br />

exception (athrow).<br />

While dynamic type check<strong>in</strong>g overhead is<br />

unlikely to be the dom<strong>in</strong>ant performance characteristic<br />

on manyJava programs, it is signi -<br />

cant enough on some that it is importantthat<br />

care be taken as to how such tests are computed.<br />

This paper presents techniques for exploit<strong>in</strong>g<br />

<strong>in</strong>formation available at compile time<br />

to generate e cient code sequences.<br />

The next section presents some background<br />

on Jalape~no. Section 3 <strong>in</strong>vestigates<br />

the cases (<strong>in</strong>stanceof, checkcast, and<br />

<strong>in</strong>voke<strong>in</strong>terface) where the putative type is<br />

known at compile time. Section 4 deals with<br />

the cases (aastore and catch blocks) where<br />

this type cannot be determ<strong>in</strong>ed until run time.<br />

Section 5 shows that careful implementation of<br />

dynamic type check can result <strong>in</strong> signi cant<br />

performance improvements on some benchmarks.<br />

Section 6 reviews other approaches to<br />

fast dynamic type check<strong>in</strong>g. And, section 7<br />

concludes.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!