This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 267477
Collapse All | Expand All

(-)a/ko4j/src/main/java/org/netbeans/html/ko4j/KOTech.java (-6 / +14 lines)
Lines 62-67 Link Here
62
    private int jsIndex;
62
    private int jsIndex;
63
63
64
    public KOTech() {
64
    public KOTech() {
65
        Thread.dumpStack();
65
    }
66
    }
66
    
67
    
67
    @Override
68
    @Override
Lines 102-115 Link Here
102
    }
103
    }
103
    
104
    
104
    private Object getJSObject() {
105
    private Object getJSObject() {
105
        int len = 64;
106
        int len;
106
        if (jsObjects != null && jsIndex < (len = jsObjects.length)) {
107
        if (jsObjects == null) {
107
            Object ret = jsObjects[jsIndex];
108
            len = 64;
108
            jsObjects[jsIndex] = null;
109
            System.err.println("len 64 for " + this);
109
            jsIndex++;
110
        } else {
110
            return ret;
111
            len = jsObjects.length;
112
            if (jsIndex < len) {
113
                Object ret = jsObjects[jsIndex];
114
                jsObjects[jsIndex] = null;
115
                jsIndex++;
116
                return ret;
117
            }
111
        }
118
        }
112
        jsObjects = Knockout.allocJS(len * 2);
119
        jsObjects = Knockout.allocJS(len * 2);
120
        System.err.printf("jsObjects size %d\n", jsObjects.length);
113
        jsIndex = 1;
121
        jsIndex = 1;
114
        Object ret = jsObjects[0];
122
        Object ret = jsObjects[0];
115
        jsObjects[0] = null;
123
        jsObjects[0] = null;
(-)a/ko4j/src/main/java/org/netbeans/html/ko4j/Knockout.java (-3 / +36 lines)
Lines 83-88 Link Here
83
    private Object js;
83
    private Object js;
84
    private Object strong;
84
    private Object strong;
85
85
86
    private static int cntCreated;
87
    private static int cntCleaned;
88
    private static long cntLast = System.currentTimeMillis();
89
86
    public Knockout(Object model, Object js, PropertyBinding[] props, FunctionBinding[] funcs) {
90
    public Knockout(Object model, Object js, PropertyBinding[] props, FunctionBinding[] funcs) {
87
        super(model, QUEUE);
91
        super(model, QUEUE);
88
        this.js = js;
92
        this.js = js;
Lines 95-100 Link Here
95
            this.funcs[i] = funcs[i].weak();
99
            this.funcs[i] = funcs[i].weak();
96
        }
100
        }
97
        active.add(this);
101
        active.add(this);
102
        cntCreated++;
98
    }
103
    }
99
    
104
    
100
    static void cleanUp() {
105
    static void cleanUp() {
Lines 103-108 Link Here
103
            if (ko == null) {
108
            if (ko == null) {
104
                return;
109
                return;
105
            }
110
            }
111
            cntCleaned++;
112
            if (cntLast + 1000 > System.currentTimeMillis()) {
113
                cntLast = System.currentTimeMillis();
114
                System.err.printf("Java created %d vs. cleaned %d\n", cntCreated, cntCleaned);
115
            }
106
            active.remove(ko);
116
            active.remove(ko);
107
            clean(ko.js);
117
            clean(ko.js);
108
            ko.js = null;
118
            ko.js = null;
Lines 159-166 Link Here
159
    
169
    
160
    @JavaScriptBody(args = { "cnt" }, body = 
170
    @JavaScriptBody(args = { "cnt" }, body = 
161
        "var arr = new Array(cnt);\n" +
171
        "var arr = new Array(cnt);\n" +
162
        "for (var i = 0; i < cnt; i++) arr[i] = new Object();\n" +
172
        "var pool = window.pool;\n" +
163
        "return arr;\n"
173
        "if (!pool) {\n" +
174
        "  pool = window.pool = [];\n" +
175
        "  pool.cntNew = 0;\n" +
176
        "  pool.cntPush = 0;\n" +
177
        "  pool.cntPop = 0;\n" +
178
        "  for (var i = 0; i < 1000000; i++) {\n" +
179
        "    pool.push(new Object())\n" +
180
        "  }\n" +
181
        "}\n" +
182
        "for (var i = 0; i < cnt; i++) {\n" +
183
        "  if (pool.length > 0) {\n" +
184
        "    arr[i] = pool.pop();\n" +
185
        "    pool.cntPop++;\n" +
186
        "  } else {\n" +
187
        "    pool.cntNew++;\n" +
188
        "    arr[i] = new Object();\n" +
189
        "  }\n" +
190
        "  if ((pool.cntNew + pool.cntPop + pool.cntPush) % 1000 == 0) {\n" +
191
//        "    console.log('New: ' + pool.cntNew + ' pop: ' + pool.cntPop + ' push: ' + pool.cntPush);\n" +
192
        "  }\n" +
193
        "}\n"
194
      + "return arr;\n"
164
    )
195
    )
165
    native static Object[] allocJS(int cnt);
196
    native static Object[] allocJS(int cnt);
166
    
197
    
Lines 170-176 Link Here
170
        wait4js = false,
201
        wait4js = false,
171
        args = { "ret", "copyFrom", "propNames", "propInfo", "propValues", "funcNames" },
202
        args = { "ret", "copyFrom", "propNames", "propInfo", "propValues", "funcNames" },
172
        body = 
203
        body = 
173
          "Object.defineProperty(ret, 'ko4j', { value : this });\n"
204
          "Object.defineProperty(ret, 'ko4j', { value : this, writable : true, configurable : true });\n"
174
        + "function normalValue(r) {\n"
205
        + "function normalValue(r) {\n"
175
        + "  if (r) try { var br = r.valueOf(); } catch (err) {}\n"
206
        + "  if (r) try { var br = r.valueOf(); } catch (err) {}\n"
176
        + "  return br === undefined ? r: br;\n"
207
        + "  return br === undefined ? r: br;\n"
Lines 257-262 Link Here
257
        "for (var p in js) {\n" +
288
        "for (var p in js) {\n" +
258
        "  delete js[p];\n" +
289
        "  delete js[p];\n" +
259
        "};\n" +
290
        "};\n" +
291
        "window.pool.cntPush++;\n" +
292
        "window.pool.push(js);\n" +
260
        "\n"
293
        "\n"
261
    )
294
    )
262
    private static native void clean(Object js);
295
    private static native void clean(Object js);

Return to bug 267477