example of excessive memory use (shootout)

L

Lew

Why is Java using 15MB here? The problem requires allocating a
negligible amount of memory:

http://shootout.alioth.debian.org/u64/benchmark.php?test=nbody〈=j...

What is meant here by "using 15MB"? Total for the JVM? Heap?
Classes plus heap?

If you're comparing to another language such as C, are you accounting
for their parts of system memory that correspond to the bytecode
interpreter, the support classes and the HotSpot compiler?

How much of the reported Java usage is to run the program itself, and
how much just to run Java?

Don't compare apples to bicycles.
 
F

fft1976

Is this a troll?

No. Can you explain why you think it might be? Is this a sensitive
topic?
(shrugs) If you want to shrink everything down
to the absolute minimum, code in machine language.

I was under the impression that JVM had a fixed memory overhead per
process, and maybe a small (2-fold or so?) overhead for the data
structures.

Some other shootout entries use less than 1MB, so the fixed overhead
should be small. (The linked entry uses very few libraries, by the
way).

The data structures needed here are perhaps 0.1KB in size. So, again,
why 15MB and not 1MB or so?

And would the memory usage go up to 150MB if the data structures were
ten times larger?
 
A

Arne Vajhøj

fft1976 said:
No. Can you explain why you think it might be? Is this a sensitive
topic?

The shootout is frequently used by trolls.
I was under the impression that JVM had a fixed memory overhead per
process, and maybe a small (2-fold or so?) overhead for the data
structures.

Some other shootout entries use less than 1MB, so the fixed overhead
should be small. (The linked entry uses very few libraries, by the
way).

The data structures needed here are perhaps 0.1KB in size. So, again,
why 15MB and not 1MB or so?

And would the memory usage go up to 150MB if the data structures were
ten times larger?

Why don't you just test yourself?

Arne
 
R

Roedy Green


A few thoughts:

public final class nbody should be public final class Nbody or NBody

Did you mean for this code to be static init?

public NBodySystem(){
bodies = new Body[]{
Body.sun(),
Body.jupiter(),
Body.saturn(),
Body.uranus(),
Body.neptune()
};

I suspect what you might have done is disappear up your own ass by
recursively using new Body.

You might just add a stack trace dump to the Body constructor and see
if the behaviour is what you expected. See
http://mindprod.com/jgloss/trace.html

--
Roedy Green Canadian Mind Products
http://mindprod.com

"Deer hunting would be fine sport, if only the deer had guns."
~ William S. Gilbert of Gilbert and Sullivan
 
L

Lew

fft1976 said:
I was under the impression that JVM had a fixed memory overhead per
process, and maybe a small (2-fold or so?) overhead for the data
structures.

That's not how it works. You haven't answered my questions upthread, though.

Java is a whole virtual computer inside the physical one. You have to have
memory for the JVM itself, for the classes that it loads, many of which are
needed no matter what programs it might run, for the various heap generations,
and for the program itself.
Some other shootout entries use less than 1MB, so the fixed overhead
should be small. (The linked entry uses very few libraries, by the
way).

Did those other entries count the memory they needed for the computer OS itself?
The data structures needed here are perhaps 0.1KB in size. So, again,
why 15MB and not 1MB or so?

Again, as I hinted upthread and am now saying outright, that 15 MB might very
well include overhead for the JVM itself. It has to load a whole bytecode
interpreter, the Hotspot compiler, various heap structures and some
fundamental classes before it can even begin to load the application.
And would the memory usage go up to 150MB if the data structures were
ten times larger?

If my guesses have any bearing on reality, and I really don't know if they do
with respect to this "shootout", then no. It'll go up to about 15.01 MB.

How about you answer the questions I asked:
What is meant here by "using 15MB"? Total for the JVM? Heap?
Classes plus heap?

Remember, don't compare apples to bicycles. I doubt very much the "shootout"
is comparing just the memory used by Java for the application; most likely
it's counting the whole overhead of loading the Java computer within the host
computer.
 
J

Joshua Cranmer

fft1976 said:
No. Can you explain why you think it might be? Is this a sensitive
topic?

Posting a complaint about memory usage using a microbenchmark that
probably has little bearing on real-world considerations.
I was under the impression that JVM had a fixed memory overhead per
process, and maybe a small (2-fold or so?) overhead for the data
structures.

It depends on many factors. There is the overhead of the VM itself, plus
the requisite set of Java classes (system loaders, object, arrays,
probably I/O as well, etc.).
Some other shootout entries use less than 1MB, so the fixed overhead
should be small. (The linked entry uses very few libraries, by the
way).

Do other entries start up their own interpreter? Probably not.
The data structures needed here are perhaps 0.1KB in size. So, again,
why 15MB and not 1MB or so?

Because there's a lot more going on then you've cared to try to think about.
And would the memory usage go up to 150MB if the data structures were
ten times larger?

Probably not. It depends on the data structures and how they scale with
size.
 
F

fft1976

It's my understanding that this is the total JVM usage at its peak.

Sorry, it looks like I misread the data on the shootout web site. No
other Java entries use significantly less than 15MB, so this one is
actually one of the slimmest there. This makes more sense.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top