John said:
Thomas G. Marshall wrote:
We had a discussion of precisely that point several weeks ago. I think
it was Chris Smith who ended up persuading me that no, #2 doesn't really
mean anything at all, because the definition of a "best effort" is
completely implementation dependant, and may even be context dependant.
My specific feelings, for the record, are that this is ultimately
meaningless to language lawyers, but presents a definite intention that
it's somewhat weasel-ish to try and get out of. Specifically, I think
to understand it you have to divide the required implementation code
into two pieces:
1. Real garbage collection code, which is used for garbage collection
whether or not the Runtime.gc() method is ever called.
2. Implementation code in the java.lang.Runtime class, including native
code. This is code that is specific to the implementation of the gc()
method, and would never be called from the remainder of the application
if Runtime.gc() were never used. This code should not have privileged
knowledge about heap layout and concurrency policies and the like.
I interpret "best effort" to be addressed to the implementor of the
Runtime.gc() method, and *not* to the implementor of the garbage
collector itself. Thus, I think it constrains the implementor of
Runtime.gc to use any available entry points to the garbage collection
module that may be defined. Presumably, most garbage collectors would
have an entry point to start garbage collection of some kind, and
Runtime.gc() would be constrained by the second sentence of the API docs
to call it if possible. Presumably, also, because a "best" effort is
specified, Runtime.gc() would be constrained to choose the entry point
and parameters to accomplish the most thorough garbage collection
possible; that is, if an entry point to the garbage collector for a full
collection is possible, then a first-generation collection doesn't
fulfill the requirement.
However, there are cases where such an entry point isn't defined in the
garbage collector implementation. Such cases might include a system
where there simply IS no deferred garbage collection work (such as a
reference counting system). In such cases, no effort would be required,
so Thomas's #1 and #2 are reconciled, and there is simultaneously a
"suggestion" being ignored, and a "best effort" being made.
The fuzzy part comes in here: who's to decide the line between JNI
implementation of the gc() method and the garbage collector itself,
especially when the code isn't the cleanest in the world? Who's to
determine what is or is not an "exposed" API? If the VM implementor
wants to avoid doing any garbage collection work at all in Runtime.gc(),
they could just declare that the garbage collector and memory allocator
are one and the same module of the application, and that their only
exposed APIs are the memory allocation APIs. Suddenly, the Runtime.gc
implementation can just claim that "our hands are tied" and do nothing.
There are even concurrency policies I could conceive of that may require
that some thread be at an allocation point to do a garbage collection.
In that case, some extra work within the garbage collector might be
required in order to make it possible to order a collection on demand.
In that case, is Runtime.gc required to do anything? What if the extra
work in the garbage collector would only take fifteen minutes? What if
it would take a month? What if it would take four days?
Unfortunately, Sun is caught here trying to write a spec that specifies
intent, without making anyt actual rules because they are afraid the
rules will rule out the next big innovation in garbage collection.
That's an inherently contradictory process, so the result is never going
to be perfect.
--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation