Commit Graph

2449 Commits

Author SHA1 Message Date
brendan%mozilla.org
7acd9814b4 Fix an out-of-date comment. 2000-07-08 02:35:56 +00:00
brendan%mozilla.org
58ffa1e2e0 Make it safe to nest a GC from js_AllocGCThing, ultimately from the interpreter; also make sure we collect all garbage (even garbage created by finalizers who unroot or unlock GC-things) when destroying the last context (39125, 44376, r=mccabe@netscape.com). 2000-07-08 02:06:01 +00:00
rogerl%netscape.com
daba9186aa Support for 'constructor'. 2000-07-08 01:08:29 +00:00
nboyd%atg.com
0a9b985a17 Deprecate FlattenedObject. 2000-07-07 14:41:35 +00:00
waterson%netscape.com
c1a0e63f75 Brendan meant to add jsdhash.h to the Mac build, too. 2000-07-06 20:55:23 +00:00
waterson%netscape.com
1001bcd519 Brendan meant add jsdhash.c to the Mac build, too. 2000-07-06 20:54:17 +00:00
rogerl%netscape.com
1375151969 Removed preprocess step, consolidated identifier handling. 2000-07-06 18:26:26 +00:00
brendan%mozilla.org
b117e30fa4 Fix lying comment, pick control flow nit (r=lumpy,a=jack). 2000-07-06 07:38:11 +00:00
brendan%mozilla.org
6d7ae73603 Add jsdhash.h to export/install lists, and jsdhash.c/.obj. 2000-07-06 04:46:18 +00:00
brendan%mozilla.org
2ecb3888a2 Avoid 80th column violations and unnecessary local variable. 2000-07-06 01:15:08 +00:00
brendan%mozilla.org
e5ca3a7b1a Undo teeny optimization from rev 3.28, alas it breaks ECMA Ed. 3, 15.5.4.15. 2000-07-06 00:30:46 +00:00
nboyd%atg.com
a1f493ab08 Remove obsolete references to NodeFactory. 2000-07-05 17:08:26 +00:00
nboyd%atg.com
fdeea4b93b Subject:
Re: Rhino1.5.R1: problems with multithreaded embedded application.
        Date:
             Mon, 03 Jul 2000 14:38:56 -0400
       From:
             Norris Boyd <nboyd@atg.com>
 Organization:
             Art Technology Group
         To:
             Fergus Gallagher <Fergus.Gallagher@orbisuk.com>
 Newsgroups:
             netscape.public.mozilla.jseng
  References:
             1




You found a bug in Rhino; I wonder if others have been running into the same thing.

The problem is with a class called LazilyLoadedCtor. I wrote this class to reduce the
time
required by initStandardObjects by only creating standard objects when the associated
constructors are first accessed. The problem is that this class was not threadsafe.
I've
made changes to that class, and to ScriptableObject as well. The design of dynamic
properties calling getters and setters (which LazilyLoadedCtor uses) didn't really
allow
any way for the getter/setter to replace itself without a thread hazard. I've now
extended
setters so that they can return a value which replaces the getter/setter to avoid this
problem.

Thanks for finding this problem. There have been a couple of other reports of problems
in
this area, so I hope this will fix them.

The patch follows.

--N

Index: LazilyLoadedCtor.java
===================================================================
RCS file: /cvsroot/mozilla/js/rhino/org/mozilla/javascript/LazilyLoadedCtor.java,v
retrieving revision 1.1
diff -u -r1.1 LazilyLoadedCtor.java
--- LazilyLoadedCtor.java 2000/02/29 21:34:37 1.1
+++ LazilyLoadedCtor.java 2000/07/03 18:31:03
@@ -58,9 +58,12 @@
     }

     public Object getProperty(ScriptableObject obj) {
-        obj.delete(ctorName);
         try {
-            ScriptableObject.defineClass(obj, Class.forName(className));
+            synchronized (obj) {
+                if (!isReplaced)
+                    ScriptableObject.defineClass(obj, Class.forName(className));
+                isReplaced = true;
+            }
         }
         catch (ClassNotFoundException e) {
             throw WrappedException.wrapException(e);
@@ -83,11 +86,14 @@
         return obj.get(ctorName, obj);
     }

-    public void setProperty(ScriptableObject obj, Object val) {
-        obj.delete(ctorName);
-        obj.put(ctorName, obj, val);
+    public Object setProperty(ScriptableObject obj, Object val) {
+        synchronized (obj) {
+            isReplaced = true;
+            return val;
+        }
     }

     private String ctorName;
     private String className;
+    private boolean isReplaced;
 }
Index: ScriptableObject.java
===================================================================
RCS file: /cvsroot/mozilla/js/rhino/org/mozilla/javascript/ScriptableObject.java,v
retrieving revision 1.17
diff -u -r1.17 ScriptableObject.java
--- ScriptableObject.java 2000/03/13 17:12:36 1.17
+++ ScriptableObject.java 2000/07/03 18:31:04
@@ -246,11 +246,21 @@
                             break;
                         }
                     }
