ee6a907611
big global change, so let me explain in more detail. This refactoring CL does the following: - moves all the dart code for isolates in a common library (lib/isolate) - changes frog to understand 'dart:isolate' imoprts by loading the code from the location above. - changes the vm to undernstand 'dart:isolate' imports by creating a separate library that is part of the bootstrap. This follows the same code-structure that Todd suggested in his CL introducing the mirror library - changes dartc to use the shared isolate library as the source of truth for type checking. I left around some of the internal js code in dartc so that the backend continues to work for apps that don't use isolates. - changes all tests that use isolates to import the library explicitly (this is a large bulk of the files in this CL) - changes test status for tests we can't fix in this repo (e.g. co19) - splits the isolate library code to make it possible to preserve some tests without exposing internal types (e.g. tests about serialization/deserialization) - changes the create_sdk script to copy the isolate library to the sdk - includes the isolate library in dartdoc I'll wait for at least one lgtm from each area (dartc, vm, frog, sdk) There is one important pending thing this CL doesn't do: - update test_runner.dart: This should be updated next time we upload the new binaries to tool/testing/bin - dartium specific changes: Vijay, is there anything I need to do for dartium? Review URL: https://chromiumcodereview.appspot.com//9422019 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4647 260f80e4-7a28-3924-810f-c04153c831b5
157 lines
3.4 KiB
Dart
157 lines
3.4 KiB
Dart
// Copyright (c) 2011, 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.
|
|
|
|
#library('MandelIsolateTest');
|
|
#import('dart:isolate');
|
|
#import('TestFramework.dart');
|
|
|
|
final TERMINATION_MESSAGE = -1;
|
|
final N = 100;
|
|
final ISOLATES = 20;
|
|
|
|
void test(TestExpectation expect) {
|
|
final state = new MandelbrotState();
|
|
expect.completes(state._validated.future).then((result) {
|
|
Expect.isTrue(result);
|
|
expect.succeeded();
|
|
});
|
|
for (int i = 0; i < Math.min(ISOLATES, N); i++) state.startClient(i);
|
|
}
|
|
|
|
|
|
class MandelbrotState {
|
|
|
|
MandelbrotState() {
|
|
_result = new List<List<int>>(N);
|
|
_lineProcessedBy = new List<LineProcessorClient>(N);
|
|
_sent = 0;
|
|
_missing = N;
|
|
_validated = new Completer<bool>();
|
|
}
|
|
|
|
void startClient(int id) {
|
|
assert(_sent < N);
|
|
final client = new LineProcessorClient(this, id);
|
|
client.processLine(_sent++);
|
|
}
|
|
|
|
void notifyProcessedLine(LineProcessorClient client, int y, List<int> line) {
|
|
assert(_result[y] === null);
|
|
_result[y] = line;
|
|
_lineProcessedBy[y] = client;
|
|
|
|
if (_sent != N) {
|
|
client.processLine(_sent++);
|
|
} else {
|
|
client.shutdown();
|
|
}
|
|
|
|
// If all lines have been computed, validate the result.
|
|
if (--_missing == 0) {
|
|
_printResult();
|
|
_validateResult();
|
|
}
|
|
}
|
|
|
|
void _validateResult() {
|
|
// TODO(ngeoffray): Implement this.
|
|
_validated.complete(true);
|
|
}
|
|
|
|
void _printResult() {
|
|
var output = new StringBuffer();
|
|
for (int i = 0; i < _result.length; i++) {
|
|
List<int> line = _result[i];
|
|
for (int j = 0; j < line.length; j++) {
|
|
if (line[j] < 10) output.add("0");
|
|
output.add(line[j]);
|
|
}
|
|
output.add("\n");
|
|
}
|
|
// print(output);
|
|
}
|
|
|
|
List<List<int>> _result;
|
|
List<LineProcessorClient> _lineProcessedBy;
|
|
int _sent;
|
|
int _missing;
|
|
Completer<bool> _validated;
|
|
}
|
|
|
|
|
|
class LineProcessorClient {
|
|
|
|
LineProcessorClient(MandelbrotState this._state, int this._id) {
|
|
_out = new LineProcessor().spawn();
|
|
}
|
|
|
|
void processLine(int y) {
|
|
_out.then((SendPort p) {
|
|
p.call(y).receive((List<int> message, SendPort replyTo) {
|
|
_state.notifyProcessedLine(this, y, message);
|
|
});
|
|
});
|
|
}
|
|
|
|
void shutdown() {
|
|
_out.then((SendPort p) {
|
|
p.send(TERMINATION_MESSAGE, null);
|
|
});
|
|
}
|
|
|
|
MandelbrotState _state;
|
|
int _id;
|
|
Future<SendPort> _out;
|
|
|
|
}
|
|
|
|
|
|
class LineProcessor extends Isolate {
|
|
|
|
LineProcessor() : super() { }
|
|
|
|
void main() {
|
|
this.port.receive((message, SendPort replyTo) {
|
|
if (message == TERMINATION_MESSAGE) {
|
|
assert(replyTo == null);
|
|
this.port.close();
|
|
} else {
|
|
replyTo.send(_processLine(message), null);
|
|
}
|
|
});
|
|
}
|
|
|
|
static List<int> _processLine(int y) {
|
|
double inverseN = 2.0 / N;
|
|
double Civ = y * inverseN - 1.0;
|
|
List<int> result = new List<int>(N);
|
|
for (int x = 0; x < N; x++) {
|
|
double Crv = x * inverseN - 1.5;
|
|
|
|
double Zrv = Crv;
|
|
double Ziv = Civ;
|
|
|
|
double Trv = Crv * Crv;
|
|
double Tiv = Civ * Civ;
|
|
|
|
int i = 49;
|
|
do {
|
|
Ziv = (Zrv * Ziv) + (Zrv * Ziv) + Civ;
|
|
Zrv = Trv - Tiv + Crv;
|
|
|
|
Trv = Zrv * Zrv;
|
|
Tiv = Ziv * Ziv;
|
|
} while (((Trv + Tiv) <= 4.0) && (--i > 0));
|
|
|
|
result[x] = i;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
}
|
|
|
|
main() {
|
|
runTests([test]);
|
|
}
|