org.jikesrvm.classloader
Class DynamicTypeCheck

java.lang.Object
  extended by org.jikesrvm.classloader.DynamicTypeCheck
All Implemented Interfaces:
TIBLayoutConstants

public class DynamicTypeCheck
extends Object
implements TIBLayoutConstants

Data structures and code for fast dynamic type checking.

As a convention, we convert all dynamic type checking operations into the following question: LHS :?= RHS (i.e. can an instance of the RHS class be stored in a variable of the LHS class or interface.) This question arises for four bytecodes: instanceof, checkcast, aastore and invokeinterface and entry into catch blocks. This gives us a uniform terminology, but in some cases (instanceof) can be somewhat counter-intuitive since despite the fact that the Java source code is written as x instanceof C, for the purposes of dynamic type checking x is the RHS and C is the LHS!

The idea of the optimizations presented below is to treat each context in which these queries arises as a special case to be optimised in isolation. Consider the following taxonomy of dynamic type checking conexts:

(1) Is the LHS unknown at compile time? True only for aastore? If so, the following test will be fast in most instances: is the runtime type of the LHS array the same as compile-time type of the variable that contains it? If so, the Java-to-bytecode compiler (and the verifier) guarantees that the test passes. Unfortunately, this test can only be used in two of three cases: when the LHS variable is a field or a parameter. When the LHS is in a local variable the Java-to-bytecode compiler has thrown away the necessary type information.

(2) Otherwise, is the LHS an array? If so, there are three sub-cases