On 2007.11.22., at 20:40, [EMAIL PROTECTED] wrote:

> Is there a way, using Rhino, to track memory used by the interpreter?

It's not possible for multiple reasons.

- First, we'd need to track memory releases as well, but since we rely  
on Java garbage collector, we can't know when do objects become  
unreachable (short of tracking each and every one with a phantom  
reference, that is; not very feasible).

- Second, a Java program can't actually know the memory footprint of  
the objects it creates. Not without loading a native DLL that bounds  
to JVMPI or JVMTI, that is. A Java program could be using guesses by  
enumerating fields through reflection, but there's always the question  
of data layout (i.e. do data types narrower than 32 bit always consume  
32 bit as to align on word boundary?) Also, how many bytes are used to  
represent class/vtable pointer/lock/system hash code?)

- Third, the scripts can invoke methods on Java objects, and there's  
no way to know how many objects these methods create, or even to limit  
them.

What you would really need would be a JVM that implements JSR-121  
"Application Isolation API Specification" <http://jcp.org/en/jsr/detail?id=121 
 >. Alas, none implement it yet. Also, it doesn't explicitly state how  
you can limit a newly created isolate's memory, but I believe it  
should be possible through passing a "-Xmx" property in a Properties  
object passed to an Isolate constructor.

> Is there a way to push a custom obect into the Rhino scope to override
> the native object that would normally be created?

Sure. Just replace it with another object of same name in the scope  
after initStandardObjects(). JavaScript is this flexible; you can  
replace anything. You could replace them even from a script.

Attila.
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to