• 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

where the code is stored is it in RAM or CPU register

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have a doubt about where the program code and stack and heap are placed?
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

As far as my knowledge of electronics goes, the cpu registers can only perform basic IO operations and Logical manipulations to the bytes they recieve.
They are also limited in number and the number can never be more than 20 (unless Intel signs a new Agreement with others to increase the amount).

So, i think JVM does all its stuff in RAM.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Rohit pointed out, CPU registers are meant for manipulating data, so they will hold data, not instructions. But between RAM and CPU registers you'll find several layers of cache, and that's used for both data and instructions.

Of course, with a process like the JVM it gets more complicated, because part of what the JVM does is to interpret bytecode instructions. So as far as the JVM is concerned, bytecode is data, even though it conceptually is code. But what I said above is still true for native code.

Rest assured that none of this is part of the SCJP, though. I'll move the discussion to a more appropriate forum.
[ February 06, 2008: Message edited by: Ulf Dittmer ]
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would say In general it's stored in RAM and cache.

The registers in your computer are only for temporary storage, a whole program wouldn't fit in them.

When you create a variable, say:

int x=2;

This reserves some space in memory(4 Bytes) and places the value 2 in it.

Now later when you use x like so:

x = x+ 1;

The value of x is retrieved from memory, and placed into a CPU register. Another register is given the value 1. Then an add operation is performed and the result value is stored in yet another register. Finally, this result value is moved back into the memory space reserved for X.


Cache is used to speed all this up, RAM is big and somewhat slow, where cache is small and fast(and expensive). When memory is used often, it is copied into the cache for fast access. When the program uses that memory, the cache is checked for it first. If it is found it is used(cache hit), if it is not, then it is brought into the cache(for future uses) and used.

At least thats the way I always understood it. I haven't programmed Assembly in about 2 years now though so I am a bit rusty...

If you really want to understand whats going on inside your computer with memory and registers, I recommend programming some Assembly. It is a bit tricky, but there is no better way to grasp this stuff in my opinion.
 
Rohit Garg
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I would also add that the jvm executable what we call 'java' cannot deal with the cache memory. It is only the job of OS installed in your system to load a specific program and execute it.

'Java' can only use the space provided by the OS as memory but cannot control the memory as yet. If it were possible then we could have an OS written completely in JAVA running on our systems. Thus i would say that there is no surity where the java code currently is i.e in RAM or in CACHE.

This context i recalled from the famous book of operating systems 'Galvin'.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rohit Garg:
I would also add that the jvm executable what we call 'java' cannot deal with the cache memory. It is only the job of OS installed in your system to load a specific program and execute it.


You need to be careful to distinguish between code in the sense of native executables (like java.exe) and code in the sense of Java bytecode (and we don't know which one the OP was asking about). All code and data can be in RAM and/or cache, so that's not saying much. But Java bytecode can very well also be in CPU registers (see my previous post).

'Java' can only use the space provided by the OS as memory but cannot control the memory as yet. If it were possible then we could have an OS written completely in JAVA running on our systems.


Not quite. There are other obstacles to writing an OS in Java besides controlling memory, e.g. the need for a bytecode interpreter/compiler, and the lack of APIs for interfacing with the many pieces of hardware an OS needs to deal with.

Thus i would say that there is no surity where the java code currently is i.e in RAM or in CACHE.


No executable can easily tell where its code resides. That's a good thing, too, because that way the OS can move it around between disk, RAM and cache as it pleases.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic