• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Java source code for ++

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

how can i see java implementation for post increment operator ++.
Does it uses native methos for this.
 
Marshal
Posts: 76811
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Download the JVM code from the Oracle website. I think it is available under "other downlaods" or similar, but I have never tried.
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vicky Aggarwal wrote:Hi,

how can i see java implementation for post increment operator ++.
Does it uses native methos for this.



There's no specific native implementation for either the preincrement or postincrement ++ operator. The java compiler expresses them in terms of primitive load/store and add operations. This Java source:



compiles into the following bytecodes (I added the comments.) You can disassemble any classfile this way using the "javap" tool:



The real difference between the two is when we push the value of "i" onto the stack . In the postincrement case, we do it before the increment; in the preincrement case, we do it after the increment. The value we push onto the stack is the one that gets copied to "j".
 
vicky Aggarwal
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Ernest Friedman-Hill ..
it gives me a better understandability.
Just confuse on a single ponit....

2: iinc 1, 1 ; ADD 1 TO LV 1



here inc method directly increment the LV ... there is no need to store it again.
Store is require in case of assignment only???
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The "store" bytecodes copy a value from the JVM stack into a local variable, while load copies data from a variable onto the stack. Many bytecodes operate only on values from the stack, so this is a common operation. But because iinc operates directly on the local variable, there's no need to do any load or store calls specifically related to this operation.

In "foo()", note that we keep the old value of the variable on the stack at line 2; then we increment the variable directly; then we take that stored old value from the stack at line 6 and move it into the other variable.
 
And then the flying monkeys attacked. My only defense was this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic