• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Multi Pass Compiler

 
Ranch Hand
Posts: 129
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to know more about Java multi passes compiler:

How many passes are there a java compiler has? which are those?
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ramnna jain wrote:How many passes are there a java compiler has?


That would most likely vary depending on the specific compiler you are using. I would say "at least one" is a pretty safe bet, but beyond that...who knows?

and more importantly, who cares?

If you want to write you own compiler, then a better question would be "Why are some multi-pass and some not?"
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At least two passes, definitely. Since you don't have to declare variables at the top of scope blocks, Java needs one pass to build a symbol table, and another pass to build an abstract syntax tree.

Other than the actual number of passes may depend on the compiler, as Fred already pointed out. I don't see why any compilers would need more than two passes though.
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:I don't see why any compilers would need more than two passes though.


Maybe the writer of the compiler got paid by the line?

It has been 15 years since I had my compilers class, and quite frankly, I stopped paying a lot of attention once I got a job. The only reason I was taking classes was to improve my chances of getting hired.

Even though I never turned in a complete, final project, I still got a 'B'.
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never finished my compilers class :P
 
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think historically, multiple passes were often performed because machines didn't have as much memory available as they do now, and it was expedient to break the task of compilation into smaller sub-tasks that required less total memory per task. Nowadays that's usually not an issue. But optimizing compilers may make multiple passes; after each optimization, the new code may be worth another pass to see what additional optimizations have been opened up.
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think that's quite right Mike. Multi-pass compilers need more memory, because for each task they perform, they add more "decorations" to the abstract syntax tree, which is always in memory. Everything needs to be in memory because optimizations may be done at a later stage. With one-pass compilation, the compiler immediately emits the final target code, and forgets about it as it moves on to the next piece of code.

One-pass compilers were popular because they were simple and fast, and didn't require much memory. Now it's all about multi-pass because memory and speed aren't problems anymore, and they allow for more expressive languages (compare having to declare variables at the top of your function/program to declaring them at the point you need them).
 
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stephan is correct, The only way the compiler can resolve references finally is via two(or more) passes.

Anyway, why bother with this thread. It compiles, it runs.

FYI, I also in university had a compiler class. Aced it and finished top of class, so there!

WP
 
Mike Simmons
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:I don't think that's quite right Mike. Multi-pass compilers need more memory, because for each task they perform, they add more "decorations" to the abstract syntax tree, which is always in memory. Everything needs to be in memory because optimizations may be done at a later stage.


I did say "historically" at the beginning of that comment. There was a time when they simply couldn't keep everything in memory for a single pass, so they wrote intermediate results to file or tape (!!!). For example, Algol 60, described here on p. 48:

Pass 1 would input a Cobol program from punched cards, perform a partial compilation and output intermediate code on one of the scratch tapes. Pass 2 would then input the intermediate code from tape, perform another partial compilation, and output slightly more detailed code on the other scratch tape, and so on. In this way, the compiler passes would be loaded, one at a time, from the system tape, while the compiled code would move back and forth between the scratch tapes, being gradually refined. The last pass would leave final code on a scratch tape, from which it could be loaded and executed. Since every pass performed a single scan of the original Cobol program (or the intermediate code), this scheme was known as multipass compilation. Multipass compilation made it possible to use a compiler that was much larger than the available core memory.

 
ramnna jain
Ranch Hand
Posts: 129
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IntelDoc

I found this document and now reading it.
But above discussion does not answer my exact question.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, if you really have to have an answer to that question, then I suggest you search for a Java compiler on line. I'm pretty sure that you should find one. Then download the code and your answer will be there.
 
reply
    Bookmark Topic Watch Topic
  • New Topic