-                    getterSlot.setter.invoke(start, arg);
+                    Object v = getterSlot.setter.invoke(start, arg);
+                    if (getterSlot.setterReturnsValue) {
+                        slots[slotIndex].value = v;
+                        if (!(v instanceof Method))
+                            slots[slotIndex].flags = 0;
+                    }
                     return;
                 }
                 Object[] args = { this, actualArg };
-                getterSlot.setter.invoke(getterSlot.delegateTo, args);
+                Object v = getterSlot.setter.invoke(getterSlot.delegateTo, args);
+                if (getterSlot.setterReturnsValue) {
+                    slots[slotIndex].value = v;
+                    if (!(v instanceof Method))
+                        slots[slotIndex].flags = 0;
+                }
                 return;
             }
             catch (InvocationTargetException e) {
@@ -1183,6 +1193,7 @@
         slot.delegateTo = delegateTo;
         slot.getter = getter;
         slot.setter = setter;
+        slot.setterReturnsValue = setter != null && setter.getReturnType() !=
Void.TYPE;
         slot.value = null;
         slot.attributes = (short) attributes;
         slot.flags = flags;
@@ -1551,6 +1562,7 @@
     Object delegateTo;  // OPT: merge with "value"
     Method getter;
     Method setter;
+    boolean setterReturnsValue;
 }




Fergus Gallagher wrote:

