1
- describe ( "Tests garbage collection" , function ( ) {
2
-
1
+ // Run GC tests only in Full marking mode
2
+ let describeFunc = __markingMode == 0 ? describe : xdescribe ;
3
+
4
+ describeFunc ( "Tests garbage collection" , function ( ) {
3
5
var myCustomEquality = function ( first , second ) {
4
6
return first == second ;
5
7
} ;
6
-
8
+
7
9
beforeEach ( function ( ) {
8
10
jasmine . addCustomEqualityTester ( myCustomEquality ) ;
9
11
} ) ;
10
12
11
13
xit ( "TestGarbageCollection" , function ( done ) {
12
- var normalTest = function ( ) {
14
+ var normalTest = function ( ) {
13
15
14
16
__log ( "TEST: TestGarbageCollection" ) ;
15
-
17
+
16
18
var obj = new com . tns . tests . ClassX ( ) ;
17
-
19
+
18
20
obj . dummy ( ) ;
19
-
21
+
20
22
obj = null ;
21
-
23
+
22
24
gc ( ) ;
23
25
java . lang . System . gc ( ) ;
24
26
gc ( ) ;
25
27
java . lang . System . gc ( ) ;
26
28
gc ( ) ;
27
29
java . lang . System . gc ( ) ;
28
-
30
+
29
31
new java . lang . Thread ( new java . lang . Runnable ( "ThreadFunc" , {
30
32
run : function ( ) {
31
33
var isCollected = com . tns . tests . ClassX . IsCollected ;
@@ -37,62 +39,62 @@ describe("Tests garbage collection", function () {
37
39
} ;
38
40
normalTest ( ) ;
39
41
} ) ;
40
-
42
+
41
43
// this test has implicit assert in com.tns.Runtime.getJavaObjectByID method
42
44
it ( "test1" , function ( ) {
43
-
45
+
44
46
function createObjects ( name ) {
45
47
var c1 = new com . tns . tests . Class1 ( ) ;
46
-
48
+
47
49
var cb1 = new com . tns . tests . Class1 . Callback1 ( name , {
48
50
getMessage : function ( ) {
49
51
var msg = c1 . getMessage ( ) ;
50
52
return msg ;
51
53
}
52
54
} ) ;
53
-
55
+
54
56
return com . tns . tests . Class1 . Class2 . printMessageWithDelay ( cb1 , 5 * 1000 ) ;
55
57
}
56
-
58
+
57
59
expect ( createObjects ( "Callback5" ) ) . toBe ( true ) ;
58
60
expect ( createObjects ( "Callback26" ) ) . toBe ( true ) ;
59
-
61
+
60
62
gc ( ) ;
61
63
java . lang . System . gc ( ) ;
62
64
} ) ;
63
-
65
+
64
66
// this test has implicit assert in com.tns.Runtime.getJavaObjectByID method
65
67
it ( "test2" , function ( ) {
66
-
68
+
67
69
function indref1 ( ) {
68
70
this . class1 = new com . tns . tests . Class1 ( ) ;
69
71
}
70
72
indref1 . prototype . getMessage = function ( ) {
71
73
return "~~~" + this . class1 . getMessage ( ) ;
72
74
}
73
-
75
+
74
76
function createObjects ( name ) {
75
77
var c1 = new indref1 ( ) ;
76
-
78
+
77
79
var cb1 = new com . tns . tests . Class1 . Callback1 ( name , {
78
80
getMessage : function ( ) {
79
81
var msg = c1 . getMessage ( ) ;
80
82
return msg ;
81
83
}
82
84
} ) ;
83
-
85
+
84
86
return com . tns . tests . Class1 . Class2 . printMessageWithDelay ( cb1 , 5 * 1000 ) ;
85
87
}
86
-
88
+
87
89
expect ( createObjects ( "Callback55" ) ) . toBe ( true ) ;
88
90
expect ( createObjects ( "Callback56" ) ) . toBe ( true ) ;
89
91
gc ( ) ;
90
92
java . lang . System . gc ( ) ;
91
93
} ) ;
92
-
94
+
93
95
// this test has implicit assert in com.tns.Runtime.getJavaObjectByID method
94
96
it ( "test3" , function ( ) {
95
-
97
+
96
98
function indref2 ( ) {
97
99
this . helper = new indref2helper ( ) ;
98
100
}
@@ -105,29 +107,29 @@ describe("Tests garbage collection", function () {
105
107
indref2helper . prototype . getMessage = function ( ) {
106
108
return "***" + this . class1 . getMessage ( ) ;
107
109
}
108
-
110
+
109
111
function createObjects ( name ) {
110
112
var c1 = new indref2 ( ) ;
111
-
113
+
112
114
var cb1 = new com . tns . tests . Class1 . Callback1 ( name , {
113
115
getMessage : function ( ) {
114
116
var msg = c1 . getMessage ( ) ;
115
117
return msg ;
116
118
}
117
119
} ) ;
118
-
120
+
119
121
return com . tns . tests . Class1 . Class2 . printMessageWithDelay ( cb1 , 5 * 1000 ) ;
120
122
}
121
-
123
+
122
124
expect ( createObjects ( "Callback91" ) ) . toBe ( true ) ;
123
125
expect ( createObjects ( "Callback92" ) ) . toBe ( true ) ;
124
126
gc ( ) ;
125
127
java . lang . System . gc ( ) ;
126
128
} ) ;
127
-
129
+
128
130
// this test has implicit assert in com.tns.Runtime.getJavaObjectByID method
129
131
it ( "test4" , function ( ) {
130
-
132
+
131
133
function indref3 ( ) {
132
134
this . helper = new indref3helper ( ) ;
133
135
}
@@ -136,97 +138,97 @@ describe("Tests garbage collection", function () {
136
138
}
137
139
function indref3helper ( ) {
138
140
this . _class1 = new com . tns . tests . Class1 ( ) ;
139
-
141
+
140
142
Object . defineProperty ( this , "class1" , {
141
143
get : function ( ) {
142
- return this . _class1
143
- }
144
+ return this . _class1
145
+ }
144
146
} ) ;
145
147
}
146
148
indref3helper . prototype . getMessage = function ( ) {
147
149
return "^^^" + this . class1 . getMessage ( ) ;
148
- }
149
-
150
+ }
151
+
150
152
function createObjects ( name ) {
151
153
var c1 = new indref3 ( ) ;
152
-
154
+
153
155
var cb1 = new com . tns . tests . Class1 . Callback1 ( name , {
154
156
getMessage : function ( ) {
155
157
var msg = c1 . getMessage ( ) ;
156
158
return msg ;
157
159
}
158
160
} ) ;
159
-
161
+
160
162
return com . tns . tests . Class1 . Class2 . printMessageWithDelay ( cb1 , 5 * 1000 ) ;
161
163
}
162
-
164
+
163
165
expect ( createObjects ( "Callback1133" ) ) . toBe ( true ) ;
164
166
expect ( createObjects ( "Callback1134" ) ) . toBe ( true ) ;
165
167
gc ( ) ;
166
168
java . lang . System . gc ( ) ;
167
169
} ) ;
168
-
170
+
169
171
// this test has implicit assert in com.tns.Runtime.getJavaObjectByID method
170
172
//originally test was commented out
171
173
xit ( "test5" , function ( ) {
172
-
174
+
173
175
function indref4 ( ) {
174
176
this . helper = new indref4helper ( ) ;
175
177
}
176
178
indref4 . prototype . getMessage = function ( ) {
177
179
return "&&&" + this . helper . getMessageZZZ ( ) ;
178
180
}
179
- function indref4helper ( ) {
181
+ function indref4helper ( ) {
180
182
var _class1 = new com . tns . tests . Class1 ( ) ;
181
-
183
+
182
184
__log ( "indref4helper _class1=" + _class1 ) ;
183
-
185
+
184
186
Object . defineProperty ( this , "class1" , {
185
187
get : function ( ) {
186
- return _class1
188
+ return _class1
187
189
}
188
190
, enumerable : false
189
191
} ) ;
190
192
}
191
193
indref4helper . prototype . getMessageZZZ = function ( ) {
192
194
return "```" + this . class1 . getMessage ( ) ;
193
195
}
194
-
196
+
195
197
function createObjects ( name ) {
196
198
var c1 = new indref4 ( ) ;
197
-
199
+
198
200
var cb1 = new com . tns . tests . Class1 . Callback1 ( name , {
199
201
getMessage : function ( ) {
200
202
var msg = c1 . getMessage ( ) ;
201
203
return msg ;
202
204
}
203
205
} ) ;
204
-
206
+
205
207
return com . tns . tests . Class1 . Class2 . printMessageWithDelay ( cb1 , 5 * 1000 ) ;
206
208
}
207
-
209
+
208
210
expect ( createObjects ( "Callback1178" ) ) . toBe ( true ) ;
209
211
expect ( createObjects ( "Callback1179" ) ) . toBe ( true ) ;
210
212
gc ( ) ;
211
213
java . lang . System . gc ( ) ;
212
214
} ) ;
213
-
215
+
214
216
it ( "testAccessingStringFieldWontLeak" , function ( ) {
215
-
217
+
216
218
__log ( "TEST: testAccessingStringFieldWontLeak" ) ;
217
219
218
220
var dummy = new com . tns . tests . DummyClass ( ) ;
219
-
221
+
220
222
for ( var i = 0 ; i < 10000 ; i ++ )
221
223
{
222
224
var name = dummy . nameField ;
223
-
225
+
224
226
expect ( name ) . toBe ( "dummy" ) ;
225
227
}
226
228
} ) ;
227
229
228
230
xit ( "should persist JavaScript object when it reappears after GC" , function ( ) {
229
-
231
+
230
232
function getObject ( ) {
231
233
var o = new java . lang . Object ( ) ;
232
234
o . x = 123 ;
@@ -287,7 +289,7 @@ describe("Tests garbage collection", function () {
287
289
gc ( ) ;
288
290
java . lang . System . gc ( ) ;
289
291
} )
290
-
292
+
291
293
it ( "should properly reintroduce Java object back in a callback" , function ( ) {
292
294
function getTestObject ( ) {
293
295
return new com . tns . tests . BadEqualsTest (
@@ -300,19 +302,19 @@ describe("Tests garbage collection", function () {
300
302
}
301
303
302
304
var test = getTestObject ( ) ;
303
-
305
+
304
306
// flush LRU cache
305
307
for ( var i = 0 ; i < 65536 ; i ++ ) {
306
308
new java . lang . Object ( ) . hashCode ( ) ;
307
309
}
308
-
310
+
309
311
gc ( ) ;
310
312
java . lang . Runtime . getRuntime ( ) . gc ( ) ;
311
313
gc ( ) ;
312
314
java . lang . Runtime . getRuntime ( ) . gc ( ) ;
313
315
gc ( ) ;
314
316
java . lang . Runtime . getRuntime ( ) . gc ( ) ;
315
-
317
+
316
318
test . postCallback ( ) ;
317
319
} ) ;
318
320
} ) ;
0 commit comments