Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: runtime/vm/unit_test.cc

Issue 3002553003: Revert "Introduce IKG into kernel-service to support incremental compilation." (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/unit_test.h ('k') | utils/kernel-service/kernel-service.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/unit_test.h" 5 #include "vm/unit_test.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "bin/builtin.h" 9 #include "bin/builtin.h"
10 #include "bin/dartutils.h" 10 #include "bin/dartutils.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 static Dart_Handle ResolvePackageUri(const char* uri_chars) { 157 static Dart_Handle ResolvePackageUri(const char* uri_chars) {
158 const int kNumArgs = 1; 158 const int kNumArgs = 1;
159 Dart_Handle dart_args[kNumArgs]; 159 Dart_Handle dart_args[kNumArgs];
160 dart_args[0] = DartUtils::NewString(uri_chars); 160 dart_args[0] = DartUtils::NewString(uri_chars);
161 return Dart_Invoke(DartUtils::BuiltinLib(), 161 return Dart_Invoke(DartUtils::BuiltinLib(),
162 DartUtils::NewString("_filePathFromUri"), kNumArgs, 162 DartUtils::NewString("_filePathFromUri"), kNumArgs,
163 dart_args); 163 dart_args);
164 } 164 }
165 165
166 static ThreadLocalKey script_reload_key = kUnsetThreadLocalKey; 166 static ThreadLocalKey script_reload_key = kUnsetThreadLocalKey;
167 static ThreadLocalKey kernel_reload_key = kUnsetThreadLocalKey;
168 167
169 char* TestCase::CompileTestScriptWithDFE(const char* url, 168 char* TestCase::CompileTestScriptWithDFE(const char* url,
170 const char* source, 169 const char* source,
171 void** kernel_pgm, 170 void** kernel_pgm) {
172 bool incrementally) { 171 Zone* zone = Thread::Current()->zone();
173 // clang-format off 172 // clang-format off
174 Dart_SourceFile sourcefiles[] = { 173 Dart_SourceFile sourcefiles[] = {
175 { 174 {
176 url, source, 175 url, source,
177 }, 176 },
178 { 177 {
179 "file:///.packages", "untitled:/" 178 "file:///.packages", "untitled:/"
180 }}; 179 }};
181 // clang-format on 180 // clang-format on
182 return CompileTestScriptWithDFE(url, 181 int sourcefiles_count = sizeof(sourcefiles) / sizeof(Dart_SourceFile);
183 sizeof(sourcefiles) / sizeof(Dart_SourceFile), 182 Dart_KernelCompilationResult compilation_result =
184 sourcefiles, kernel_pgm, incrementally); 183 Dart_CompileSourcesToKernel(url, sourcefiles_count, sourcefiles);
185 }
186
187 char* TestCase::CompileTestScriptWithDFE(const char* url,
188 int sourcefiles_count,
189 Dart_SourceFile sourcefiles[],
190 void** kernel_pgm,
191 bool incrementally) {
192 Zone* zone = Thread::Current()->zone();
193 Dart_KernelCompilationResult compilation_result = Dart_CompileSourcesToKernel(
194 url, sourcefiles_count, sourcefiles, incrementally);
195 184
196 if (compilation_result.status != Dart_KernelCompilationStatus_Ok) { 185 if (compilation_result.status != Dart_KernelCompilationStatus_Ok) {
197 return OS::SCreate(zone, "Compilation failed %s", compilation_result.error); 186 return OS::SCreate(zone, "Compilation failed %s", compilation_result.error);
198 } 187 }
199 const uint8_t* kernel_file = compilation_result.kernel; 188 const uint8_t* kernel_file = compilation_result.kernel;
200 intptr_t kernel_length = compilation_result.kernel_size; 189 intptr_t kernel_length = compilation_result.kernel_size;
201 if (kernel_file == NULL) { 190 if (kernel_file == NULL) {
202 return OS::SCreate(zone, "front end generated a NULL kernel file"); 191 return OS::SCreate(zone, "front end generated a NULL kernel file");
203 } 192 }
204 *kernel_pgm = Dart_ReadKernelBinary(kernel_file, kernel_length); 193 *kernel_pgm = Dart_ReadKernelBinary(kernel_file, kernel_length);
205 if (*kernel_pgm == NULL) { 194 if (*kernel_pgm == NULL) {
206 return OS::SCreate(zone, "Failed to read generated kernel binary"); 195 return OS::SCreate(zone, "Failed to read generated kernel binary");
207 } 196 }
208 return NULL; 197 return NULL;
209 } 198 }
210 199
211 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, 200 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag,
212 Dart_Handle library, 201 Dart_Handle library,
213 Dart_Handle url) { 202 Dart_Handle url) {
214 if (FLAG_use_dart_frontend) { 203 if (FLAG_use_dart_frontend) {
215 // Reload request. 204 // Reload request.
216 205 ASSERT(script_reload_key != kUnsetThreadLocalKey);
206 const char* script_source = reinterpret_cast<const char*>(
207 OSThread::GetThreadLocal(script_reload_key));
208 ASSERT(script_source != NULL);
209 OSThread::SetThreadLocal(script_reload_key, 0);
217 const char* urlstr = NULL; 210 const char* urlstr = NULL;
218 Dart_Handle result = Dart_StringToCString(url, &urlstr); 211 Dart_Handle result = Dart_StringToCString(url, &urlstr);
219 if (Dart_IsError(result)) { 212 if (Dart_IsError(result)) {
220 return Dart_NewApiError("accessing url characters failed"); 213 return Dart_NewApiError("accessing url characters failed");
221 } 214 }
222
223 // Updated library either arrives as dart source or as
224 // a precompiled kernel binary.
225 void* kernel_pgm; 215 void* kernel_pgm;
226 if (script_reload_key != kUnsetThreadLocalKey) { 216 char* error =
227 const char* script_source = reinterpret_cast<const char*>( 217 TestCase::CompileTestScriptWithDFE(urlstr, script_source, &kernel_pgm);
228 OSThread::GetThreadLocal(script_reload_key)); 218 if (error == NULL) {
229 ASSERT(script_source != NULL); 219 return Dart_LoadScript(url, Dart_Null(),
230 OSThread::SetThreadLocal(script_reload_key, 0); 220 reinterpret_cast<Dart_Handle>(kernel_pgm), 0, 0);
231 char* error = TestCase::CompileTestScriptWithDFE(urlstr, script_source,
232 &kernel_pgm);
233 if (error != NULL) {
234 return Dart_NewApiError(error);
235 }
236 } else { 221 } else {
237 ASSERT(kernel_reload_key != kUnsetThreadLocalKey); 222 return Dart_NewApiError(error);
238 kernel_pgm =
239 reinterpret_cast<void*>(OSThread::GetThreadLocal(kernel_reload_key));
240 ASSERT(kernel_pgm != NULL);
241 OSThread::SetThreadLocal(kernel_reload_key, 0);
242 } 223 }
243 return Dart_LoadScript(url, Dart_Null(),
244 reinterpret_cast<Dart_Handle>(kernel_pgm), 0, 0);
245 } 224 }
246 if (tag == Dart_kCanonicalizeUrl) { 225 if (tag == Dart_kCanonicalizeUrl) {
247 Dart_Handle library_url = Dart_LibraryUrl(library); 226 Dart_Handle library_url = Dart_LibraryUrl(library);
248 if (Dart_IsError(library_url)) { 227 if (Dart_IsError(library_url)) {
249 return library_url; 228 return library_url;
250 } 229 }
251 return Dart_DefaultCanonicalizeUrl(library_url, url); 230 return Dart_DefaultCanonicalizeUrl(library_url, url);
252 } 231 }
253 if (tag == Dart_kScriptTag) { 232 if (tag == Dart_kScriptTag) {
254 // Reload request. 233 // Reload request.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 DART_CHECK_VALID(lib); 321 DART_CHECK_VALID(lib);
343 result = Dart_SetNativeResolver(lib, resolver, NULL); 322 result = Dart_SetNativeResolver(lib, resolver, NULL);
344 DART_CHECK_VALID(result); 323 DART_CHECK_VALID(result);
345 if (finalize_classes) { 324 if (finalize_classes) {
346 result = Dart_FinalizeLoading(false); 325 result = Dart_FinalizeLoading(false);
347 DART_CHECK_VALID(result); 326 DART_CHECK_VALID(result);
348 } 327 }
349 return lib; 328 return lib;
350 } 329 }
351 330
331 static Dart_Handle LoadTestScriptWithDFE(const char* script,
332 Dart_NativeEntryResolver resolver,
333 const char* lib_url,
334 bool finalize_classes) {
335 Dart_Handle url = NewString(lib_url);
336 Dart_Handle result = Dart_SetLibraryTagHandler(LibraryTagHandler);
337 EXPECT_VALID(result);
338 void* kernel_pgm = NULL;
339 char* error =
340 TestCase::CompileTestScriptWithDFE(lib_url, script, &kernel_pgm);
341 if (error == NULL) {
342 Dart_Handle lib = Dart_LoadScript(
343 url, Dart_Null(), reinterpret_cast<Dart_Handle>(kernel_pgm), 0, 0);
344 DART_CHECK_VALID(lib);
345 result = Dart_SetNativeResolver(lib, resolver, NULL);
346 DART_CHECK_VALID(result);
347 if (finalize_classes) {
348 result = Dart_FinalizeLoading(false);
349 DART_CHECK_VALID(result);
350 }
351 return lib;
352 } else {
353 return Dart_NewApiError(error);
354 }
355 }
356
352 Dart_Handle TestCase::LoadTestScript(const char* script, 357 Dart_Handle TestCase::LoadTestScript(const char* script,
353 Dart_NativeEntryResolver resolver, 358 Dart_NativeEntryResolver resolver,
354 const char* lib_url, 359 const char* lib_url,
355 bool finalize_classes) { 360 bool finalize_classes) {
356 return FLAG_use_dart_frontend 361 if (!FLAG_use_dart_frontend) {
357 ? LoadTestScriptWithDFE( 362 return LoadTestScriptWithVMParser(script, resolver, lib_url,
358 1, 363 finalize_classes);
359 (Dart_SourceFile[1]){{OS::SCreate(Thread::Current()->zone(), 364 } else {
360 "file:///%s", lib_url), 365 Zone* zone = Thread::Current()->zone();
361 script}}, 366 char* resolved_lib_url = OS::SCreate(zone, "file:///%s", lib_url);
362 resolver, finalize_classes) 367 return LoadTestScriptWithDFE(script, resolver, resolved_lib_url,
363 : LoadTestScriptWithVMParser(script, resolver, lib_url, 368 finalize_classes);
364 finalize_classes);
365 }
366
367 Dart_Handle TestCase::LoadTestScriptWithDFE(int sourcefiles_count,
368 Dart_SourceFile sourcefiles[],
369 Dart_NativeEntryResolver resolver,
370 bool finalize,
371 bool incrementally) {
372 // First script is the main script.
373 Dart_Handle url = NewString(sourcefiles[0].uri);
374 Dart_Handle result = Dart_SetLibraryTagHandler(LibraryTagHandler);
375 EXPECT_VALID(result);
376 void* kernel_pgm = NULL;
377 char* error = TestCase::CompileTestScriptWithDFE(
378 sourcefiles[0].uri, sourcefiles_count, sourcefiles, &kernel_pgm,
379 incrementally);
380 if (error != NULL) {
381 return Dart_NewApiError(error);
382 } 369 }
383 Dart_Handle lib = Dart_LoadScript(
384 url, Dart_Null(), reinterpret_cast<Dart_Handle>(kernel_pgm), 0, 0);
385 DART_CHECK_VALID(lib);
386 result = Dart_SetNativeResolver(lib, resolver, NULL);
387 DART_CHECK_VALID(result);
388 if (finalize) {
389 result = Dart_FinalizeLoading(false);
390 DART_CHECK_VALID(result);
391 }
392 return lib;
393 } 370 }
394 371
395 #ifndef PRODUCT 372 #ifndef PRODUCT
396 373
397 void TestCase::SetReloadTestScript(const char* script) { 374 void TestCase::SetReloadTestScript(const char* script) {
398 if (script_reload_key == kUnsetThreadLocalKey) { 375 if (script_reload_key == kUnsetThreadLocalKey) {
399 script_reload_key = OSThread::CreateThreadLocal(); 376 script_reload_key = OSThread::CreateThreadLocal();
400 } 377 }
401 ASSERT(script_reload_key != kUnsetThreadLocalKey); 378 ASSERT(script_reload_key != kUnsetThreadLocalKey);
402 ASSERT(OSThread::GetThreadLocal(script_reload_key) == 0); 379 ASSERT(OSThread::GetThreadLocal(script_reload_key) == 0);
403 // Store the new script in TLS. 380 // Store the new script in TLS.
404 OSThread::SetThreadLocal(script_reload_key, reinterpret_cast<uword>(script)); 381 OSThread::SetThreadLocal(script_reload_key, reinterpret_cast<uword>(script));
405 } 382 }
406 383
407 void TestCase::SetReloadTestKernel(const void* kernel) {
408 if (kernel_reload_key == kUnsetThreadLocalKey) {
409 kernel_reload_key = OSThread::CreateThreadLocal();
410 }
411 ASSERT(kernel_reload_key != kUnsetThreadLocalKey);
412 ASSERT(OSThread::GetThreadLocal(kernel_reload_key) == 0);
413 // Store the new script in TLS.
414 OSThread::SetThreadLocal(kernel_reload_key, reinterpret_cast<uword>(kernel));
415 }
416
417 Dart_Handle TestCase::TriggerReload() { 384 Dart_Handle TestCase::TriggerReload() {
418 Isolate* isolate = Isolate::Current(); 385 Isolate* isolate = Isolate::Current();
419 JSONStream js; 386 JSONStream js;
420 bool success = false; 387 bool success = false;
421 { 388 {
422 TransitionNativeToVM transition(Thread::Current()); 389 TransitionNativeToVM transition(Thread::Current());
423 success = isolate->ReloadSources(&js, 390 success = isolate->ReloadSources(&js,
424 false, // force_reload 391 false, // force_reload
425 NULL, NULL, 392 NULL, NULL,
426 true); // dont_delete_reload_context 393 true); // dont_delete_reload_context
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 TransitionNativeToVM transition(thread); 428 TransitionNativeToVM transition(thread);
462 Isolate* isolate = thread->isolate(); 429 Isolate* isolate = thread->isolate();
463 if (isolate->reload_context() != NULL) { 430 if (isolate->reload_context() != NULL) {
464 isolate->DeleteReloadContext(); 431 isolate->DeleteReloadContext();
465 } 432 }
466 } 433 }
467 434
468 return result; 435 return result;
469 } 436 }
470 437
471 Dart_Handle TestCase::ReloadTestKernel(const void* kernel) {
472 SetReloadTestKernel(kernel);
473
474 Dart_Handle result = TriggerReload();
475 if (Dart_IsError(result)) {
476 return result;
477 }
478
479 result = GetReloadErrorOrRootLibrary();
480
481 {
482 Thread* thread = Thread::Current();
483 TransitionNativeToVM transition(thread);
484 Isolate* isolate = thread->isolate();
485 if (isolate->reload_context() != NULL) {
486 isolate->DeleteReloadContext();
487 }
488 }
489
490 return result;
491 }
492
493 #endif // !PRODUCT 438 #endif // !PRODUCT
494 439
495 Dart_Handle TestCase::LoadCoreTestScript(const char* script, 440 Dart_Handle TestCase::LoadCoreTestScript(const char* script,
496 Dart_NativeEntryResolver resolver) { 441 Dart_NativeEntryResolver resolver) {
497 return LoadTestScript(script, resolver, CORELIB_TEST_URI); 442 return LoadTestScript(script, resolver, CORELIB_TEST_URI);
498 } 443 }
499 444
500 Dart_Handle TestCase::lib() { 445 Dart_Handle TestCase::lib() {
501 Dart_Handle url = NewString(TestCase::url()); 446 Dart_Handle url = NewString(TestCase::url());
502 Dart_Handle lib = Dart_LookupLibrary(url); 447 Dart_Handle lib = Dart_LookupLibrary(url);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 pos = strstr(in, prefix); 566 pos = strstr(in, prefix);
622 } 567 }
623 // Copy the remainder of in to out. 568 // Copy the remainder of in to out.
624 while (*in != '\0') { 569 while (*in != '\0') {
625 *out++ = *in++; 570 *out++ = *in++;
626 } 571 }
627 *out = '\0'; 572 *out = '\0';
628 } 573 }
629 574
630 } // namespace dart 575 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/unit_test.h ('k') | utils/kernel-service/kernel-service.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698