In Java Card (I'm interested in Classic downto 2.1.1), transient (RAM) needed by an applet is typically allocated on install by makeTransientByteArray()
. That method accepts a parameter CLEAR_ON_RESET
or CLEAR_ON_DESELECT
. The later comes with warning that
CLEAR_ON_DESELECT
transient objects can be accessed only when the applet which created the object is in the same context as the currently selected applet.The Java Card runtime environment will throw a SecurityException if a
CLEAR_ON_DESELECT
transient object is accessed when the currently selected applet is not in the same context as the applet which created the object.
My reading is that CLEAR_ON_DESELECT
(but not CLEAR_ON_RESET
) would allow the runtime to overlay the transients (allocated on install as stated above) between two applets, as long as they are not simultaneously selected, so that several applets allocating mj bytes would consume about max(mj) transient bytes, rather than sum(mj).
Update: I'm told something on the tune that on at least some runtime environments, the overlay occurs selectively for transients allocated from different packages. But I fail to find a reference, or a precise description of such rule/mechanism.
Question: Is this overlay mechanism sometime implemented in the runtime? If yes, when does it occurs? And are there cards with a runtime not implementing it? If yes, is there a way to tell other than by experiment, maybe from the version of Java Card advertised?
Other question: Precisely what does "context" mean in the quoted restriction? In particular, is a CLEAR_ON_DESELECT
transient usable by another instance of the applet, sharing it with the instance that allocated by the mechanism shown here? Note: I'm not interested in sharing the content of the transient, only in avoiding two allocations, to workaround a possible lack of overlay by the runtime.
Update: I asked the same question here and got an interesting answer.