Hello J.E.
You need to look at the OS implementation of the virtual memory manager.
At least, if possible...
I don't think so, look at the output of and try to reverse engineer it:
<code>
$ javap java.util.HashMap
</code>
First of all I only see an array of HashMap.Entry[] objects. I do not see
an auxiliary structure to store the the keys. It seems very unlikely that
they have a b-tree. What kind of index is the most efficient for a
specific application is very specific to well... the application. If the
collection is fixed in size, a hash index should outperform a b-tree. But
you would need to test it.
These are implementation details, therefore it is impossible to answer
the question without reference to a particular version of a particular
provider's JVM. It is unlikely that a method like the one you describe
(Reference: SunVM)
One thing that is for certain is that you can only specify the minimum and
maximum sizes of memory available to the JVM. While the JVM is a Virtual
Machine by itself, it does not have its own mechanism for swapping out
memory that is infrequently accessed. Which would be a good and easy way
to minimize the memory footprint of the JVM.
The only way to get the JVM to swap itself out to virtual memory is when
-Xmx sets the maximum size to such a high level that the OS itself will
start swapping. This is an experimental observation, and I do not have any
publications on it. If you want to test it out yourself, code something
stupid like this:
<code>
public class MemoryBlasterXP
{
static LinkedList list=new LinkedList();
public static void main(String[] args)
{
for (;
list.add(new Integer(1));
}
}
</code>
Run it with: java -Xms16M -Xmx1G MemoryBlasterXP. Note that this will only
work if the total amount of memory (RAM+swapfile) is greater that 1G. Also
note that your OS may not be able to hand such a large amount. Also note
that on Linux (Solaris too probably) the system administrator may have set
limits on the maximum amount of memory for a process. (ulimit -a to check
it out)