> I am having problems getting my head around contexts and scopes and my
> multi-threaded application fall over.
>
> If I set "global=false" the following code used a per-thread
> initStandardObject() and this seems to work.  But when I set
> "global=true", the global "parentScope" is used and I get some wierd
> errors.
>
> If I change "__CODE__.slice(0,5)" to
> 1. "__CODE__" - works
> 2. "__CODE__.substring(0,5)" - fails
> 3. "__CODE__.toString()" - works
>
> Any help appreciated.
>
> Fergus
>
> ===== Test.java =========================================
> import java.io.*;
> import org.mozilla.javascript.*;
>
> public class Test implements Runnable {
>         private Script script;
>         private Scriptable parentScope;
>         private String __CODE__="ABCDEFGHIJK";
>         private boolean global = true;
>         private static Context globalContext = null;
>         public Test() throws Exception {
>                 String js= "java.lang.System.out.println(__CODE__.slice(0,5));";
>                 globalContext.setCompileFunctionsWithDynamicScope(false);
>                 parentScope = globalContext.initStandardObjects(null);
>                 StringReader sr = new StringReader(js);
>                 script = globalContext.compileReader(parentScope, sr, "(compiled)",
> 1,null);
>         }
>
>         public void run() {
>                 try {
>                         Context context = Context.enter();
>                         Scriptable threadScope;
>                         if (global) {
>                                 threadScope = context.newObject(parentScope);
>                                 threadScope.setPrototype(parentScope);
>                                 threadScope.setParentScope(null);
>                         } else {
>                                 threadScope = context.initStandardObjects(null);
>                         }
>                         threadScope.put("__CODE__",threadScope,__CODE__);
>                         script.exec(context,threadScope);
>                 }
>                 catch (Exception e) {
>                         System.err.println(e.getClass().getName()+":
"+e.getMessage());
>                 }
>                 finally {
>                         Context.exit();
>                 }
>         }
>
>         public static void main(String args[]) throws Exception {
>         globalContext = Context.enter();
>                 Test me = new Test();
>                 int count=10;
>                 Thread[] threads = new Thread[count];
>                 for (int i=0; i<count; i++) {
>                         Thread t = new Thread(me);
>                         threads[i] = t;
>                         t.start();
>                 }
>                 for (int i=0; i<count; i++) {
>                         threads[i].join();
>                 }
>                 Context.exit();
>         }
> }
>
> ==== OUTPUT ===============================================
> ABCDE
> ABCDE
> org.mozilla.javascript.EcmaError: undefined is not a function.
> org.mozilla.javascript.EvaluatorException: Constructor for "String" not
> found.
> org.mozilla.javascript.EvaluatorException: Constructor for "String" not
> found.
> org.mozilla.javascript.EvaluatorException: Constructor for "String" not
> found.
> org.mozilla.javascript.EvaluatorException: Constructor for "String" not
> found.
> org.mozilla.javascript.EvaluatorException: Constructor for "String" not
> found.
> org.mozilla.javascript.EvaluatorException: Constructor for "String" not
> found.
> org.mozilla.javascript.EvaluatorException: Constructor for "String" not
> found.
> ===========================================================
>
> The number and type of exceptions is highly variable from run to run -
> anywhere from 1-9 out of 10.
> The EcmaError in particular only happens occasionally.
>
> --
> Fergus Gallagher          Tel: +44 (20) 8 987 0717
> Orbis                     Fax: +44 (20) 8 742 2649
> The Swan Centre           email: Fergus.Gallagher@orbisuk.com
> Fishers Lane              Web: http://www.orbisuk.com
> London W4 1RX / UK
2000-07-03 18:40:35 +00:00
jband%netscape.com
53edf6e9f7 updating readme. Not part of build 2000-07-02 19:37:57 +00:00
cls%seawood.org
1f3b6d75ab Removed obsolete REQUIRES variable from every Makefile.in/makefile.win 2000-06-30 08:08:04 +00:00
jband%netscape.com
1a7630d560 Fix dogfood/crash bugs: 42750, 39858 and fix 43897 and improve JS/XPConnect error reporting to help with crasher 40792. r=mccabe@netscape.com. 2000-06-30 04:04:46 +00:00
beard%netscape.com
0eeae607ae Fix build bustage. 2000-06-29 18:40:58 +00:00
rogerl%netscape.com
fd98adafce use handleDot for call, too. 2000-06-29 18:30:47 +00:00
beard%netscape.com
8f5fea173e delete property support. 2000-06-29 18:14:14 +00:00
beard%netscape.com
a4c5f704f4 DELETE_PROP 2000-06-29 18:13:46 +00:00
beard%netscape.com
7a6367c583 DELETE_PROP 2000-06-29 17:14:56 +00:00
beard%netscape.com
11134b4173 added DELETE_PROP instruction to implement the "delete" operation. 2000-06-29 17:11:50 +00:00
beard%netscape.com
97dfdc5f04 unused parameter warning 2000-06-29 05:48:09 +00:00
beard%netscape.com
8f4cadb250 complementary operator delete(void*, JSClass*). 2000-06-29 05:46:36 +00:00
beard%netscape.com
8891b0c7ba some classes to test js2 with. 2000-06-29 04:49:48 +00:00
beard%netscape.com
8da0055bc5 updated dependencies 2000-06-29 04:25:10 +00:00
beard%netscape.com
074f981eb4 Changed StaticCall to use static slot. 2000-06-29 04:23:56 +00:00
beard%netscape.com
b202adfd39 Fixing static dotted expressions. 2000-06-29 04:23:20 +00:00
beard%netscape.com
7a512866fd now uses conditional compilation #if defined(OPCODE_NAMES), so that a simple "icode.h" can be included by vmtypes.h and vmtypes.cpp. 2000-06-29 04:21:00 +00:00
beard%netscape.com
486b437613 moved all machine generated classes, etc. to icode.h. 2000-06-29 04:19:19 +00:00
beard%netscape.com
2a451cdd8b Generated by tools/gencode.pl. 2000-06-29 04:18:16 +00:00
beard%netscape.com
640ba6e24c fixed static calls. 2000-06-29 03:15:52 +00:00
rogerl%netscape.com
63744d7c1c Implicit this and class lookup stuff. 2000-06-29 01:21:41 +00:00
cls%seawood.org
e5efcb7528 wrap ifndef XPCONNECT_STANDALONE around xpconnect test components that require external interfaces. Thanks to Mark Adams <madams@janna.com> for the patch. Bug 42026 2000-06-28 22:53:55 +00:00
beard%netscape.com
237dd352ed implemented JSClass::printProperties(). 2000-06-28 19:46:13 +00:00
beard%netscape.com
9930edd0d5 Enhanced printing of types. 2000-06-28 19:45:44 +00:00
beard%netscape.com
c0e9f6d274 Type of a JSType* is Type_Type (wow, recursive). Changed mBaseType to be JSType* instead of const JSType*. 2000-06-28 19:45:09 +00:00
rogerl%netscape.com
52bffdadcf First set of unified 'dot' handling changes for statics. 2000-06-28 18:41:30 +00:00
beard%netscape.com
d40b8dd8cb added jsclasses.h 2000-06-28 18:10:04 +00:00
beard%netscape.com
941b505765 Fix string <. 2000-06-28 16:38:20 +00:00
beard%netscape.com
d9bf640477 Fixed dynamic lookup of static slots. Added code to compare strings. 2000-06-28 16:32:52 +00:00
beard%netscape.com
b1350d87b6 GET_STATIC/SET_STATIC/STATIC_XCR now use an index rather than a name. Implemented GET_PROP/SET_PROP for class objects (looks up slot dynamically, etc.) 2000-06-28 16:15:06 +00:00
beard%netscape.com
866b5d3d8d GET_STATIC/SET_STATIC/STATIC_XCR now use an index rather than a name. Now using JSClass::hasStatic() rather than looking up statics in class' scope. 2000-06-28 16:14:18 +00:00
beard%netscape.com
8132734212 GET_STATIC/SET_STATIC/STATIC_XCR now use an index rather than a name. 2000-06-28 16:13:12 +00:00
beard%netscape.com
970477555f Static slots. 2000-06-28 16:11:54 +00:00
cls%seawood.org
a9f6433fbe Tweaks to build xpconnect standalone. Bug #42024. Thanks to Mark Adams <madams@janna.com> for the patches. 2000-06-28 07:03:13 +00:00
beard%netscape.com
2b1351cc3b Win-specific operator== noise. 2000-06-27 03:52:56 +00:00
beard%netscape.com
4873ce7882 Fixed unitialized static class members. 2000-06-27 03:43:40 +00:00
beard%netscape.com
7b2b4a1e2f addSlot -> defineSlot, added defineStatic. 2000-06-27 03:42:42 +00:00
brendan%mozilla.org
9f75641ee2 Not again\! 2000-06-27 03:29:49 +00:00