[vm] Remove unused compilation and type-feedback traces.

Reduces VM code size by about 33k.

TEST=ci
Change-Id: Ifc74284fa69fe209ebf12566ca81bda765f19057
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/202863
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
Ryan Macnak 2021-06-21 23:47:50 +00:00 committed by commit-bot@chromium.org
parent 02e82dae37
commit fb5465c624
14 changed files with 0 additions and 1601 deletions

View file

@ -116,8 +116,6 @@ static const char* const kSnapshotKindNames[] = {
V(assembly, assembly_filename) \
V(elf, elf_filename) \
V(loading_unit_manifest, loading_unit_manifest_filename) \
V(load_compilation_trace, load_compilation_trace_filename) \
V(load_type_feedback, load_type_feedback_filename) \
V(save_debugging_info, debugging_info_filename) \
V(save_obfuscation_map, obfuscation_map_filename)
@ -390,34 +388,6 @@ static void MaybeLoadCode() {
Dart_Handle result = Dart_CompileAll();
CHECK_RESULT(result);
}
if ((load_compilation_trace_filename != NULL) &&
((snapshot_kind == kCoreJIT) || (snapshot_kind == kAppJIT))) {
// Finalize all classes. This ensures that there are no non-finalized
// classes in the gaps between cid ranges. Such classes prevent merging of
// cid ranges.
Dart_Handle result = Dart_FinalizeAllClasses();
CHECK_RESULT(result);
// Sort classes to have better cid ranges.
result = Dart_SortClasses();
CHECK_RESULT(result);
uint8_t* buffer = NULL;
intptr_t size = 0;
ReadFile(load_compilation_trace_filename, &buffer, &size);
result = Dart_LoadCompilationTrace(buffer, size);
free(buffer);
CHECK_RESULT(result);
}
if ((load_type_feedback_filename != NULL) &&
((snapshot_kind == kCoreJIT) || (snapshot_kind == kAppJIT))) {
uint8_t* buffer = NULL;
intptr_t size = 0;
ReadFile(load_type_feedback_filename, &buffer, &size);
Dart_Handle result = Dart_LoadTypeFeedback(buffer, size);
free(buffer);
CHECK_RESULT(result);
}
}
static void CreateAndWriteCoreSnapshot() {

View file

@ -73,8 +73,6 @@ static bool kernel_isolate_is_running = false;
static Dart_Isolate main_isolate = NULL;
static void ReadFile(const char* filename, uint8_t** buffer, intptr_t* size);
#define SAVE_ERROR_AND_EXIT(result) \
*error = Utils::StrDup(Dart_GetError(result)); \
if (Dart_IsCompilationError(result)) { \
@ -925,32 +923,6 @@ static void EmbedderInformationCallback(Dart_EmbedderInformation* info) {
ErrorExit(exit_code, "%s\n", Dart_GetError(result)); \
}
static void WriteFile(const char* filename,
const uint8_t* buffer,
const intptr_t size) {
File* file = File::Open(NULL, filename, File::kWriteTruncate);
if (file == NULL) {
ErrorExit(kErrorExitCode, "Unable to open file %s\n", filename);
}
if (!file->WriteFully(buffer, size)) {
ErrorExit(kErrorExitCode, "Unable to write file %s\n", filename);
}
file->Release();
}
static void ReadFile(const char* filename, uint8_t** buffer, intptr_t* size) {
File* file = File::Open(NULL, filename, File::kRead);
if (file == NULL) {
ErrorExit(kErrorExitCode, "Unable to open file %s\n", filename);
}
*size = file->Length();
*buffer = reinterpret_cast<uint8_t*>(malloc(*size));
if (!file->ReadFully(*buffer, *size)) {
ErrorExit(kErrorExitCode, "Unable to read file %s\n", filename);
}
file->Release();
}
void RunMainIsolate(const char* script_name,
const char* package_config_override,
CommandLineOptions* dart_options) {
@ -1017,23 +989,6 @@ void RunMainIsolate(const char* script_name,
script_name);
}
if (Options::load_compilation_trace_filename() != NULL) {
uint8_t* buffer = NULL;
intptr_t size = 0;
ReadFile(Options::load_compilation_trace_filename(), &buffer, &size);
result = Dart_LoadCompilationTrace(buffer, size);
free(buffer);
CHECK_RESULT(result);
}
if (Options::load_type_feedback_filename() != NULL) {
uint8_t* buffer = NULL;
intptr_t size = 0;
ReadFile(Options::load_type_feedback_filename(), &buffer, &size);
result = Dart_LoadTypeFeedback(buffer, size);
free(buffer);
CHECK_RESULT(result);
}
// Create a closure for the main entry point which is in the exported
// namespace of the root library or invoke a getter of the same name
// in the exported namespace and return the resulting closure.
@ -1068,21 +1023,6 @@ void RunMainIsolate(const char* script_name,
}
}
CHECK_RESULT(result);
if (Options::save_compilation_trace_filename() != NULL) {
uint8_t* buffer = NULL;
intptr_t size = 0;
result = Dart_SaveCompilationTrace(&buffer, &size);
CHECK_RESULT(result);
WriteFile(Options::save_compilation_trace_filename(), buffer, size);
}
if (Options::save_type_feedback_filename() != NULL) {
uint8_t* buffer = NULL;
intptr_t size = 0;
result = Dart_SaveTypeFeedback(&buffer, &size);
CHECK_RESULT(result);
WriteFile(Options::save_type_feedback_filename(), buffer, size);
}
}
WriteDepsFile(isolate);

View file

@ -23,10 +23,6 @@ namespace bin {
V(snapshot_depfile, snapshot_deps_filename) \
V(depfile, depfile) \
V(depfile_output_filename, depfile_output_filename) \
V(save_compilation_trace, save_compilation_trace_filename) \
V(load_compilation_trace, load_compilation_trace_filename) \
V(save_type_feedback, save_type_feedback_filename) \
V(load_type_feedback, load_type_feedback_filename) \
V(root_certs_file, root_certs_file) \
V(root_certs_cache, root_certs_cache) \
V(namespace, namespc) \

View file

@ -3690,58 +3690,6 @@ DART_EXPORT bool Dart_IsServiceIsolate(Dart_Isolate isolate);
*/
DART_EXPORT bool Dart_WriteProfileToTimeline(Dart_Port main_port, char** error);
/*
* ====================
* Compilation Feedback
* ====================
*/
/**
* Record all functions which have been compiled in the current isolate.
*
* \param buffer Returns a pointer to a buffer containing the trace.
* This buffer is scope allocated and is only valid until the next call to
* Dart_ExitScope.
* \param size Returns the size of the buffer.
* \return Returns an valid handle upon success.
*/
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle
Dart_SaveCompilationTrace(uint8_t** buffer, intptr_t* buffer_length);
/**
* Compile all functions from data from Dart_SaveCompilationTrace. Unlike JIT
* feedback, this data is fuzzy: loading does not need to happen in the exact
* program that was saved, the saver and loader do not need to agree on checked
* mode versus production mode or debug/release/product.
*
* \return Returns an error handle if a compilation error was encountered.
*/
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle
Dart_LoadCompilationTrace(uint8_t* buffer, intptr_t buffer_length);
/**
* Record runtime feedback for the current isolate, including type feedback
* and usage counters.
*
* \param buffer Returns a pointer to a buffer containing the trace.
* This buffer is scope allocated and is only valid until the next call to
* Dart_ExitScope.
* \param size Returns the size of the buffer.
* \return Returns an valid handle upon success.
*/
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle
Dart_SaveTypeFeedback(uint8_t** buffer, intptr_t* buffer_length);
/**
* Compile functions using data from Dart_SaveTypeFeedback. The data must from a
* VM with the same version and compiler flags.
*
* \return Returns an error handle if a compilation error was encountered or a
* version mismatch is detected.
*/
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle
Dart_LoadTypeFeedback(uint8_t* buffer, intptr_t buffer_length);
/*
* ==============
* Precompilation

View file

@ -1,45 +0,0 @@
// Copyright (c) 2019, 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.
import "dart:async";
import "dart:io";
import "package:path/path.dart" as p;
import "snapshot_test_helper.dart";
int fib(int n) {
if (n <= 1) return 1;
return fib(n - 1) + fib(n - 2);
}
Future<void> main(List<String> args) async {
if (args.contains("--child")) {
print(fib(35));
return;
}
if (!Platform.script.toString().endsWith(".dart")) {
print("This test must run from source");
return;
}
await withTempDir((String tmp) async {
final String tracePath = p.join(tmp, "compilation_trace.txt");
final result1 = await runDart("generate compilation trace", [
"--save_compilation_trace=$tracePath",
Platform.script.toFilePath(),
"--child",
]);
expectOutput("14930352", result1);
final result2 = await runDart("use compilation trace", [
"--load_compilation_trace=$tracePath",
Platform.script.toFilePath(),
"--child",
]);
expectOutput("14930352", result2);
});
}

View file

@ -1,45 +0,0 @@
// Copyright (c) 2019, 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.
import "dart:async";
import "dart:io";
import "package:path/path.dart" as p;
import "snapshot_test_helper.dart";
int fib(int n) {
if (n <= 1) return 1;
return fib(n - 1) + fib(n - 2);
}
Future<void> main(List<String> args) async {
if (args.contains("--child")) {
print(fib(35));
return;
}
if (!Platform.script.toString().endsWith(".dart")) {
print("This test must run from source");
return;
}
await withTempDir((String tmp) async {
final String feedbackPath = p.join(tmp, "type_feedback.bin");
final result1 = await runDart("generate type feedback", [
"--save_type_feedback=$feedbackPath",
Platform.script.toFilePath(),
"--child",
]);
expectOutput("14930352", result1);
final result2 = await runDart("use type feedback", [
"--load_type_feedback=$feedbackPath",
Platform.script.toFilePath(),
"--child",
]);
expectOutput("14930352", result2);
});
}

View file

@ -1,45 +0,0 @@
// Copyright (c) 2019, 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.
import "dart:async";
import "dart:io";
import "package:path/path.dart" as p;
import "snapshot_test_helper.dart";
int fib(int n) {
if (n <= 1) return 1;
return fib(n - 1) + fib(n - 2);
}
Future<void> main(List<String> args) async {
if (args.contains("--child")) {
print(fib(35));
return;
}
if (!Platform.script.toString().endsWith(".dart")) {
print("This test must run from source");
return;
}
await withTempDir((String tmp) async {
final String tracePath = p.join(tmp, "compilation_trace.txt");
final result1 = await runDart("generate compilation trace", [
"--save_compilation_trace=$tracePath",
Platform.script.toFilePath(),
"--child",
]);
expectOutput("14930352", result1);
final result2 = await runDart("use compilation trace", [
"--load_compilation_trace=$tracePath",
Platform.script.toFilePath(),
"--child",
]);
expectOutput("14930352", result2);
});
}

View file

@ -1,45 +0,0 @@
// Copyright (c) 2019, 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.
import "dart:async";
import "dart:io";
import "package:path/path.dart" as p;
import "snapshot_test_helper.dart";
int fib(int n) {
if (n <= 1) return 1;
return fib(n - 1) + fib(n - 2);
}
Future<void> main(List<String> args) async {
if (args.contains("--child")) {
print(fib(35));
return;
}
if (!Platform.script.toString().endsWith(".dart")) {
print("This test must run from source");
return;
}
await withTempDir((String tmp) async {
final String feedbackPath = p.join(tmp, "type_feedback.bin");
final result1 = await runDart("generate type feedback", [
"--save_type_feedback=$feedbackPath",
Platform.script.toFilePath(),
"--child",
]);
expectOutput("14930352", result1);
final result2 = await runDart("use type feedback", [
"--load_type_feedback=$feedbackPath",
Platform.script.toFilePath(),
"--child",
]);
expectOutput("14930352", result2);
});
}

View file

@ -460,7 +460,6 @@ dart_2/isolates/thread_pool_test: Skip # Only AOT has lightweight enough isolate
[ $hot_reload || $hot_reload_rollback ]
dart/appjit*: SkipByDesign # Cannot reload with URI pointing to app snapshot.
dart/compilation_trace_test: Pass, Slow
dart/disassemble_determinism_test: SkipSlow # Runs expensive fibonacci(32) computation in 2 subprocesses
dart/isolates/spawn_function_test: Skip # This test explicitly enables isolate groups (off-by-default atm). It will be enabled once full IG reloading is implemented.
dart/issue_31959_31960_test: SkipSlow
@ -472,9 +471,7 @@ dart/spawn_infinite_loop_test: Skip # We can shutdown an isolate before it reloa
dart/spawn_shutdown_test: Skip # We can shutdown an isolate before it reloads.
dart/splay_test: SkipSlow
dart/stack_overflow_shared_test: SkipSlow # Too slow with --shared-slow-path-triggers-gc flag and not relevant outside precompiled.
dart/type_feedback_test: Pass, Slow
dart_2/appjit*: SkipByDesign # Cannot reload with URI pointing to app snapshot.
dart_2/compilation_trace_test: Pass, Slow
dart_2/disassemble_determinism_test: SkipSlow # Runs expensive fibonacci(32) computation in 2 subprocesses
dart_2/isolates/spawn_function_test: Skip # This test explicitly enables isolate groups (off-by-default atm). It will be enabled once full IG reloading is implemented.
dart_2/issue_31959_31960_test: SkipSlow
@ -486,7 +483,6 @@ dart_2/spawn_infinite_loop_test: Skip # We can shutdown an isolate before it rel
dart_2/spawn_shutdown_test: Skip # We can shutdown an isolate before it reloads.
dart_2/splay_test: SkipSlow
dart_2/stack_overflow_shared_test: SkipSlow # Too slow with --shared-slow-path-triggers-gc flag and not relevant outside precompiled.
dart_2/type_feedback_test: Pass, Slow
[ $hot_reload || $hot_reload_rollback || $compiler != dartk && $compiler != dartkp ]
dart/entrypoints/*: SkipByDesign # These tests are for compiler optimizations and very sensitive to when functions are optimized, so they are disabled on hotreload and optcounter bots.

View file

@ -26,13 +26,6 @@ def BuildOptions():
type="string",
help="kind of snapshot to generate",
default="core")
result.add_option(
"--load_compilation_trace",
action="store",
type="string",
help=
"path to a compilation trace to load before generating a core-jit snapshot"
)
result.add_option(
"--vm_flag",
action="append",
@ -139,10 +132,6 @@ def Main():
for flag in options.vm_flag:
script_args.append(flag)
if options.load_compilation_trace:
script_args.append(''.join(
["--load_compilation_trace=", options.load_compilation_trace]))
# Pass along the packages if there is one.
if options.packages:
script_args.append(''.join(["--packages=", options.packages]))

File diff suppressed because it is too large Load diff

View file

@ -1,141 +0,0 @@
// Copyright (c) 2017, 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.
#ifndef RUNTIME_VM_COMPILATION_TRACE_H_
#define RUNTIME_VM_COMPILATION_TRACE_H_
#include "platform/assert.h"
#include "vm/object.h"
#include "vm/program_visitor.h"
#include "vm/zone_text_buffer.h"
#if !defined(DART_PRECOMPILED_RUNTIME)
namespace dart {
class CompilationTraceSaver : public FunctionVisitor {
public:
explicit CompilationTraceSaver(Zone* zone);
void VisitFunction(const Function& function);
void StealBuffer(uint8_t** buffer, intptr_t* buffer_length) {
*buffer = reinterpret_cast<uint8_t*>(buf_.buffer());
*buffer_length = buf_.length();
}
private:
ZoneTextBuffer buf_;
String& func_name_;
Class& cls_;
String& cls_name_;
Library& lib_;
String& uri_;
};
class CompilationTraceLoader : public ValueObject {
public:
explicit CompilationTraceLoader(Thread* thread);
ObjectPtr CompileTrace(uint8_t* buffer, intptr_t buffer_length);
private:
ObjectPtr CompileTriple(const char* uri_cstr,
const char* cls_cstr,
const char* func_cstr);
ObjectPtr CompileFunction(const Function& function);
void SpeculateInstanceCallTargets(const Function& function);
Thread* thread_;
Zone* zone_;
String& uri_;
String& class_name_;
String& function_name_;
String& function_name2_;
Library& lib_;
Class& cls_;
Function& function_;
Function& function2_;
Field& field_;
Array& sites_;
ICData& site_;
AbstractType& static_type_;
Class& receiver_cls_;
Function& target_;
String& selector_;
Array& args_desc_;
Object& error_;
};
class TypeFeedbackSaver : public FunctionVisitor {
public:
explicit TypeFeedbackSaver(BaseWriteStream* stream);
void WriteHeader();
void SaveClasses();
void SaveFields();
void VisitFunction(const Function& function);
private:
void WriteClassByName(const Class& cls);
void WriteString(const String& value);
void WriteInt(intptr_t value) { stream_->Write(static_cast<int32_t>(value)); }
BaseWriteStream* const stream_;
Class& cls_;
Library& lib_;
String& str_;
Array& fields_;
Field& field_;
Code& code_;
Array& call_sites_;
ICData& call_site_;
};
class TypeFeedbackLoader : public ValueObject {
public:
explicit TypeFeedbackLoader(Thread* thread);
~TypeFeedbackLoader();
ObjectPtr LoadFeedback(ReadStream* stream);
private:
ObjectPtr CheckHeader();
ObjectPtr LoadClasses();
ObjectPtr LoadFields();
ObjectPtr LoadFunction();
FunctionPtr FindFunction(UntaggedFunction::Kind kind,
const TokenPosition& token_pos);
ClassPtr ReadClassByName();
StringPtr ReadString();
intptr_t ReadInt() { return stream_->Read<int32_t>(); }
Thread* thread_;
Zone* zone_;
ReadStream* stream_;
intptr_t num_cids_;
intptr_t* cid_map_;
String& uri_;
Library& lib_;
String& cls_name_;
Class& cls_;
String& field_name_;
Array& fields_;
Field& field_;
String& func_name_;
Function& func_;
Array& call_sites_;
ICData& call_site_;
String& target_name_;
Function& target_;
Array& args_desc_;
GrowableObjectArray& functions_to_compile_;
Object& error_;
};
} // namespace dart
#endif // !defined(DART_PRECOMPILED_RUNTIME)
#endif // RUNTIME_VM_COMPILATION_TRACE_H_

View file

@ -13,7 +13,6 @@
#include "platform/unicode.h"
#include "vm/class_finalizer.h"
#include "vm/clustered_snapshot.h"
#include "vm/compilation_trace.h"
#include "vm/compiler/jit/compiler.h"
#include "vm/dart.h"
#include "vm/dart_api_impl.h"
@ -6410,94 +6409,6 @@ DART_EXPORT void Dart_SetThreadName(const char* name) {
thread->SetName(name);
}
DART_EXPORT
Dart_Handle Dart_SaveCompilationTrace(uint8_t** buffer,
intptr_t* buffer_length) {
#if defined(DART_PRECOMPILED_RUNTIME)
return Api::NewError("%s: Cannot compile on an AOT runtime.", CURRENT_FUNC);
#else
Thread* thread = Thread::Current();
API_TIMELINE_DURATION(thread);
DARTSCOPE(thread);
CHECK_NULL(buffer);
CHECK_NULL(buffer_length);
CompilationTraceSaver saver(thread->zone());
ProgramVisitor::WalkProgram(thread->zone(), thread->isolate_group(), &saver);
saver.StealBuffer(buffer, buffer_length);
return Api::Success();
#endif // defined(DART_PRECOMPILED_RUNTIME)
}
DART_EXPORT
Dart_Handle Dart_SaveTypeFeedback(uint8_t** buffer, intptr_t* buffer_length) {
#if defined(DART_PRECOMPILED_RUNTIME)
return Api::NewError("%s: Cannot compile on an AOT runtime.", CURRENT_FUNC);
#else
Thread* thread = Thread::Current();
API_TIMELINE_DURATION(thread);
DARTSCOPE(thread);
CHECK_NULL(buffer);
CHECK_NULL(buffer_length);
ZoneWriteStream stream(Api::TopScope(thread)->zone(), MB);
TypeFeedbackSaver saver(&stream);
saver.WriteHeader();
saver.SaveClasses();
saver.SaveFields();
ProgramVisitor::WalkProgram(thread->zone(), thread->isolate_group(), &saver);
*buffer = stream.buffer();
*buffer_length = stream.bytes_written();
return Api::Success();
#endif // defined(DART_PRECOMPILED_RUNTIME)
}
DART_EXPORT
Dart_Handle Dart_LoadCompilationTrace(uint8_t* buffer, intptr_t buffer_length) {
#if defined(DART_PRECOMPILED_RUNTIME)
return Api::NewError("%s: Cannot compile on an AOT runtime.", CURRENT_FUNC);
#else
Thread* thread = Thread::Current();
API_TIMELINE_DURATION(thread);
DARTSCOPE(thread);
CHECK_NULL(buffer);
Dart_Handle state = Api::CheckAndFinalizePendingClasses(T);
if (Api::IsError(state)) {
return state;
}
CompilationTraceLoader loader(thread);
const Object& error =
Object::Handle(loader.CompileTrace(buffer, buffer_length));
if (error.IsError()) {
return Api::NewHandle(T, Error::Cast(error).ptr());
}
return Api::Success();
#endif // defined(DART_PRECOMPILED_RUNTIME)
}
DART_EXPORT
Dart_Handle Dart_LoadTypeFeedback(uint8_t* buffer, intptr_t buffer_length) {
#if defined(DART_PRECOMPILED_RUNTIME)
return Api::NewError("%s: Cannot compile on an AOT runtime.", CURRENT_FUNC);
#else
Thread* thread = Thread::Current();
API_TIMELINE_DURATION(thread);
DARTSCOPE(thread);
CHECK_NULL(buffer);
Dart_Handle state = Api::CheckAndFinalizePendingClasses(T);
if (Api::IsError(state)) {
return state;
}
ReadStream stream(buffer, buffer_length);
TypeFeedbackLoader loader(thread);
const Object& error = Object::Handle(loader.LoadFeedback(&stream));
if (error.IsError()) {
return Api::NewHandle(T, Error::Cast(error).ptr());
}
return Api::Success();
#endif // defined(DART_PRECOMPILED_RUNTIME)
}
DART_EXPORT Dart_Handle Dart_SortClasses() {
#if defined(DART_PRECOMPILED_RUNTIME)
return Api::NewError("%s: Cannot compile on an AOT runtime.", CURRENT_FUNC);

View file

@ -45,8 +45,6 @@ vm_sources = [
"code_patcher_arm64.cc",
"code_patcher_ia32.cc",
"code_patcher_x64.cc",
"compilation_trace.cc",
"compilation_trace.h",
"constants_arm.cc",
"constants_arm.h",
"constants_arm64.cc",