PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 10, 2022

[FIXED] Where is the super reference in a Java instance method's stack frame?

 July 10, 2022     java, jvm, reference, stack, super     No comments   

Issue

I read Bill Venner's excellent Inside the Java Virtual Machine book, which, in Chapter 5 explores in detail, among other things, the composition of a JVM's stack frame. (This chapter from the book also happens to be officially published here: https://www.artima.com/insidejvm/ed2/jvm8.html) Apart from this book I studied relatively much the runtime data areas of some JVM's, especially their stack and heap.

In an instance method's stack frame, the local variables section constitutes an array of words which holds the method arguments (or parameters), local variables and the "hidden" this reference.

What I'd like to know is, where is the super reference stored, as that is also always available in any non-static context (i.e. instance method body or initializer block), except in the Object class. Is it stored somewhere alongside the reference "this"? If yes, then why is it seemingly always left out from stack frame representations/overviews?


Solution

There is no "super" reference.

When you do:

super.foo()

You "seem" to be calling foo on an object called "super", but that's merely Java's syntax, and doesn't have to reflect what's happening under the hood. When this call is translated, it is translated to a invokespecial instruction, that invokes the superclass's foo method.

Compare this to a this.foo() call, which translates to a invokevirtual instruction. Unlike invokespecial, this will do dynamic dispatch, selecting the right method to call, depending on the runtime type of this.

Note that in both cases, there is a aload_0 instruction before invoking the method, loading the this reference onto the stack.



Answered By - Sweeper
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing