This discussion is archived
5 Replies Latest reply: Jan 17, 2013 7:01 AM by 801926 RSS

Overlay and restrictions for CLEAR_ON_DESELECT transient?

fgrieu Newbie
Currently Being Moderated
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 m ~j~ bytes would consume about max( m ~j~ ) transient bytes, rather than sum( m ~j~ ).

Question: Is this overlay mechanism sometime implemented in the runtime? If yes, 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: What does "context" exactly 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?
http://stackoverflow.com/a/14257052/903600
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.
  • 1. Re: Overlay and restrictions for CLEAR_ON_DESELECT transient?
    801926 Explorer
    Currently Being Moderated
    If you use JCOP tools, you can easily see in the Java Card memory view overlay of COD memory. As correctly interpreted by you, all JC cards shall support it this way.
  • 2. Re: Overlay and restrictions for CLEAR_ON_DESELECT transient?
    fgrieu Newbie
    Currently Being Moderated
    Thanks lexdabear, I'm taking your answer as implying the overlay occurs in at least some cases, and how to check that in a JCOP context.

    But is that universal, and what's the rule? 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.

    Also, the second question on what "context" means in the quoted restriction remains unanswered. Of course I can try, but again I'm afraid that could vary from a runtime to another.
  • 3. Re: Overlay and restrictions for CLEAR_ON_DESELECT transient?
    801926 Explorer
    Currently Being Moderated
    fgrieu wrote:
    Thanks lexdabear, I'm taking your answer as implying the overlay occurs in at least some cases, and how to check that in a JCOP context.

    But is that universal, and what's the rule?
    That's how I interpret the spec and also implemented in the JCOP.
    I'm told something on the tune that on at least some runtime environments, the overlay occurs selectively for transients allocated from different packages.
    That's right regarding the packages. COD is allocated per package, not applet.
    But I fail to find a reference, or a precise description of such rule/mechanism.
    I read it from the extract you pasted above.
    >
    Also, the second question on what "context" means in the quoted restriction remains unanswered. Of course I can try, but again I'm afraid that could vary from a runtime to another.
    Context is here relevant in case SIO, logical channel and multiselectable are used.
  • 4. Re: Overlay and restrictions for CLEAR_ON_DESELECT transient?
    fgrieu Newbie
    Currently Being Moderated
    Many thanks, I'll take that as the best answer possible.

    But your reading skill is supernatural if you manage to get that the quoted statement implies there is overlay across packages, but not within a package.
  • 5. Re: Overlay and restrictions for CLEAR_ON_DESELECT transient?
    801926 Explorer
    Currently Being Moderated
    Well, if you read about package firewall, add the normal Java access rules within a package, you need to arrive that COD memory is package wide and not applet. Think about it from the Java Card implementer point of view.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points