Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to write program that uses all memory available?

 
H Melua
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
H Melua
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic