Skip to content

Commit 06493ef

Browse files
committed
feat: Run GC tests only in Full marking mode
1 parent 00ae9c1 commit 06493ef

File tree

4 files changed

+64
-56
lines changed

4 files changed

+64
-56
lines changed

test-app/app/src/main/assets/app/tests/testGC.js

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
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 () {
35
var myCustomEquality = function(first, second) {
46
return first == second;
57
};
6-
8+
79
beforeEach(function() {
810
jasmine.addCustomEqualityTester(myCustomEquality);
911
});
1012

1113
xit("TestGarbageCollection", function (done) {
12-
var normalTest = function () {
14+
var normalTest = function () {
1315

1416
__log("TEST: TestGarbageCollection");
15-
17+
1618
var obj = new com.tns.tests.ClassX();
17-
19+
1820
obj.dummy();
19-
21+
2022
obj = null;
21-
23+
2224
gc();
2325
java.lang.System.gc();
2426
gc();
2527
java.lang.System.gc();
2628
gc();
2729
java.lang.System.gc();
28-
30+
2931
new java.lang.Thread(new java.lang.Runnable("ThreadFunc", {
3032
run: function() {
3133
var isCollected = com.tns.tests.ClassX.IsCollected;
@@ -37,62 +39,62 @@ describe("Tests garbage collection", function () {
3739
};
3840
normalTest();
3941
});
40-
42+
4143
// this test has implicit assert in com.tns.Runtime.getJavaObjectByID method
4244
it("test1", function () {
43-
45+
4446
function createObjects(name) {
4547
var c1 = new com.tns.tests.Class1();
46-
48+
4749
var cb1 = new com.tns.tests.Class1.Callback1(name, {
4850
getMessage: function() {
4951
var msg = c1.getMessage();
5052
return msg;
5153
}
5254
});
53-
55+
5456
return com.tns.tests.Class1.Class2.printMessageWithDelay(cb1, 5 * 1000);
5557
}
56-
58+
5759
expect(createObjects("Callback5")).toBe(true);
5860
expect(createObjects("Callback26")).toBe(true);
59-
61+
6062
gc();
6163
java.lang.System.gc();
6264
});
63-
65+
6466
// this test has implicit assert in com.tns.Runtime.getJavaObjectByID method
6567
it("test2", function () {
66-
68+
6769
function indref1() {
6870
this.class1 = new com.tns.tests.Class1();
6971
}
7072
indref1.prototype.getMessage = function() {
7173
return "~~~" + this.class1.getMessage();
7274
}
73-
75+
7476
function createObjects(name) {
7577
var c1 = new indref1();
76-
78+
7779
var cb1 = new com.tns.tests.Class1.Callback1(name, {
7880
getMessage: function() {
7981
var msg = c1.getMessage();
8082
return msg;
8183
}
8284
});
83-
85+
8486
return com.tns.tests.Class1.Class2.printMessageWithDelay(cb1, 5 * 1000);
8587
}
86-
88+
8789
expect(createObjects("Callback55")).toBe(true);
8890
expect(createObjects("Callback56")).toBe(true);
8991
gc();
9092
java.lang.System.gc();
9193
});
92-
94+
9395
// this test has implicit assert in com.tns.Runtime.getJavaObjectByID method
9496
it("test3", function () {
95-
97+
9698
function indref2() {
9799
this.helper = new indref2helper();
98100
}
@@ -105,29 +107,29 @@ describe("Tests garbage collection", function () {
105107
indref2helper.prototype.getMessage = function() {
106108
return "***" + this.class1.getMessage();
107109
}
108-
110+
109111
function createObjects(name) {
110112
var c1 = new indref2();
111-
113+
112114
var cb1 = new com.tns.tests.Class1.Callback1(name, {
113115
getMessage: function() {
114116
var msg = c1.getMessage();
115117
return msg;
116118
}
117119
});
118-
120+
119121
return com.tns.tests.Class1.Class2.printMessageWithDelay(cb1, 5 * 1000);
120122
}
121-
123+
122124
expect(createObjects("Callback91")).toBe(true);
123125
expect(createObjects("Callback92")).toBe(true);
124126
gc();
125127
java.lang.System.gc();
126128
});
127-
129+
128130
// this test has implicit assert in com.tns.Runtime.getJavaObjectByID method
129131
it("test4", function () {
130-
132+
131133
function indref3() {
132134
this.helper = new indref3helper();
133135
}
@@ -136,97 +138,97 @@ describe("Tests garbage collection", function () {
136138
}
137139
function indref3helper() {
138140
this._class1 = new com.tns.tests.Class1();
139-
141+
140142
Object.defineProperty(this, "class1", {
141143
get: function() {
142-
return this._class1
143-
}
144+
return this._class1
145+
}
144146
});
145147
}
146148
indref3helper.prototype.getMessage = function() {
147149
return "^^^" + this.class1.getMessage();
148-
}
149-
150+
}
151+
150152
function createObjects(name) {
151153
var c1 = new indref3();
152-
154+
153155
var cb1 = new com.tns.tests.Class1.Callback1(name, {
154156
getMessage: function() {
155157
var msg = c1.getMessage();
156158
return msg;
157159
}
158160
});
159-
161+
160162
return com.tns.tests.Class1.Class2.printMessageWithDelay(cb1, 5 * 1000);
161163
}
162-
164+
163165
expect(createObjects("Callback1133")).toBe(true);
164166
expect(createObjects("Callback1134")).toBe(true);
165167
gc();
166168
java.lang.System.gc();
167169
});
168-
170+
169171
// this test has implicit assert in com.tns.Runtime.getJavaObjectByID method
170172
//originally test was commented out
171173
xit("test5", function () {
172-
174+
173175
function indref4() {
174176
this.helper = new indref4helper();
175177
}
176178
indref4.prototype.getMessage = function() {
177179
return "&&&" + this.helper.getMessageZZZ();
178180
}
179-
function indref4helper() {
181+
function indref4helper() {
180182
var _class1 = new com.tns.tests.Class1();
181-
183+
182184
__log("indref4helper _class1=" + _class1);
183-
185+
184186
Object.defineProperty(this, "class1", {
185187
get: function() {
186-
return _class1
188+
return _class1
187189
}
188190
,enumerable: false
189191
});
190192
}
191193
indref4helper.prototype.getMessageZZZ = function() {
192194
return "```" + this.class1.getMessage();
193195
}
194-
196+
195197
function createObjects(name) {
196198
var c1 = new indref4();
197-
199+
198200
var cb1 = new com.tns.tests.Class1.Callback1(name, {
199201
getMessage: function() {
200202
var msg = c1.getMessage();
201203
return msg;
202204
}
203205
});
204-
206+
205207
return com.tns.tests.Class1.Class2.printMessageWithDelay(cb1, 5 * 1000);
206208
}
207-
209+
208210
expect(createObjects("Callback1178")).toBe(true);
209211
expect(createObjects("Callback1179")).toBe(true);
210212
gc();
211213
java.lang.System.gc();
212214
});
213-
215+
214216
it("testAccessingStringFieldWontLeak", function () {
215-
217+
216218
__log("TEST: testAccessingStringFieldWontLeak");
217219

218220
var dummy = new com.tns.tests.DummyClass();
219-
221+
220222
for (var i=0; i<10000; i++)
221223
{
222224
var name = dummy.nameField;
223-
225+
224226
expect(name).toBe("dummy");
225227
}
226228
});
227229

228230
xit("should persist JavaScript object when it reappears after GC", function () {
229-
231+
230232
function getObject() {
231233
var o = new java.lang.Object();
232234
o.x = 123;
@@ -287,7 +289,7 @@ describe("Tests garbage collection", function () {
287289
gc();
288290
java.lang.System.gc();
289291
})
290-
292+
291293
it("should properly reintroduce Java object back in a callback", function () {
292294
function getTestObject() {
293295
return new com.tns.tests.BadEqualsTest(
@@ -300,19 +302,19 @@ describe("Tests garbage collection", function () {
300302
}
301303

302304
var test = getTestObject();
303-
305+
304306
// flush LRU cache
305307
for (var i=0; i<65536; i++) {
306308
new java.lang.Object().hashCode();
307309
}
308-
310+
309311
gc();
310312
java.lang.Runtime.getRuntime().gc();
311313
gc();
312314
java.lang.Runtime.getRuntime().gc();
313315
gc();
314316
java.lang.Runtime.getRuntime().gc();
315-
317+
316318
test.postCallback();
317319
});
318320
});

test-app/runtime/src/main/cpp/ObjectManager.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,3 +883,7 @@ void ObjectManager::ReleaseNativeCounterpart(v8::Local<v8::Object> &object) {
883883
auto jsInfoIdx = static_cast<int>(MetadataNodeKeys::JsInfo);
884884
object->SetInternalField(jsInfoIdx, Undefined(m_isolate));
885885
}
886+
887+
ObjectManager::JavaScriptMarkingMode ObjectManager::GetMarkingMode() {
888+
return this->m_markingMode;
889+
}

test-app/runtime/src/main/cpp/ObjectManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class ObjectManager {
7777
None
7878
};
7979

80+
JavaScriptMarkingMode GetMarkingMode();
8081
private:
8182

8283
struct JSInstanceInfo {

test-app/runtime/src/main/cpp/Runtime.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& native
597597
globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__runtimeVersion"), ArgConverter::ConvertToV8String(isolate, NATIVE_SCRIPT_RUNTIME_VERSION), readOnlyFlags);
598598
globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__time"), FunctionTemplate::New(isolate, CallbackHandlers::TimeCallback));
599599
globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__releaseNativeCounterpart"), FunctionTemplate::New(isolate, CallbackHandlers::ReleaseNativeCounterpartCallback));
600+
globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__markingMode"), Number::New(isolate, m_objectManager->GetMarkingMode()), readOnlyFlags);
600601

601602

602603
/*

0 commit comments

Comments
 (0)