Skip to content

Commit b99599b

Browse files
a-sivacommit-bot@chromium.org
authored andcommitted
More cleanup of the loader code.
Change-Id: I8ee048f2a06f8aa54cb5efb832740a53b2bd042d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127444 Reviewed-by: Ryan Macnak <rmacnak@google.com> Reviewed-by: Ben Konyi <bkonyi@google.com> Commit-Queue: Siva Annamalai <asiva@google.com>
1 parent a3953b6 commit b99599b

File tree

7 files changed

+6
-322
lines changed

7 files changed

+6
-322
lines changed

runtime/bin/dartutils.cc

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -524,21 +524,10 @@ Dart_Handle DartUtils::SetupServiceLoadPort() {
524524
return Builtin::SetLoadPort(load_port);
525525
}
526526

527-
Dart_Handle DartUtils::SetupPackageRoot(const char* package_root,
528-
const char* packages_config) {
527+
Dart_Handle DartUtils::SetupPackageConfig(const char* packages_config) {
529528
Dart_Handle result = Dart_Null();
530529

531-
// Set up package root if specified.
532-
if (package_root != NULL) {
533-
ASSERT(packages_config == NULL);
534-
result = NewString(package_root);
535-
RETURN_IF_ERROR(result);
536-
const int kNumArgs = 1;
537-
Dart_Handle dart_args[kNumArgs];
538-
dart_args[0] = result;
539-
result = Dart_Invoke(DartUtils::LookupBuiltinLib(),
540-
NewString("_setPackageRoot"), kNumArgs, dart_args);
541-
} else if (packages_config != NULL) {
530+
if (packages_config != NULL) {
542531
result = NewString(packages_config);
543532
RETURN_IF_ERROR(result);
544533
const int kNumArgs = 1;

runtime/bin/dartutils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ class DartUtils {
152152
static Dart_Handle PrepareForScriptLoading(bool is_service_isolate,
153153
bool trace_loading);
154154
static Dart_Handle SetupServiceLoadPort();
155-
static Dart_Handle SetupPackageRoot(const char* package_root,
156-
const char* packages_file);
155+
static Dart_Handle SetupPackageConfig(const char* packages_file);
156+
157157
static Dart_Handle SetupIOLibrary(const char* namespc_path,
158158
const char* script_uri,
159159
bool disable_exit);

runtime/bin/main.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,13 @@ static Dart_Handle SetupCoreLibraries(Dart_Isolate isolate,
199199
if (Dart_IsError(result)) return result;
200200
}
201201

202-
// Setup package root if specified.
203-
result = DartUtils::SetupPackageRoot(nullptr, packages_file);
202+
// Setup packages config if specified.
203+
result = DartUtils::SetupPackageConfig(packages_file);
204204
if (Dart_IsError(result)) return result;
205205
if (!Dart_IsNull(result) && resolved_packages_config != nullptr) {
206206
result = Dart_StringToCString(result, resolved_packages_config);
207207
if (Dart_IsError(result)) return result;
208208
ASSERT(*resolved_packages_config != nullptr);
209-
210209
#if !defined(DART_PRECOMPILED_RUNTIME)
211210
if (is_isolate_group_start) {
212211
isolate_group_data->set_resolved_packages_config(

runtime/bin/vmservice/loader.dart

Lines changed: 0 additions & 218 deletions
Original file line numberDiff line numberDiff line change
@@ -30,44 +30,8 @@ _sanitizeWindowsPath(path) {
3030
return fixedPath;
3131
}
3232

33-
_trimWindowsPath(path) {
34-
// Convert /X:/ to X:/.
35-
if (_isWindows == false) {
36-
// Do nothing when not running Windows.
37-
return path;
38-
}
39-
if (!path.startsWith('/') || (path.length < 3)) {
40-
return path;
41-
}
42-
// Match '/?:'.
43-
if ((path[0] == '/') && (path[2] == ':')) {
44-
// Remove leading '/'.
45-
return path.substring(1);
46-
}
47-
return path;
48-
}
49-
50-
// Ensure we have a trailing slash character.
51-
_enforceTrailingSlash(uri) {
52-
if (!uri.endsWith('/')) {
53-
return '$uri/';
54-
}
55-
return uri;
56-
}
57-
58-
class FileRequest {
59-
final SendPort sp;
60-
final int tag;
61-
final Uri uri;
62-
final Uri resolvedUri;
63-
final String libraryUrl;
64-
FileRequest(this.sp, this.tag, this.uri, this.resolvedUri, this.libraryUrl);
65-
}
66-
6733
@pragma("vm:entry-point")
6834
bool _traceLoading = false;
69-
@pragma("vm:entry-point")
70-
bool _deterministic = false;
7135

7236
// State associated with the isolate that is used for loading.
7337
class IsolateLoaderState extends IsolateEmbedderData {
@@ -87,10 +51,6 @@ class IsolateLoaderState extends IsolateEmbedderData {
8751
if (rootScript != null) {
8852
_rootScript = Uri.parse(rootScript);
8953
}
90-
// If the --package-root flag was passed.
91-
if (packageRootFlag != null) {
92-
_setPackageRoot(packageRootFlag);
93-
}
9454
// If the --packages flag was passed.
9555
if (packagesConfigFlag != null) {
9656
_setPackagesConfig(packagesConfigFlag);
@@ -139,40 +99,6 @@ class IsolateLoaderState extends IsolateEmbedderData {
13999
Uri _packageConfig = null;
140100
Map<String, Uri> _packageMap = null;
141101

142-
// We issue only 16 concurrent calls to File.readAsBytes() to stay within
143-
// platform-specific resource limits (e.g. max open files). The rest go on
144-
// _fileRequestQueue and are processed when we can safely issue them.
145-
static final int _maxFileRequests = _deterministic ? 1 : 16;
146-
int currentFileRequests = 0;
147-
final List<FileRequest> _fileRequestQueue = new List<FileRequest>();
148-
149-
bool get shouldIssueFileRequest => currentFileRequests < _maxFileRequests;
150-
void enqueueFileRequest(FileRequest fr) {
151-
_fileRequestQueue.add(fr);
152-
}
153-
154-
FileRequest dequeueFileRequest() {
155-
if (_fileRequestQueue.length == 0) {
156-
return null;
157-
}
158-
return _fileRequestQueue.removeAt(0);
159-
}
160-
161-
_setPackageRoot(String packageRoot) {
162-
packageRoot = _sanitizeWindowsPath(packageRoot);
163-
if (packageRoot.startsWith('file:') ||
164-
packageRoot.startsWith('http:') ||
165-
packageRoot.startsWith('https:')) {
166-
packageRoot = _enforceTrailingSlash(packageRoot);
167-
_packageRoot = _workingDirectory.resolve(packageRoot);
168-
} else {
169-
packageRoot = _sanitizeWindowsPath(packageRoot);
170-
packageRoot = _trimWindowsPath(packageRoot);
171-
_packageRoot =
172-
_workingDirectory.resolveUri(new Uri.directory(packageRoot));
173-
}
174-
}
175-
176102
_setPackagesConfig(String packagesParam) {
177103
var packagesName = _sanitizeWindowsPath(packagesParam);
178104
var packagesUri = Uri.parse(packagesName);
@@ -396,150 +322,6 @@ void _sendExtensionImportResponse(
396322
sp.send(msg);
397323
}
398324

399-
void _loadHttp(
400-
SendPort sp, int tag, Uri uri, Uri resolvedUri, String libraryUrl) {
401-
if (_httpClient == null) {
402-
_httpClient = new HttpClient()..maxConnectionsPerHost = 6;
403-
}
404-
_httpClient
405-
.getUrl(resolvedUri)
406-
.then((HttpClientRequest request) => request.close())
407-
.then((HttpClientResponse response) {
408-
var builder = new BytesBuilder(copy: false);
409-
response.listen(builder.add, onDone: () {
410-
if (response.statusCode != 200) {
411-
var msg = "Failure getting $resolvedUri:\n"
412-
" ${response.statusCode} ${response.reasonPhrase}";
413-
_sendResourceResponse(sp, tag, uri, resolvedUri, libraryUrl, msg);
414-
} else {
415-
_sendResourceResponse(
416-
sp, tag, uri, resolvedUri, libraryUrl, builder.takeBytes());
417-
}
418-
}, onError: (e) {
419-
_sendResourceResponse(
420-
sp, tag, uri, resolvedUri, libraryUrl, e.toString());
421-
});
422-
}).catchError((e) {
423-
_sendResourceResponse(sp, tag, uri, resolvedUri, libraryUrl, e.toString());
424-
});
425-
// It's just here to push an event on the event loop so that we invoke the
426-
// scheduled microtasks.
427-
Timer.run(() {});
428-
}
429-
430-
void _loadFile(IsolateLoaderState loaderState, SendPort sp, int tag, Uri uri,
431-
Uri resolvedUri, String libraryUrl) {
432-
var path = resolvedUri.toFilePath();
433-
var sourceFile = new File(path);
434-
sourceFile.readAsBytes().then((data) {
435-
_sendResourceResponse(sp, tag, uri, resolvedUri, libraryUrl, data);
436-
}, onError: (e) {
437-
_sendResourceResponse(sp, tag, uri, resolvedUri, libraryUrl, e.toString());
438-
}).whenComplete(() {
439-
loaderState.currentFileRequests--;
440-
while (loaderState.shouldIssueFileRequest) {
441-
FileRequest fr = loaderState.dequeueFileRequest();
442-
if (fr == null) {
443-
break;
444-
}
445-
_loadFile(
446-
loaderState, fr.sp, fr.tag, fr.uri, fr.resolvedUri, fr.libraryUrl);
447-
loaderState.currentFileRequests++;
448-
}
449-
});
450-
}
451-
452-
void _loadDataUri(
453-
SendPort sp, int tag, Uri uri, Uri resolvedUri, String libraryUrl) {
454-
try {
455-
var mime = uri.data.mimeType;
456-
if ((mime != "application/dart") && (mime != "text/plain")) {
457-
throw "MIME-type must be application/dart or text/plain: $mime given.";
458-
}
459-
var charset = uri.data.charset;
460-
if ((charset != "utf-8") && (charset != "US-ASCII")) {
461-
// The C++ portion of the embedder assumes UTF-8.
462-
throw "Only utf-8 or US-ASCII encodings are supported: $charset given.";
463-
}
464-
_sendResourceResponse(
465-
sp, tag, uri, resolvedUri, libraryUrl, uri.data.contentAsBytes());
466-
} catch (e) {
467-
_sendResourceResponse(sp, tag, uri, resolvedUri, libraryUrl,
468-
"Invalid data uri ($uri):\n $e");
469-
}
470-
}
471-
472-
// Loading a package URI needs to first map the package name to a loadable
473-
// URI.
474-
_loadPackage(IsolateLoaderState loaderState, SendPort sp, bool traceLoading,
475-
int tag, Uri uri, Uri resolvedUri, String libraryUrl) {
476-
if (loaderState._packagesReady) {
477-
var resolvedUri;
478-
try {
479-
resolvedUri = loaderState._resolvePackageUri(uri);
480-
} catch (e, s) {
481-
if (traceLoading) {
482-
_log("Exception ($e) when resolving package URI: $uri");
483-
}
484-
// Report error.
485-
_sendResourceResponse(
486-
sp, tag, uri, resolvedUri, libraryUrl, e.toString());
487-
return;
488-
}
489-
// Recursively call with the new resolved uri.
490-
_handleResourceRequest(
491-
loaderState, sp, traceLoading, tag, uri, resolvedUri, libraryUrl);
492-
} else {
493-
if (loaderState._pendingPackageLoads.isEmpty) {
494-
// Package resolution has not been setup yet, and this is the first
495-
// request for package resolution & loading.
496-
loaderState._requestPackagesMap();
497-
}
498-
// Register the action of loading this package once the package resolution
499-
// is ready.
500-
loaderState._pendingPackageLoads.add(() {
501-
_handleResourceRequest(
502-
loaderState, sp, traceLoading, tag, uri, uri, libraryUrl);
503-
});
504-
if (traceLoading) {
505-
_log("Pending package load of '$uri': "
506-
"${loaderState._pendingPackageLoads.length} pending");
507-
}
508-
}
509-
}
510-
511-
// TODO(johnmccutchan): This and most other top level functions in this file
512-
// should be turned into methods on the IsolateLoaderState class.
513-
_handleResourceRequest(IsolateLoaderState loaderState, SendPort sp,
514-
bool traceLoading, int tag, Uri uri, Uri resolvedUri, String libraryUrl) {
515-
if (resolvedUri.scheme == '' || resolvedUri.scheme == 'file') {
516-
if (loaderState.shouldIssueFileRequest) {
517-
_loadFile(loaderState, sp, tag, uri, resolvedUri, libraryUrl);
518-
loaderState.currentFileRequests++;
519-
} else {
520-
FileRequest fr = new FileRequest(sp, tag, uri, resolvedUri, libraryUrl);
521-
loaderState.enqueueFileRequest(fr);
522-
}
523-
} else if ((resolvedUri.scheme == 'http') ||
524-
(resolvedUri.scheme == 'https')) {
525-
_loadHttp(sp, tag, uri, resolvedUri, libraryUrl);
526-
} else if ((resolvedUri.scheme == 'data')) {
527-
_loadDataUri(sp, tag, uri, resolvedUri, libraryUrl);
528-
} else if ((resolvedUri.scheme == 'package')) {
529-
_loadPackage(
530-
loaderState, sp, traceLoading, tag, uri, resolvedUri, libraryUrl);
531-
} else {
532-
_sendResourceResponse(
533-
sp,
534-
tag,
535-
uri,
536-
resolvedUri,
537-
libraryUrl,
538-
'Unknown scheme (${resolvedUri.scheme}) for '
539-
'$resolvedUri');
540-
}
541-
}
542-
543325
// Handling of packages requests. Finding and parsing of .packages file or
544326
// packages/ directories.
545327
const _LF = 0x0A;

runtime/bin/vmservice_impl.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,6 @@ bool VmService::Setup(const char* server_ip,
202202
Dart_SetField(library, DartUtils::NewString("_isFuchsia"), is_fuchsia);
203203
SHUTDOWN_ON_ERROR(result);
204204

205-
if (deterministic) {
206-
result = Dart_SetField(library, DartUtils::NewString("_deterministic"),
207-
Dart_True());
208-
SHUTDOWN_ON_ERROR(result);
209-
}
210-
211205
// Get _getWatchSignalInternal from dart:io.
212206
Dart_Handle dart_io_str = Dart_NewStringFromCString(DartUtils::kIOLibURL);
213207
SHUTDOWN_ON_ERROR(dart_io_str);

sdk/lib/_internal/vm/bin/builtin.dart

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ Uri _workingDirectory;
7474
// package imports can be resolved relative to it. The root script is the basis
7575
// for the root library in the VM.
7676
Uri _rootScript;
77-
// The package root set on the command line.
78-
Uri _packageRoot;
7977

8078
// Special handling for Windows paths so that they are compatible with URI
8179
// handling.
@@ -154,38 +152,6 @@ void _setWorkingDirectory(String cwd) {
154152
}
155153
}
156154

157-
// Embedder Entrypoint:
158-
// The embedder calls this method with a custom package root.
159-
@pragma("vm:entry-point")
160-
String _setPackageRoot(String packageRoot) {
161-
if (!_setupCompleted) {
162-
_setupHooks();
163-
}
164-
if (_traceLoading) {
165-
_log('Setting package root: $packageRoot');
166-
}
167-
if (packageRoot.startsWith('file:') ||
168-
packageRoot.startsWith('http:') ||
169-
packageRoot.startsWith('https:')) {
170-
packageRoot = _enforceTrailingSlash(packageRoot);
171-
_packageRoot = _workingDirectory.resolve(packageRoot);
172-
} else {
173-
packageRoot = _sanitizeWindowsPath(packageRoot);
174-
packageRoot = _trimWindowsPath(packageRoot);
175-
_packageRoot = _workingDirectory.resolveUri(new Uri.directory(packageRoot));
176-
}
177-
// Now that we have determined the packageRoot value being used, set it
178-
// up for use in Platform.packageRoot. This is only set when the embedder
179-
// sets up the package root. Automatically discovered package root will
180-
// not update the VMLibraryHooks value.
181-
var packageRootStr = _packageRoot.toString();
182-
VMLibraryHooks.packageRootString = packageRootStr;
183-
if (_traceLoading) {
184-
_log('Package root URI: $_packageRoot');
185-
}
186-
return packageRootStr;
187-
}
188-
189155
// Embedder Entrypoint:
190156
@pragma("vm:entry-point")
191157
String _setPackagesMap(String packagesParam) {
@@ -246,12 +212,6 @@ String _resolveScriptUri(String scriptName) {
246212
return scriptUri.toString();
247213
}
248214

249-
// Only used by vm/cc unit tests.
250-
Uri _resolvePackageUri(Uri uri) {
251-
assert(_packageRoot != null);
252-
return _packageRoot.resolve(uri.path);
253-
}
254-
255215
// Register callbacks and hooks with the rest of the core libraries.
256216
@pragma("vm:entry-point")
257217
_setupHooks() {

0 commit comments

Comments
 (0)