Skip to content

Commit eeff415

Browse files
authored
Merge pull request #750 from NativeScript/release
Merge branch 'release' into master
2 parents 3e29d0a + df627ec commit eeff415

File tree

7 files changed

+80
-7
lines changed

7 files changed

+80
-7
lines changed

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,24 @@ The source in this repo is organized in Android Studio projects.
2929
# How to build
3030

3131
* Run command
32-
```Shell
33-
gradlew build
34-
```
32+
33+
Windows:
34+
35+
```Shell
36+
gradlew createPackage
37+
```
38+
39+
Mac/Linux:
40+
41+
```Shell
42+
./gradlew createPackage
43+
```
44+
45+
* The build process includes building of the runtime package (both optimized and with unstripped v8 symbol table), as well as all supplementary tools used for the android builds: metadata-generator, binding-generator, metadata-generator, static-binding-generator
3546
* The result of the build will be in the dist folder.
3647

48+
`Note:` To cut the build time in half and package only the optimized (stripped) version of the runtime package comment out 'tasks.generateRuntimeAar.execute()' in the [build.gradle](https://github.com/NativeScript/android-runtime/blob/v3.0.0-rc.1/build.gradle#L114) script.
49+
3750
# How to run tests
3851

3952
* Go to subfolder test-app after you built the runtime.
@@ -42,5 +55,5 @@ gradlew build
4255
``Note: Keep in mind the device or emulator needs to have an sdcard mounted.``
4356
* Run command
4457
```Shell
45-
gradle runtest
58+
gradlew runtest
4659
```

build-artifacts/project-template-gradle/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,8 @@ task copyAarDependencies (type: Copy) {
500500
Object[] files = Files.find(
501501
Paths.get("$projectDir", "$nodeModulesDir"),
502502
Integer.MAX_VALUE,
503-
filterAarFilesFn
503+
filterAarFilesFn,
504+
java.nio.file.FileVisitOption.FOLLOW_LINKS
504505
)
505506
.map(mapToStringFn)
506507
.toArray();

build-artifacts/project-template-gradle/src/main/java/com/tns/NativeScriptSyncService.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ public void run() {
128128
int length = input.readInt();
129129
input.readFully(new byte[length]); // ignore the payload
130130
executePartialSync(context, syncDir);
131+
// delete temporary /sync dir after syncing .xml/.css resources
132+
deleteRecursive(syncDir);
131133
executeRemovedSync(context, removedSyncDir);
134+
// delete temporary /removedsync dir after removing files from the project
135+
deleteRecursive(removedSyncDir);
132136

133137
runtime.runScript(new File(NativeScriptSyncService.this.context.getFilesDir(), "internal/livesync.js"));
134138
try {
@@ -157,7 +161,11 @@ private void deleteRecursive(File fileOrDirectory) {
157161
}
158162
}
159163

160-
fileOrDirectory.delete();
164+
boolean success = fileOrDirectory.delete();
165+
166+
if (!success && fileOrDirectory.isDirectory()) {
167+
android.util.Log.d("Sync", "Failed to delete temp sync directory: " + fileOrDirectory.getAbsolutePath());
168+
}
161169
}
162170

163171
public static boolean isSyncEnabled(Context context) {

runtime/src/main/jni/ObjectManager.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,10 @@ void ObjectManager::MarkReachableObjects(Isolate* isolate, const Local<Object>&
460460
NativeScriptExtension::ReleaseClosureObjects(closureObjects);
461461
}
462462

463+
if (o->IsArray()) {
464+
MarkReachableArrayElements(o, s);
465+
}
466+
463467
auto proto = o->GetPrototype();
464468
if (!proto.IsEmpty() && !proto->IsNull() && !proto->IsUndefined() && proto->IsObject()) {
465469
s.push(proto);
@@ -518,6 +522,19 @@ void ObjectManager::MarkReachableObjects(Isolate* isolate, const Local<Object>&
518522
} // while
519523
}
520524

525+
void ObjectManager::MarkReachableArrayElements(Local<Object> &o, stack<Local<Value>> &s) {
526+
auto arr = o.As<Array>();
527+
528+
int arrEnclosedObjectsLength = arr->Length();
529+
for (int i = 0; i < arrEnclosedObjectsLength; i++) {
530+
auto enclosedElement = arr->Get(i);
531+
532+
if (!enclosedElement.IsEmpty() && enclosedElement->IsObject()) {
533+
s.push(enclosedElement);
534+
}
535+
}
536+
}
537+
521538
void ObjectManager::OnGcStartedStatic(Isolate* isolate, GCType type, GCCallbackFlags flags) {
522539
try {
523540
auto runtime = Runtime::GetRuntime(isolate);

runtime/src/main/jni/ObjectManager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,15 @@ class ObjectManager {
4949

5050
v8::Local<v8::Object> GetEmptyObject(v8::Isolate* isolate);
5151

52+
static void MarkReachableArrayElements(v8::Local<v8::Object> &o, std::stack<v8::Local<v8::Value>> &s);
53+
5254
enum class MetadataNodeKeys {
5355
JsInfo,
5456
CallSuper,
5557
END
5658
};
5759

60+
5861
private:
5962

6063
struct JSInstanceInfo {

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,29 @@ describe("Tests garbage collection", function () {
264264
gc();
265265
java.lang.System.gc();
266266
});
267+
268+
it("should keep array-enclosed objects alive after GC", function () {
269+
function createObjects(name) {
270+
var arr = new Array();
271+
arr.push(new com.tns.tests.Class1());
272+
273+
var cb1 = new com.tns.tests.Class1.Callback1(name, {
274+
getMessage: function() {
275+
var msg = arr[0].getMessage();
276+
return msg;
277+
}
278+
});
279+
280+
return com.tns.tests.Class1.Class2.printMessageWithDelay(cb1, 2 * 1000);
281+
}
282+
283+
expect(createObjects("Callback1")).toBe(true);
284+
expect(createObjects("Callback2")).toBe(true);
285+
expect(createObjects("Callback3")).toBe(true);
286+
287+
gc();
288+
java.lang.System.gc();
289+
})
267290

268291
it("should properly reintroduce Java object back in a callback", function () {
269292
function getTestObject() {

test-app/app/src/main/java/com/tns/NativeScriptSyncService.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ public void run() {
128128
int length = input.readInt();
129129
input.readFully(new byte[length]); // ignore the payload
130130
executePartialSync(context, syncDir);
131+
// delete temporary /sync dir after syncing .xml/.css resources
132+
deleteRecursive(syncDir);
131133
executeRemovedSync(context, removedSyncDir);
134+
// delete temporary /removedsync dir after removing files from the project
135+
deleteRecursive(removedSyncDir);
132136

133137
runtime.runScript(new File(NativeScriptSyncService.this.context.getFilesDir(), "internal/livesync.js"));
134138
try {
@@ -157,7 +161,11 @@ private void deleteRecursive(File fileOrDirectory) {
157161
}
158162
}
159163

160-
fileOrDirectory.delete();
164+
boolean success = fileOrDirectory.delete();
165+
166+
if (!success && fileOrDirectory.isDirectory()) {
167+
android.util.Log.d("Sync", "Failed to delete temp sync directory: " + fileOrDirectory.getAbsolutePath());
168+
}
161169
}
162170

163171
public static boolean isSyncEnabled(Context context) {

0 commit comments

Comments
 (0)