Changeset 182661 in webkit


Ignore:
Timestamp:
Apr 11, 2015 12:43:34 PM (9 years ago)
Author:
Yusuke Suzuki
Message:

Run flaky conservative GC related test first before polluting stack and registers
https://bugs.webkit.org/show_bug.cgi?id=143634

Reviewed by Ryosuke Niwa.

After r182653, JSC API tests fail. However, it's not related to the change.
After investigating the cause of this failure, I've found that the failed test is flaky
because JSC's GC is conservative. If previously allocated JSGlobalObject is accidentally alive
due to conservative roots in C stack and registers, this test fails.

Since GC marks C stack and registers as roots conservatively,
objects not referenced logically can be accidentally marked and alive.
To avoid this situation as possible as we can,

  1. run this test first before stack is polluted,
  2. extract this test as a function to suppress stack height.
  • API/tests/testapi.mm:

(testWeakValue):
(testObjectiveCAPIMain):
(testObjectiveCAPI):

Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/tests/testapi.mm

    r182336 r182661  
    485485}
    486486
    487 void testObjectiveCAPI()
    488 {
    489     NSLog(@"Testing Objective-C API");
     487// This test is flaky. Since GC marks C stack and registers as roots conservatively,
     488// objects not referenced logically can be accidentally marked and alive.
     489// To avoid this situation as possible as we can,
     490// 1. run this test first before stack is polluted,
     491// 2. extract this test as a function to suppress stack height.
     492static void testWeakValue()
     493{
     494    @autoreleasepool {
     495        JSVirtualMachine *vm = [[JSVirtualMachine alloc] init];
     496        TestObject *testObject = [TestObject testObject];
     497        JSManagedValue *weakValue;
     498        @autoreleasepool {
     499            JSContext *context = [[JSContext alloc] initWithVirtualMachine:vm];
     500            context[@"testObject"] = testObject;
     501            weakValue = [[JSManagedValue alloc] initWithValue:context[@"testObject"]];
     502        }
     503
     504        @autoreleasepool {
     505            JSContext *context = [[JSContext alloc] initWithVirtualMachine:vm];
     506            context[@"testObject"] = testObject;
     507            JSSynchronousGarbageCollectForDebugging([context JSGlobalContextRef]);
     508            checkResult(@"weak value == nil", ![weakValue value]);
     509            checkResult(@"root is still alive", !context[@"testObject"].isUndefined);
     510        }
     511    }
     512}
     513
     514static void testObjectiveCAPIMain()
     515{
    490516    @autoreleasepool {
    491517        JSVirtualMachine* vm = [[JSVirtualMachine alloc] init];
     
    10601086            JSValue *result = [context evaluateScript:@"didClick"];
    10611087            checkResult(@"Event handler onclick doesn't fire", ![result toBool]);
    1062         }
    1063     }
    1064 
    1065     @autoreleasepool {
    1066         JSVirtualMachine *vm = [[JSVirtualMachine alloc] init];
    1067         TestObject *testObject = [TestObject testObject];
    1068         JSManagedValue *weakValue;
    1069         @autoreleasepool {
    1070             JSContext *context = [[JSContext alloc] initWithVirtualMachine:vm];
    1071             context[@"testObject"] = testObject;
    1072             weakValue = [[JSManagedValue alloc] initWithValue:context[@"testObject"]];
    1073         }
    1074 
    1075         @autoreleasepool {
    1076             JSContext *context = [[JSContext alloc] initWithVirtualMachine:vm];
    1077             context[@"testObject"] = testObject;
    1078             JSSynchronousGarbageCollectForDebugging([context JSGlobalContextRef]);
    1079             checkResult(@"weak value == nil", ![weakValue value]);
    1080             checkResult(@"root is still alive", !context[@"testObject"].isUndefined);
    10811088        }
    10821089    }
     
    14101417}
    14111418
     1419void testObjectiveCAPI()
     1420{
     1421    NSLog(@"Testing Objective-C API");
     1422    testWeakValue();
     1423    testObjectiveCAPIMain();
     1424}
     1425
    14121426#else
    14131427
  • trunk/Source/JavaScriptCore/ChangeLog

    r182660 r182661  
     12015-04-11  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        Run flaky conservative GC related test first before polluting stack and registers
     4        https://bugs.webkit.org/show_bug.cgi?id=143634
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        After r182653, JSC API tests fail. However, it's not related to the change.
     9        After investigating the cause of this failure, I've found that the failed test is flaky
     10        because JSC's GC is conservative. If previously allocated JSGlobalObject is accidentally alive
     11        due to conservative roots in C stack and registers, this test fails.
     12
     13        Since GC marks C stack and registers as roots conservatively,
     14        objects not referenced logically can be accidentally marked and alive.
     15        To avoid this situation as possible as we can,
     16        1. run this test first before stack is polluted,
     17        2. extract this test as a function to suppress stack height.
     18
     19        * API/tests/testapi.mm:
     20        (testWeakValue):
     21        (testObjectiveCAPIMain):
     22        (testObjectiveCAPI):
     23
    1242015-04-11  Matt Baker  <mattbaker@apple.com>
    225
Note: See TracChangeset for help on using the changeset viewer.