The Artima Developer Community
Sponsored Link

Chapter 8 of Inside the Java Virtual Machine
The Linking Model
by Bill Venners

<<  Page 7 of 20  >>

Advertisement

Resolution of CONSTANT_Methodref_info Entries

To resolve a constant pool entry of type CONSTANT_Methodref_info, the virtual machine must first resolve the CONSTANT_Class_info entry specified in the class_index item. Therefore, any error that can be thrown because of the resolution of a CONSTANT_Class_info can be thrown during the resolution of a CONSTANT_Methodref_info. If the resolution of the CONSTANT_Class_info entry succeeds, the virtual machine searches for the indicated method in the type and its supertypes. If it finds the indicated method, the virtual machine checks to make sure the current class has permission to access the method.

If resolution to the CONSTANT_Class_info completes successfully, the virtual machine performs method resolution using these steps:

  1. If the resolved type is an interface, not a class, the virtual machine throws IncompatibleClassChangeError.
  2. Otherwise, the resolved type is a class. The virtual machine checks the referenced class for a method of the specified name and descriptor. If the virtual machine discovers such a method, that method is the result of the successful method lookup.
  3. Otherwise, if the class has a direct superclass, the virtual machine checks the class's direct superclass, and recursively all the superclasses of the class, for a method of the specified name and descriptor. If the virtual machine discovers such a method, that method is the result of the successful method lookup.
  4. Otherwise, the virtual machine checks any interfaces directly implemented by the class, and recursively, any superinterfaces of interfaces directly implemented by the type, for a method of the specified name and descriptor. If the virtual machine discovers such a method, that method is the result of the successful method lookup.
  5. Otherwise, method lookup fails.

If the virtual machine discovers there is no method with the proper name, return type, and number and types of parameters in the referenced class or any of its supertypes (if method lookup fails), the virtual machine throws NoSuchMethodError. Otherwise, if the method exists, but the method is abstract, the virtual machine throws AbstractMethodError. Otherwise, if the method exists, but the current class doesn't have permission to access the method, the virtual machine throws IllegalAccessError.

Otherwise, the virtual machine marks the entry as resolved and places a direct reference to the method in the data for the constant pool entry.

<<  Page 7 of 20  >>


Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use