Mon, 02 Jul 2001 12:58:44 +0200
From:
Igor Bukanov <igor@icesoft.no>
Organization:
Wind River
To:
Norris Boyd <nboyd@atg.com>
Hi, Norris!
It turned out that in our browser implementation we need to be able to
abort too-long-running scripts. I implemented that for interpreter mode
via instruction counter callback. This callback is called at branch
points after instruction counter reach certain threshold as you
suggested once in mozilla-jseng mail list. The attached patch adds to
Context.java:
public int getInstructionObserverThreshold() {
return instructionThreshold;
}
public void setInstructionObserverThreshold(int threshold) {
instructionThreshold = threshold;
}
protected void observeInstructionCount(int instructionCount) {}
...
int instructionCount;
int instructionThreshold;
where observeInstructionCount is a callback that should be overwritten
in a custom Context to observe execution.
Then as long as instructionThreshold is not 0 modifications to
Interpreter.java increase instructionCount at branches/function
calls/catch blocks and call cx.observeInstructionCount when it reaches
instructionThreshold. I also replaces 3 catch statements in
Interpreter.interpret for EcmaError, JavaScriptException and
RuntimeException by single one to reduce code duplication.
The patch lacks documentation in Context.java but I would add that later
if the patch is ok.
Regards, Igor
==========================
Subject:
Re: Working for Rhino
Date:
Tue, 3 Jul 2001 10:41:42 +0200
From:
felix.meschberger@day.com
To:
Norris Boyd <nboyd@atg.com>
Hi Norris,
Well, I couldn't wait ;-) Here are my diffs :
LazilyLoadedCtor: Make class and constructor public for use on my host
objects
NodeTransformer : Replace checks for "arguments" by call to
checkActivationNeeded() in Context
Context: Add the name list proposed as a hashtable with
adder/checker/remover methods
Hope this helps. Regards
Felix
move debug object counters and various constructors to jsd_xpc.cpp
add LiveEphemeral struct to reperesent a link in a PRCList of ephemeral objects.
declare jsdIEphemeral interface in objects that need it, add invalidaAll static method to jsdIProperty and jsdIValue. jsdIObject still needs work.
Large changes to improve the way we deal with our wrappers around js engine structures. jsdIScript, jsdIStackFrame, jsdIValue, and jsdIProperty interfaces now inherit from a new interface "jsdIEphemeral". This interface is used to invalidate the wrapper. Once the wrapper is invalidated, *most* methods throw NS_ERROR_NOT_AVAILABLE, some interfaces, such as jsdIScript, cache important information so that the wrapper isn't utterly useless once it has been invalidated. The boolean isValid attribute can be used to see if the wrapper is still valid.
factor debug object counters into some simple macros
add new velid assertion macros for the new ephemeral objects
add utility functions for dealing with PR_CLISTs full of ephemeral objects.
invalidate the jsdIFrame after the execution hook completes
move some c/dtors from jsd_xpc.h over here to avoid exposing debug object counters, and repeating some macros
fix incorrectly set out parameter in getValue::GetDoubleValue
Subject:
Re: Rhino: [[DefaultValue]] missing for Call object
Resent-Date:
Mon, 2 Jul 2001 08:52:07 -0700 (PDT)
Resent-From:
mozilla-jseng@mozilla.org
Date:
Mon, 02 Jul 2001 11:49:59 -0400
From:
Norris Boyd <nboyd@atg.com>
Organization:
Art Technology Group
To:
Christopher Oliver <coliver@mminternet.com>
CC:
mozilla-jseng@mozilla.org
References:
1
I believe the correct result of the script should be
[object global]
[object Object]
[object global]
The activation object (which goes by the name of "Call" for historical
reasons) should never be the 'this' value in a function call. See "10.1.6
Activation Object" in the ECMA spec.
I'll look at fixing the problem for Rhino. If there's agreement on my
analysis, someone should fix this for Spidermonkey too.
--N
Christopher Oliver wrote:
> Hi,
>
> function a() {
> function b() {
> print(this);
> }
> this.f = function() {
> print(this);
> b();
> }
> b();
> }
>
> var a = new a();
> a.f();
>
> Running the above script with SpiderMonkey produces:
>
> [object global]
> [object Object]
> [object Call]
>
> Running with Rhino produces the following exception:
>
> uncaught JavaScript exception: undefined: Cannot find default value for
> object. (line 3)
>
> This is due to a bug in org.mozilla.javascript.NativeCall which doesn't
> implement toString or valueOf or override getDefaultValue.
> However, even after I hacked in an implementation of getDefaultValue in
> NativeCall, Rhino still produces a different result then spidermonkey:
>
> [object Call]
> [object Object]
> [object Call]
Re: Bug in RhinoTip
Resent-Date:
Sat, 30 Jun 2001 11:45:38 -0700 (PDT)
Resent-From:
mozilla-jseng@mozilla.org
Date:
Sat, 30 Jun 2001 20:54:21 +0200
From:
Igor Bukanov <igor@icesoft.no>
Organization:
Wind River
To:
nboyd@atg.com
CC:
Christopher Oliver <coliver@mminternet.com>, mozilla-jseng@mozilla.org
References:
1
Christopher Oliver wrote:
> Hi,
>
> I noticed the following in today's rhinoTip:
>
> js> throw 100
> js: uncaught JavaScript exception: java.lang.Object@5d601f
>
> js> throw 200
> js: uncaught JavaScript exception: java.lang.Object@5d601f
>
> js> throw i = 100
> js: uncaught JavaScript exception: 100
The attached patch to omj/Interpreter.java fixes that: I forgot to check
for stack[stackTop] == DBL_MARK during throw when implemented
interpreter optimization to minimize number of created Double instances.
I think that example should go to the test suite in a form like:
try { throw 100; } catch (ex) { return ex == 100; }
Regards, Igor
Bugfix to Rhino Debugger
Date:
Sat, 30 Jun 2001 06:09:44 -0700
From:
Christopher Oliver <coliver@mminternet.com>
Organization:
Primary Interface LLC
To:
nboyd@atg.com
Hi Norris,
Attached is a fix to a problem I encountered with the Rhino debugger.
Apparently some recent changes to the engine broke the debugger because
the debugger wasn't acquiring a Context before making certain engine
calls like ScriptableObject.getIds(). You can see this by stepping
through the "enum.js" example and expanding the variable "elements".
The below exception trace will be printed on the debugger console. The
attached file should fix this problem.
Chris
Subject:
Another fix to VariableModel.java
Date:
Sat, 30 Jun 2001 07:33:51 -0700
From:
Christopher Oliver <coliver@mminternet.com>
Organization:
Primary Interface LLC
To:
nboyd@atg.com
Hi Norris,
I modified this file to always call Context.toString() to display a
variable's value in the the tree table. Previously it only called it
for Scriptables and the toString() method of the object otherwise. This
caused for example JavaScript "2" to be displayed as "2.0".
Chris
This removes all call-sites I can currently fix. Tomorrow I'll try to get someone to checkin my changes to security/ and I'll get some help with the Netscape side of things.
nsString::GetUnicode()'s final death-blow will be dealt soon. Please keep this in mind as you add new code :-)
Rhino: speed optimization in omj/Interpreter.java
Date:
Tue, 26 Jun 2001 21:06:56 +0200
From:
Igor Bukanov <igor@icesoft.no>
Organization:
Wind River
To:
Norris Boyd <nboyd@atg.com>
Hi, Norris!
The attached Interpreter_patch contains a speed optimization patch that
tries to avoid creation of Double objects by keeping a parallel stack
for double values: instead of putting Double to the stack, DBL_MRK is
put and the real value is put to double stack (sDbl). Then when reading
stack with DBL_MRK, the double value from the double stack is used
wrapped to Double object when necessary. In addition local and vars
arrays are merged to stack array.
The attached before.txt and after.txt contain results of typical runs of
mozilla/js/benchmarks/all_bench.js before and after optimization on my
PC: Athlon 650/Red Hat 7.0/JDK 1.3.0 from Sun .
In number of cases the optimization actually slow down the executionby
5-10% (I guess due to the checks for DBL_MRK), but mostly it is a nice
sped up often by factor of 2 ot more with overall optimization win: 267
versus 218 seconds.
I guess it is possible to apply the same optimization to the optimizer
package, but in our browser we use strictly interpreter mode. Also by
changing signature of call/construct methods in Scriptable it is
possible to avoid creation of almost all objects currently allocated
during method calls, but that is for far future.
Regards, Igor
declare and initialize new provate members in jsdScript, copy important script properties at jsdScript creation time, so they're around after Invalidate().
large changes to fix the following bugs:
82684, crash manually clearing breakpoint
*actually* clearing mValid in jsdScript::Invalidate fixed this one.
85636, assertions on quiting venkman
jsdService::Off now disconnects the hooks into JSD, to avoid calling back into js after that. It also processes any pending script delete events that occurred during the last GC. The code to process the gPendingScripts list has been factored out of the gc callback. Processing the dead script list allows us to properly finalize all of the jsdIScript object, which seems to clear up the "gc roots exist at shutdown" assertions. In effect, these changes get rid of *all* of the jsd related assertions on exit.
Added isOn attribute to jsdIService.
Added isValid attribute to jsdIScript. We now prefetch appropriate properties from the underlying JSDScript, so that it's available after the script is Invalidate()d
moved jsdService constructor to jsd_xpc.h
Save the runtime passed to OnForRuntime so we can use it to clear the GC Gallback in Off().
xpconnect had been printing it's large "js component threw exception" whenever chatzilla's socket code threw NS_BASE_STREAM_WOULD_BLOCK from it's streamprovider (a non-error nsresult, bah.) This patch adds the exception to the "suppression list", to quiet the debug message.
I looked into this somewhat and I noticed the following:
1) There is a bug in Interpreter.java, line 1695. It sets the variable "i" to
the line number of the special call, but overwrites it on line 1699. It then
passes this value to ScriptRuntime.callSpecial
2) In "generateScriptICode" in Interpreter.java the variable
itsData.itsSourceFile fails to be set to itsSourceFile. This causes a null
source file name to be passed to handleCompilationDone when "Widget.js" is
compiled. That is why you
initially see "<stdin>, line 6" when the debugger comes up (the debugger
interprets a null source name as "stdin"). I simply modified it as follows
(this might not be the right thing to do?):
private InterpretedScript generateScriptICode(Context cx,
Scriptable scope,
Node tree,
Object securityDomain)
{
itsSourceFile = (String) tree.getProp(Node.SOURCENAME_PROP);
itsData.itsSourceFile = itsSourceFile;
...
and that corrected the problem.
However there seems to be no way for the debugger to detect that the script
passed to handleCompilationDone() is the argument of an "eval()". So I modifed
NativeGlobal.evalSpecial() to munge the filename to indicate this (by appending
"(eval)" to it). That way a separate window is created in the debugger to hold
the compiled eval code. This is probably not be the best way to solve the
problem.
I have attached the files I modified.
Cheers,
Chris
Simon Massey wrote:
> Christopher,
>
> Attached is the code that trips the debugger up. The debugger comes up. You
minimize the console to reveal Widget.js file window. You click 'Go'. The
Widget.js window looses all the code in it and is just replaced by the evaluated
code:
>
> this.invokedByEval()
>
> The rhino tip I have is rhino15R2pre.zip
>
> I am running it with the command:
>
> start javaw org.mozilla.javascript.tools.debugger.JSDebugger -f Widget.js -f
Main.js
>
> using the JVM:
>
> java version "1.3.0"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
> Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
>
> on Win2k.
>
> Just in case you are wondering why on earth my code wants to do this, it is
because I want to do some introspection. The real Widget invokes all its methods
that have a particular substring in their names:
>
> for( key in this ){
> if( key.indexOf('reflect') == 0 ){
> var evalStr = "this."+key+"()";
> eval(evalStr);
> }
> }
>
> Thanks for the great code. I have the real Widget stabilized and am happily
using the debugger on my other files.
>
> Thanks again!
>
> Simon Massey
>
Changes allow us to have a finer control over which parts of the tree are built with PIC. Part of the static build branch landing.
Bug #46775 r=mcafee a=leaf