File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How to write program that uses all memory available? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to write program that uses all memory available?" Watch "How to write program that uses all memory available?" New topic
Author

How to write program that uses all memory available?

H Melua
Ranch Hand

Joined: Jan 04, 2005
Posts: 172
Hello!

That might sound malicious! but i want to write a testing program that uses all the memory available in my computer and eventually crashes! I can make a program to report out of memory and full stop by simple infinite loops, but i want the machine to crash!

why am i doing that?

I'm testing the stack inspection feature in Java (thats for my project) and i want to see if it will be able to protect my computer against DoS attack...

now what i can do is make the program launch unlimited number of windows of very big size... but that requires permission to print something into screen... and so its not very useful! because i'm not planning to give that code any permissions to begin with!

any ideas?

This is honestly for educational purposes! and it will be tried on my machine!!

HannaH
[ July 10, 2008: Message edited by: H Melua ]
Darius Cooper
Greenhorn

Joined: Jul 10, 2008
Posts: 8
So, if I understand, you're saying that you know how to exhaust all the memory allowed to the JVM, but you want to exhaust the memory outside the JVM too? Is that right?

If so, you can't do that. Depending on the machine, you might be able to grab all the CPU though.
Rodrigo Tomita
Ranch Hand

Joined: Apr 28, 2008
Posts: 70
Hannah,

I'm not sure I got your question, but I believe the most you can do is to make your computer to run very slowly if you set the -Xmx parameter to almost all your available memory - and make your Java code to use all that memory. This will expand the memory allowed to the JVM.

The JVM doesn't allow you to set the parameter to be more than the memory your computer have, though.
H Melua
Ranch Hand

Joined: Jan 04, 2005
Posts: 172
Thanks very much for replying guys...
Originally posted by Darius Cooper:
So, if I understand, you're saying that you know how to exhaust all the memory allowed to the JVM, but you want to exhaust the memory outside the JVM too? Is that right?

If so, you can't do that. Depending on the machine, you might be able to grab all the CPU though.


Yes thats exactly what i meant...
I don't want to lose hope

Originally posted by Rodrigo Tomita:
Hannah,

I'm not sure I got your question, but I believe the most you can do is to make your computer to run very slowly if you set the -Xmx parameter to almost all your available memory - and make your Java code to use all that memory. This will expand the memory allowed to the JVM.

The JVM doesn't allow you to set the parameter to be more than the memory your computer have, though.


But in that case, the JVM will simply half the program, and that will be the end of it! It wouldnt crash the machine would it?
I want it as Darius said, to use the memory outside the JVM and leave windows to deal with it (which often cant deal with things properly!!)

What i want to do is perform a Denial of Service attack on my machine... (my computer in this case is acting as a server with a compute engine...)... i want to supply it with a task that uses all its memory and stop my server (machine) from running...

Is that at all possible?
Thanks again
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
People have written such C programs in the past - you just keep calling malloc until it fails, a very simple procedure*. However, as was mentioned above, you can't really do this on Java, which I think is the whole point of the exercise for you?


* On Linux you would also need to fill that memory since it uses overcommit accounting as standard, where the kernel only panics when it's actually short of memory, not just allocated too much. You could also use calloc rather than malloc to dodge this.


Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
H Melua
Ranch Hand

Joined: Jan 04, 2005
Posts: 172
Originally posted by Charles Lyons:
People have written such C programs in the past - you just keep calling malloc until it fails, a very simple procedure*. However, as was mentioned above, you can't really do this on Java, which I think is the whole point of the exercise for you?

* On Linux you would also need to fill that memory since it uses overcommit accounting as standard, where the kernel only panics when it's actually short of memory, not just allocated too much. You could also use calloc rather than malloc to dodge this.


oh don't i just love Java
I guess i'll have to give up

Thanks to you too
Rodrigo Tomita
Ranch Hand

Joined: Apr 28, 2008
Posts: 70
Originally posted by H Melua:

But in that case, the JVM will simply half the program, and that will be the end of it! It wouldnt crash the machine would it?


No, I don't think it would really crash the machine... it would only make the machine run slowly if you catch the out of memory error and keep your code running in a loop.

As Charles mentioned, I think you will get more luck with C/C++.
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
oh don't i just love Java. I guess i'll have to give up
On the flip side though, I hope you appreciate how the JVM can protect you against such problems?! One of the key advantages of Java over C++ is that it handles memory leaks much better and while the application might crash (rare with the garbage collection - you really have to try for this), it won't bring the entire computer down with it! That, and you don't need to recompile on every platform
H Melua
Ranch Hand

Joined: Jan 04, 2005
Posts: 172
Originally posted by Charles Lyons:
On the flip side though, I hope you appreciate how the JVM can protect you against such problems?! One of the key advantages of Java over C++ is that it handles memory leaks much better and while the application might crash (rare with the garbage collection - you really have to try for this), it won't bring the entire computer down with it! That, and you don't need to recompile on every platform


I certainly do and i love it for that..

I'm studying MSc in secure programming, and i only realised how lucky i was for studying Java in my undergrad (comp. science) when i saw how much safety java offers over C++(if only programmers know how to program!!)

right now I'm critically analysing the new AccessController.checkPermission() algorithm, unfortunately it is really hard, i wonder how programmers make use if it (if they do!!)
[ July 10, 2008: Message edited by: H Melua ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to write program that uses all memory available?
 
Similar Threads
Garbage collection?
How to check an application running
class question
Best Practice: Where to put database in Web Application (Tomcat as one example)?
Send video to PDA