Skip to content

Commit dd1882a

Browse files
author
zhourenjian
committed
Fixed bug that Hotspot swapped SimpleRPCRunnable subclasses may register its fields more than once.
Fixed bug that Hotspot classes list from server side may be cached by browser, use random query to avoid such bugs and server side will also send out Pragma: no-cache.
1 parent a3538ab commit dd1882a

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

sources/net.sf.j2s.java.core/src/java/lang/ClassExt.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,18 @@ Clazz.registerSerializableFields = function (clazz) {
394394
if (length > 0 && length % 2 == 1) {
395395
var fs = clazz.declared$Fields;
396396
for (var i = 1; i <= (length - 1) / 2; i++) {
397-
fs[fs.length] = { name : args[i + i - 1], type : args[i + i] };
397+
var o = { name : args[i + i - 1], type : args[i + i] };
398+
var existed = false;
399+
for (var j = 0; j < fs.length; j++) {
400+
if (fs[j].name == o.name) { // reloaded classes
401+
fs[j].type = o.type; // update type
402+
existed = true;
403+
break;
404+
}
405+
}
406+
if (!existed) {
407+
fs[fs.length] = o;
408+
}
398409
}
399410
}
400411
};

sources/net.sf.j2s.java.core/src/java/lang/ClassLoader.js

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,6 +2425,7 @@ ClazzLoader.removeFromArray = function (node, arr) {
24252425
};
24262426

24272427
/* private */
2428+
/*-# destroyClassNode -> dCN #-*/
24282429
ClazzLoader.destroyClassNode = function (node) {
24292430
var parents = node.parents;
24302431
if (parents != null) {
@@ -2476,7 +2477,7 @@ ClazzLoader.unloadClassExt = function (qClazzName) {
24762477
ClazzLoader.classUnloaded (qClazzName);
24772478
};
24782479

2479-
/* private */
2480+
/* protected */ /* Clazz#assureInnerClass */
24802481
ClazzLoader.assureInnerClass = function (clzz, fun) {
24812482
var clzzName = clzz.__CLASS_NAME__;
24822483
if (Clazz.unloadedClasses[clzzName]) {
@@ -2517,7 +2518,9 @@ ClazzLoader.assureInnerClass = function (clzz, fun) {
25172518
}
25182519
};
25192520

2521+
/*-# lastHotspotUpdated -> ltUd #-*/
25202522
ClazzLoader.lastHotspotUpdated = new Date ().getTime ();
2523+
/*-# lastHotspotSessionID -> ltSI #-*/
25212524
ClazzLoader.lastHotspotSessionID = 0;
25222525

25232526
/*
@@ -2536,7 +2539,9 @@ ClazzLoader.updateHotspot = function () {
25362539
}
25372540
var length = (arguments.length - 1) / 3;
25382541
var lastID = 0;
2542+
/*-# lastUpdated -> lUd #-*/
25392543
var lastUpdated = 0;
2544+
/*-# toUpdateClasses -> tUs #-*/
25402545
var toUpdateClasses = new Array ();
25412546
for (var i = 0; i < length; i++) {
25422547
var time = arguments[i * 3];
@@ -2553,6 +2558,7 @@ ClazzLoader.updateHotspot = function () {
25532558
if (toUpdateClasses.length > 0) {
25542559
ClazzLoader.lastHotspotUpdated = lastUpdated;
25552560
ClazzLoader.lastHotspotSessionID = lastID;
2561+
/*-# needUpdateClasses -> nUC #-*/
25562562
var needUpdateClasses = new Array ();
25572563
for (var i = 0; i < toUpdateClasses.length; i++) {
25582564
needUpdateClasses[i] = Clazz.unloadClass (toUpdateClasses[i]);
@@ -2574,6 +2580,7 @@ ClazzLoader.updateHotspot = function () {
25742580
};
25752581

25762582
/* private */
2583+
/*-# removeHotspotScriptNode -> rtSN #-*/
25772584
ClazzLoader.removeHotspotScriptNode = function (n) {
25782585
// lazily remove script nodes.
25792586
window.setTimeout ((function (node) {
@@ -2594,23 +2601,33 @@ ClazzLoader.removeHotspotScriptNode = function (n) {
25942601
}
25952602
};
25962603

2604+
/*-# lastHotspotScriptLoaded -> ltSL #-*/
25972605
ClazzLoader.lastHotspotScriptLoaded = true;
2598-
ClazzLoader.hotspotMonitoringTimeout = null;
2606+
/*-# hotspotJSTimeout -> hJSt #-*/
2607+
ClazzLoader.hotspotJSTimeout = null;
2608+
/*-# lastHotspotJSFailed -> ltJF #-*/
25992609
ClazzLoader.lastHotspotJSFailed = false;
26002610

26012611
/* protected */
2612+
/*-# hotspotMonitoring -> htMr #-*/
26022613
ClazzLoader.hotspotMonitoring = function () {
2603-
if (ClazzLoader.lastHotspotScriptLoaded) {
2614+
if (ClazzLoader.lastHotspotScriptLoaded
2615+
&& !ClazzLoader.lastHotspotJSFailed) {
26042616
var port = window["j2s.hotspot.port"];
26052617
if (port == null) {
26062618
port = 1725;
26072619
}
26082620
var hotspotURL = "http://127.0.0.1:" + port;
26092621
if (ClazzLoader.lastHotspotSessionID == 0) {
2610-
hotspotURL += "/hotspot.js";
2622+
hotspotURL += "/hotspot.js?" + Math.random ();
26112623
} else {
2612-
hotspotURL += "/" + ClazzLoader.lastHotspotSessionID + ".js";
2624+
hotspotURL += "/" + ClazzLoader.lastHotspotSessionID + ".js?"
2625+
+ Math.random ();
26132626
}
2627+
2628+
ClazzLoader.lastHotspotJSFailed = true;
2629+
ClazzLoader.lastHotspotScriptLoaded = false;
2630+
26142631
var script = document.createElement ("SCRIPT");
26152632
script.type = "text/javascript";
26162633
script.src = hotspotURL;
@@ -2633,19 +2650,19 @@ ClazzLoader.hotspotMonitoring = function () {
26332650
};
26342651
}
26352652

2636-
ClazzLoader.lastHotspotJSFailed = true;
2637-
ClazzLoader.lastHotspotScriptLoaded = false;
26382653
var head = document.getElementsByTagName ("HEAD")[0];
26392654
head.appendChild (script);
2640-
}
2641-
2642-
window.setTimeout (ClazzLoader.hotspotMonitoring, 250);
2643-
if (ClazzLoader.hotspotMonitoringTimeout == null) {
2644-
ClazzLoader.hotspotMonitoringTimeout = window.setTimeout (function () {
2655+
if (ClazzLoader.hotspotJSTimeout != null) {
2656+
window.clearTimeout (ClazzLoader.hotspotJSTimeout);
2657+
ClazzLoader.hotspotJSTimeout = null;
2658+
}
2659+
ClazzLoader.hotspotJSTimeout = window.setTimeout (function () {
26452660
ClazzLoader.lastHotspotScriptLoaded = true; // timeout
2646-
window.setTimeout (ClazzLoader.hotspotMonitoring, 50);
2661+
ClazzLoader.lastHotspotJSFailed = false; // timeout
26472662
}, 7500); // 7.5 seconds to time out
26482663
}
2664+
2665+
window.setTimeout (ClazzLoader.hotspotMonitoring, 250);
26492666
};
26502667

26512668
/*

0 commit comments

Comments
 (0)