Remove dependencies on isolates.

This starts removing support for isolates. I've kept around the
isolate library for now, but I stopped injecting the isolate logic
unless you directly access an isolate API.

Concrete changes:

* Timer no longer uses the event queue: this was only used in worker
isolates, soon to be removed.

* Checking for whether the code is run within a worker is not dependent
   on initializing the isolates global state. This was important to allow
   deferred-loading to work without the isolate logic.

* Workers no longer track pending async calls correctly. This may make it possible
   to terminate worker isolates early, again this wont be relevant shortly.

Bug: https://github.com/dart-lang/sdk/issues/32684
Change-Id: I05025418e05c3641ba1a3bc34ea75ca558a28fbd
Reviewed-on: https://dart-review.googlesource.com/54160
Commit-Queue: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
This commit is contained in:
Sigmund Cherem 2018-05-09 16:36:26 +00:00 committed by commit-bot@chromium.org
parent 2ad715e706
commit 3ec1b929e3
9 changed files with 30 additions and 128 deletions

View file

@ -312,26 +312,14 @@ class ResolutionEnqueuerListener extends EnqueuerListener {
}
// Enable isolate support if we start using something from the isolate
// library, or timers for the async library. We exclude constant fields,
// which are ending here because their initializing expression is
// compiled.
LibraryEntity library = member.library;
if (!_backendUsage.isIsolateInUse && !(member.isField && member.isConst)) {
Uri uri = library.canonicalUri;
if (uri == Uris.dart_isolate) {
_backendUsage.isIsolateInUse = true;
worldImpact
.addImpact(_enableIsolateSupport(_elementEnvironment.mainFunction));
} else if (uri == Uris.dart_async) {
if (member.name == '_createTimer' ||
member.name == '_createPeriodicTimer') {
// The [:Timer:] class uses the event queue of the isolate
// library, so we make sure that event queue is generated.
_backendUsage.isIsolateInUse = true;
worldImpact.addImpact(
_enableIsolateSupport(_elementEnvironment.mainFunction));
}
}
// library. We exclude constant fields, which are ending here because their
// initializing expression is compiled.
if (!_backendUsage.isIsolateInUse &&
!(member.isField && member.isConst) &&
member.library.canonicalUri == Uris.dart_isolate) {
_backendUsage.isIsolateInUse = true;
worldImpact
.addImpact(_enableIsolateSupport(_elementEnvironment.mainFunction));
}
if (member.isGetter && member.name == Identifiers.runtimeType_) {
@ -437,6 +425,10 @@ class ResolutionEnqueuerListener extends EnqueuerListener {
_interceptorData.addInterceptorsForNativeClassMembers(cls);
} else if (cls == _commonElements.jsIndexingBehaviorInterface) {
_registerBackendImpact(impactBuilder, _impacts.jsIndexingBehavior);
} else if (cls.library.canonicalUri == Uris.dart_isolate) {
_backendUsage.isIsolateInUse = true;
impactBuilder
.addImpact(_enableIsolateSupport(_elementEnvironment.mainFunction));
}
_customElementsAnalysis.registerInstantiatedClass(cls);

View file

@ -72,20 +72,15 @@ _callInIsolate(_IsolateContext isolate, Function function) {
///
/// These functions only has to be called for code that can be run from a
/// worker-isolate (so not for general dom operations).
enterJsAsync() {
_globalState.topEventLoop._activeJsAsyncCount++;
}
enterJsAsync() {}
/// Marks leaving a javascript async operation.
///
/// See [enterJsAsync].
leaveJsAsync() {
_globalState.topEventLoop._activeJsAsyncCount--;
assert(_globalState.topEventLoop._activeJsAsyncCount >= 0);
}
leaveJsAsync() {}
/// Returns true if we are currently in a worker context.
bool isWorker() => _globalState.isWorker;
bool isWorker() => globalWindow == null && globalPostMessageDefined;
/**
* Called by the compiler to fetch the current isolate context.
@ -787,7 +782,7 @@ class IsolateNatives {
return JS('String', 'String(#.src)', currentScript);
}
// A worker has no script tag - so get an url from a stack-trace.
if (_globalState.isWorker) return computeThisScriptFromTrace();
if (isWorker()) return computeThisScriptFromTrace();
// An isolate that doesn't support workers, but doesn't have a
// currentScript either. This is most likely a Chrome extension.
return null;
@ -1372,31 +1367,11 @@ class ReceivePortImpl extends Stream implements ReceivePort {
class TimerImpl implements Timer {
final bool _once;
bool _inEventLoop = false;
int _handle;
int _tick = 0;
TimerImpl(int milliseconds, void callback()) : _once = true {
if (milliseconds == 0 && (!hasTimer() || _globalState.isWorker)) {
void internalCallback() {
_handle = null;
callback();
}
// Setting _handle to something different from null indicates that the
// callback has not been run. Hence, the choice of 1 is arbitrary.
_handle = 1;
// This makes a dependency between the async library and the
// event loop of the isolate library. The compiler makes sure
// that the event loop is compiled if [Timer] is used.
// TODO(7907): In case of web workers, we need to use the event
// loop instead of setTimeout, to make sure the futures get executed in
// order.
_globalState.topEventLoop
.enqueue(_globalState.currentContext, internalCallback, 'timer');
_inEventLoop = true;
} else if (hasTimer()) {
if (hasTimer()) {
void internalCallback() {
_handle = null;
leaveJsAsync();
@ -1409,8 +1384,7 @@ class TimerImpl implements Timer {
_handle = JS('int', 'self.setTimeout(#, #)',
convertDartClosureToJS(internalCallback, 0), milliseconds);
} else {
assert(milliseconds > 0);
throw new UnsupportedError('Timer greater than 0.');
throw new UnsupportedError('`setTimeout()` not found.');
}
}
@ -1443,9 +1417,6 @@ class TimerImpl implements Timer {
void cancel() {
if (hasTimer()) {
if (_inEventLoop) {
throw new UnsupportedError('Timer in event loop cannot be canceled.');
}
if (_handle == null) return;
leaveJsAsync();
if (_once) {

View file

@ -188,7 +188,8 @@ LibTest/isolate/Isolate/spawnUri_A01_t06: RuntimeError # Dart issue 15974
LibTest/isolate/Isolate/spawnUri_A01_t07: RuntimeError # Dart issue 15974
LibTest/isolate/Isolate/spawnUri_A02_t01: RuntimeError, Pass # Dart issue 15617
LibTest/isolate/Isolate/spawn_A02_t02: RuntimeError, Pass # Dart issue 15617
LibTest/isolate/Isolate/spawn_A04_t01: RuntimeError # Dart issue 15974
LibTest/isolate/Isolate/spawn_A04_t01: SkipByDesign
LibTest/isolate/Isolate/spawn_A04_t02: SkipByDesign
LibTest/isolate/Isolate/spawn_A06_t06: Skip # Times out. Please triage this failure.
LibTest/math/MutableRectangle/boundingBox_A01_t01: RuntimeError, Pass # co19-roll r706: Please triage this failure.
LibTest/math/Rectangle/boundingBox_A01_t01: RuntimeError, Pass # co19-roll r706: Please triage this failure.

View file

@ -43,7 +43,6 @@ no_such_method_mirrors_test: Pass, Slow # TODO(kasperl): Please triage.
[ $compiler == dart2js && $runtime == d8 && $fasta ]
deferred_fail_and_retry_test: RuntimeError # Uses XHR in dart:html
deferred_fail_and_retry_worker_test: Fail # Uses XHR in dart:html
unconditional_dartio_import_test: RuntimeError # Uses dart:io
[ $compiler == dart2js && $runtime == ff && $system == windows ]
@ -52,9 +51,6 @@ consistent_index_error_string_test: Pass, Slow # Issue 25940
[ $compiler == dart2js && $runtime == none ]
*: Fail, Pass # TODO(ahe): Triage these tests.
[ $compiler == dart2js && $runtime == safari ]
deferred_fail_and_retry_worker_test: Timeout # Issue 22106
[ $compiler == dart2js && $checked ]
variable_type_test/01: Fail, OK
variable_type_test/03: Fail, OK
@ -77,7 +73,6 @@ closure_signature_unneeded_test: RuntimeError # Too eager signature generation.
[ $compiler == dart2js && $csp ]
deferred_custom_loader_test: SkipByDesign # Issue 25683
deferred_fail_and_retry_test: SkipByDesign # Uses eval to simulate failed loading.
deferred_fail_and_retry_worker_test: SkipByDesign # Uses eval to simulate failed loading.
js_interop_optional_arg_test: RuntimeError # Issue 31082
js_interop_test: RuntimeError # Issue 31082

View file

@ -1,60 +0,0 @@
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test that when a deferred import from a worker fails to load, it is possible
// to retry.
import "deferred_fail_and_retry_lib.dart" deferred as lib;
import "package:expect/expect.dart";
import "package:async_helper/async_helper.dart";
import "dart:isolate";
import "dart:js" as js;
void test(SendPort sendPort) {
// Patch XMLHttpRequest to fail on first load.
js.context.callMethod("eval", [
"""
oldXMLHttpRequest = XMLHttpRequest;
XMLHttpRequest = function() {
XMLHttpRequest = oldXMLHttpRequest;
var instance = new XMLHttpRequest();
this.addEventListener = function(x, y, z) {
instance.addEventListener(x, y, z);
}
this.send = function() {
instance.send();
}
this.open = function(x, uri) {
instance.open(x, "non_existing.js");
}
}
"""
]);
lib.loadLibrary().then((_) {
sendPort.send("Library should not have loaded");
}, onError: (error) {
sendPort.send("failed");
lib.loadLibrary().then((_) {
sendPort.send(lib.foo());
}, onError: (error) {
sendPort.send("Library should have loaded this time $error");
});
});
}
main() {
ReceivePort receivePort = new ReceivePort();
asyncStart();
bool receivedFailed = false;
receivePort.listen((message) {
if (!receivedFailed) {
Expect.equals("failed", message);
receivedFailed = true;
} else {
Expect.equals("loaded", message);
asyncEnd();
}
});
Isolate.spawn(test, receivePort.sendPort);
}

View file

@ -14,9 +14,6 @@ native_no_such_method_exception5_frog_test: SkipByDesign # mirrors not supported
[ $browser ]
*: Skip
[ $compiler == dart2js && $runtime == d8 && $system == windows && !$fasta ]
compute_this_script_test: Skip # Issue 17458
[ $compiler == dart2js && $fasta ]
native_library_same_name_used_frog_test: CompileTimeError
subclassing_constructor_1_test: RuntimeError
@ -24,8 +21,5 @@ subclassing_super_call_test: RuntimeError
subclassing_super_field_1_test: RuntimeError
subclassing_super_field_2_test: RuntimeError
[ $compiler == dart2js && $fasta && $host_checked ]
compute_this_script_test: Crash # 'file:*/pkg/compiler/lib/src/ssa/types.dart': Failed assertion: line 63 pos 12: '!result.isEmpty': is not true.
[ $compiler == dart2js && $minified ]
optimization_hints_test: RuntimeError, OK # Test relies on unminified names.

View file

@ -26,6 +26,8 @@ webgl_1_test: StaticWarning
window_nosuchmethod_test: StaticWarning
[ $compiler == dart2js ]
async_spawnuri_test: SkipByDesign
async_test: SkipByDesign
custom/document_register_type_extensions_test/construction: Pass, Timeout # Roll 50 failure
custom/document_register_type_extensions_test/registration: Pass, Timeout # Roll 50 failure
custom/entered_left_view_test/shadow_dom: Pass, Timeout # Roll 50 failure
@ -194,7 +196,6 @@ xhr_test/json: Fail # TODO(dart2js-team): Please triage this failure.
[ $compiler == dart2js && $runtime == d8 && $fasta ]
async_spawnuri_test: RuntimeError
async_test: RuntimeError
audiobuffersourcenode_test: RuntimeError
audiocontext_test: RuntimeError
audioelement_test: RuntimeError

View file

@ -7,6 +7,7 @@ browser/typed_data_message_test: StaticWarning
[ $compiler == dart2js ]
browser/issue_12474_test: CompileTimeError # Issue 22529
deferred_in_isolate2_test: SkipByDesign
enum_const_test/02: RuntimeError # Issue 21817
error_at_spawnuri_test: SkipByDesign # Test uses a ".dart" URI.
error_exit_at_spawnuri_test: SkipByDesign # Test uses a ".dart" URI.
@ -23,9 +24,11 @@ message3_test/constList_identical: RuntimeError # Issue 21817
message3_test/constMap: RuntimeError # Issue 21817
non_fatal_exception_in_timer_callback_test: Skip # Issue 23876
spawn_uri_exported_main_test: SkipByDesign # Test uses a ".dart" URI.
spawn_uri_missing_from_isolate_test: SkipByDesign
spawn_uri_nested_vm_test: SkipByDesign # Test uses a ".dart" URI.
spawn_uri_vm_test: SkipByDesign # Test uses a ".dart" URI.
stacktrace_message_test: RuntimeError # Fails to send stacktrace object.
timer_isolate_test: SkipByDesign
[ $compiler == fasta ]
browser/compute_this_script_browser_test: CompileTimeError # TODO(ahe): Support dart:html in Fasta.

View file

@ -8,6 +8,8 @@ convert/base64_test/01: Fail, OK # Uses bit-wise operations to detect invalid va
convert/chunked_conversion_utf88_test: Slow, Pass
convert/utf85_test: Slow, Pass
developer/timeline_test: Skip # Not supported
html/async_spawnuri_test: SkipByDesign
html/async_test: SkipByDesign
html/custom/document_register_type_extensions_test/construction: Pass, Timeout # Roll 50 failure
html/custom/document_register_type_extensions_test/registration: Pass, Timeout # Roll 50 failure
html/custom/element_upgrade_failure_test: MissingCompileTimeError
@ -26,6 +28,7 @@ html/svgelement_test/PathElement: Pass, RuntimeError # Roll 50 failure
html/wrapping_collections_test: SkipByDesign # Testing an issue that is only relevant to Dartium
html/xhr_test: Pass, Slow
isolate/browser/issue_12474_test: CompileTimeError # Issue 22529
isolate/deferred_in_isolate2_test: SkipByDesign
isolate/enum_const_test/02: RuntimeError # Issue 21817
isolate/error_at_spawnuri_test: SkipByDesign # Test uses a ".dart" URI.
isolate/error_exit_at_spawnuri_test: SkipByDesign # Test uses a ".dart" URI.
@ -42,9 +45,11 @@ isolate/message3_test/constList_identical: RuntimeError # Issue 21817
isolate/message3_test/constMap: RuntimeError # Issue 21817
isolate/non_fatal_exception_in_timer_callback_test: Skip # Issue 23876
isolate/spawn_uri_exported_main_test: SkipByDesign # Test uses a ".dart" URI.
isolate/spawn_uri_missing_from_isolate_test: SkipByDesign
isolate/spawn_uri_nested_vm_test: SkipByDesign # Test uses a ".dart" URI.
isolate/spawn_uri_vm_test: SkipByDesign # Test uses a ".dart" URI.
isolate/stacktrace_message_test: RuntimeError # Fails to send stacktrace object.
isolate/timer_isolate_test: SkipByDesign
math/double_pow_test: RuntimeError
math/low_test: RuntimeError
math/random_big_test: RuntimeError # Using bigint seeds for random.