Skip to content

Commit f5e3f94

Browse files
committed
- Complete revamp of isolate-specific flags. - Associate flags with the isolate on creation. - Dart_CreateIsolate and associate callback do take an extra flags argument. - Make sure to clear IC data array when clearing code. BUG=23578 Review URL: https://codereview.chromium.org//1162033005
1 parent deb1697 commit f5e3f94

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+388
-226
lines changed

runtime/bin/gen_snapshot.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,8 @@ int main(int argc, char** argv) {
554554
}
555555

556556
char* error;
557-
Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, NULL, NULL, &error);
557+
Dart_Isolate isolate = Dart_CreateIsolate(
558+
NULL, NULL, NULL, NULL, NULL, &error);
558559
if (isolate == NULL) {
559560
Log::PrintErr("Error: %s", error);
560561
free(error);
@@ -600,7 +601,7 @@ int main(int argc, char** argv) {
600601

601602
// Now we create an isolate into which we load all the code that needs to
602603
// be in the snapshot.
603-
if (Dart_CreateIsolate(NULL, NULL, NULL, NULL, &error) == NULL) {
604+
if (Dart_CreateIsolate(NULL, NULL, NULL, NULL, NULL, &error) == NULL) {
604605
fprintf(stderr, "%s", error);
605606
free(error);
606607
exit(255);

runtime/bin/main.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ static Dart_Handle EnvironmentCallback(Dart_Handle name) {
579579
static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri,
580580
const char* main,
581581
const char* package_root,
582+
Dart_IsolateFlags* flags,
582583
char** error,
583584
int* exit_code) {
584585
ASSERT(script_uri != NULL);
@@ -588,6 +589,7 @@ static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri,
588589
isolate = Dart_CreateIsolate(script_uri,
589590
main,
590591
isolate_snapshot_buffer,
592+
flags,
591593
isolate_data,
592594
error);
593595

@@ -673,7 +675,11 @@ static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri,
673675
static Dart_Isolate CreateIsolateAndSetup(const char* script_uri,
674676
const char* main,
675677
const char* package_root,
678+
Dart_IsolateFlags* flags,
676679
void* data, char** error) {
680+
// The VM should never call the isolate helper with a NULL flags.
681+
ASSERT(flags != NULL);
682+
ASSERT(flags->version == DART_FLAGS_CURRENT_VERSION);
677683
IsolateData* parent_isolate_data = reinterpret_cast<IsolateData*>(data);
678684
int exit_code = 0;
679685
if (script_uri == NULL) {
@@ -697,6 +703,7 @@ static Dart_Isolate CreateIsolateAndSetup(const char* script_uri,
697703
return CreateIsolateAndSetupHelper(script_uri,
698704
main,
699705
package_root,
706+
flags,
700707
error,
701708
&exit_code);
702709
}
@@ -967,6 +974,7 @@ void main(int argc, char** argv) {
967974
Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name,
968975
"main",
969976
commandline_package_root,
977+
NULL,
970978
&error,
971979
&exit_code);
972980
if (isolate == NULL) {

runtime/bin/vmservice_dartium.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Dart_Isolate VmServiceServer::CreateIsolate(const uint8_t* snapshot_buffer) {
4545
"main",
4646
snapshot_buffer,
4747
NULL,
48+
NULL,
4849
&error);
4950
if (!isolate) {
5051
fprintf(stderr, "Dart_CreateIsolate failed: %s\n", error);

runtime/include/dart_api.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,23 @@ DART_EXPORT Dart_Handle Dart_VisitPrologueWeakHandles(
685685
*/
686686
DART_EXPORT const char* Dart_VersionString();
687687

688+
689+
/**
690+
* Isolate specific flags are set when creating a new isolate using the
691+
* Dart_IsolateFlags structure.
692+
*
693+
* Current version of flags is encoded in a 32-bit integer with 16 bits used
694+
* for each part.
695+
*/
696+
697+
#define DART_FLAGS_CURRENT_VERSION (0x00000001)
698+
699+
typedef struct {
700+
int32_t version;
701+
bool enable_type_checks;
702+
bool enable_asserts;
703+
} Dart_IsolateFlags;
704+
688705
/**
689706
* An isolate creation and initialization callback function.
690707
*
@@ -723,6 +740,9 @@ DART_EXPORT const char* Dart_VersionString();
723740
* \param package_root The package root path for this isolate to resolve
724741
* package imports against. If this parameter is NULL, the package root path
725742
* of the parent isolate should be used.
743+
* \param flags Default flags for this isolate being spawned. Either inherited
744+
* from the spawning isolate or passed as parameters when spawning the
745+
* isolate from Dart code.
726746
* \param callback_data The callback data which was passed to the
727747
* parent isolate when it was created by calling Dart_CreateIsolate().
728748
* \param error A structure into which the embedder can place a
@@ -734,6 +754,7 @@ DART_EXPORT const char* Dart_VersionString();
734754
typedef Dart_Isolate (*Dart_IsolateCreateCallback)(const char* script_uri,
735755
const char* main,
736756
const char* package_root,
757+
Dart_IsolateFlags* flags,
737758
void* callback_data,
738759
char** error);
739760

@@ -894,6 +915,7 @@ DART_EXPORT bool Dart_IsVMFlagSet(const char* flag_name);
894915
* Provided only for advisory purposes to improve debugging messages.
895916
* \param snapshot A buffer containing a snapshot of the isolate or
896917
* NULL if no snapshot is provided.
918+
* \param flags Pointer to VM specific flags or NULL for default flags.
897919
* \param callback_data Embedder data. This data will be passed to
898920
* the Dart_IsolateCreateCallback when new isolates are spawned from
899921
* this parent isolate.
@@ -905,6 +927,7 @@ DART_EXPORT bool Dart_IsVMFlagSet(const char* flag_name);
905927
DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* script_uri,
906928
const char* main,
907929
const uint8_t* snapshot,
930+
Dart_IsolateFlags* flags,
908931
void* callback_data,
909932
char** error);
910933
/* TODO(turnidge): Document behavior when there is already a current

runtime/lib/isolate.cc

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -171,21 +171,20 @@ static bool CreateIsolate(Isolate* parent_isolate,
171171
return false;
172172
}
173173

174+
Dart_IsolateFlags api_flags;
175+
state->isolate_flags()->CopyTo(&api_flags);
176+
174177
void* init_data = parent_isolate->init_callback_data();
175178
Isolate* child_isolate = reinterpret_cast<Isolate*>(
176179
(callback)(state->script_url(),
177180
state->function_name(),
178181
state->package_root(),
182+
&api_flags,
179183
init_data,
180184
error));
181185
if (child_isolate == NULL) {
182186
return false;
183187
}
184-
// TODO(iposva): Evaluate whether it's ok to override the embedder's setup.
185-
// Currently the strict_compilation flag is ignored if it's false and
186-
// checked-mode was enabled using a command-line flag. The command-line flag
187-
// overrides the user code's request.
188-
child_isolate->set_strict_compilation(state->checked_mode());
189188
if (!state->is_spawn_uri()) {
190189
// For isolates spawned using the spawn semantics we set
191190
// the origin_id to the origin_id of the parent isolate.
@@ -234,12 +233,10 @@ DEFINE_NATIVE_ENTRY(Isolate_spawnFunction, 4) {
234233
#endif
235234
// Get the parent function so that we get the right function name.
236235
func = func.parent_function();
237-
bool checkedFlag = isolate->strict_compilation();
238236
Spawn(isolate, new IsolateSpawnState(port.Id(),
239237
func,
240238
message,
241-
paused.value(),
242-
checkedFlag));
239+
paused.value()));
243240
return Object::null();
244241
}
245242
}
@@ -278,20 +275,19 @@ DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 7) {
278275
utf8_package_root[len] = '\0';
279276
}
280277

281-
bool checkedFlag;
282-
if (checked.IsNull()) {
283-
checkedFlag = isolate->strict_compilation();
284-
} else {
285-
checkedFlag = checked.value();
278+
IsolateSpawnState* state = new IsolateSpawnState(port.Id(),
279+
canonical_uri,
280+
utf8_package_root,
281+
args,
282+
message,
283+
paused.value());
284+
// If we were passed a value then override the default flags state for
285+
// checked mode.
286+
if (!checked.IsNull()) {
287+
state->isolate_flags()->set_checked(checked.value());
286288
}
287289

288-
Spawn(isolate, new IsolateSpawnState(port.Id(),
289-
canonical_uri,
290-
utf8_package_root,
291-
args,
292-
message,
293-
paused.value(),
294-
checkedFlag));
290+
Spawn(isolate, state);
295291
return Object::null();
296292
}
297293

runtime/lib/object.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ DEFINE_NATIVE_ENTRY(Object_as, 4) {
271271
location, instance_type_name, type_name,
272272
dst_name, Object::null_string());
273273
} else {
274-
ASSERT(Isolate::Current()->TypeChecksEnabled());
274+
ASSERT(isolate->flags().type_checks());
275275
bound_error_message = String::New(bound_error.ToErrorCString());
276276
Exceptions::CreateAndThrowTypeError(
277277
location, instance_type_name, Symbols::Empty(),

runtime/vm/ast.cc

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ AstNode* LoadStaticFieldNode::MakeAssignmentNode(AstNode* rhs) {
517517
if (field().is_final()) {
518518
return NULL;
519519
}
520-
if (Isolate::Current()->TypeChecksEnabled()) {
520+
if (Isolate::Current()->flags().type_checks()) {
521521
rhs = new AssignableNode(
522522
field().token_pos(),
523523
rhs,
@@ -557,11 +557,14 @@ AstNode* LoadIndexedNode::MakeAssignmentNode(AstNode* rhs) {
557557

558558

559559
AstNode* StaticGetterNode::MakeAssignmentNode(AstNode* rhs) {
560+
Thread* thread = Thread::Current();
561+
Zone* zone = thread->zone();
562+
Isolate* isolate = thread->isolate();
560563
if (is_super_getter()) {
561564
ASSERT(receiver() != NULL);
562565
const String& setter_name =
563-
String::ZoneHandle(Field::SetterSymbol(field_name_));
564-
Function& setter = Function::ZoneHandle(
566+
String::ZoneHandle(zone, Field::SetterSymbol(field_name_));
567+
Function& setter = Function::ZoneHandle(zone,
565568
Resolver::ResolveDynamicAnyArgs(cls(), setter_name));
566569
if (setter.IsNull() || setter.is_abstract()) {
567570
// No instance setter found in super class chain,
@@ -591,25 +594,27 @@ AstNode* StaticGetterNode::MakeAssignmentNode(AstNode* rhs) {
591594
return new StaticSetterNode(token_pos(), NULL, cls(), field_name_, rhs);
592595
}
593596

594-
Object& obj = Object::Handle(prefix.LookupObject(field_name_));
597+
Object& obj = Object::Handle(zone, prefix.LookupObject(field_name_));
595598
if (obj.IsField()) {
596-
const Field& field = Field::ZoneHandle(Field::Cast(obj).raw());
599+
const Field& field = Field::ZoneHandle(zone, Field::Cast(obj).raw());
597600
if (!field.is_final()) {
598-
if (Isolate::Current()->TypeChecksEnabled()) {
601+
if (isolate->flags().type_checks()) {
599602
rhs = new AssignableNode(field.token_pos(),
600603
rhs,
601-
AbstractType::ZoneHandle(field.type()),
604+
AbstractType::ZoneHandle(zone, field.type()),
602605
field_name_);
603606
}
604607
return new StoreStaticFieldNode(token_pos(), field, rhs);
605608
}
606609
}
607610

608611
// No field found in prefix. Look for a setter function.
609-
const String& setter_name = String::Handle(Field::SetterName(field_name_));
612+
const String& setter_name = String::Handle(zone,
613+
Field::SetterName(field_name_));
610614
obj = prefix.LookupObject(setter_name);
611615
if (obj.IsFunction()) {
612-
const Function& setter = Function::ZoneHandle(Function::Cast(obj).raw());
616+
const Function& setter = Function::ZoneHandle(zone,
617+
Function::Cast(obj).raw());
613618
ASSERT(setter.is_static() && setter.IsSetterFunction());
614619
return new StaticSetterNode(
615620
token_pos(), NULL, field_name_, setter, rhs);
@@ -622,25 +627,27 @@ AstNode* StaticGetterNode::MakeAssignmentNode(AstNode* rhs) {
622627

623628
if (owner().IsLibrary()) {
624629
const Library& library = Library::Cast(owner());
625-
Object& obj = Object::Handle(library.ResolveName(field_name_));
630+
Object& obj = Object::Handle(zone, library.ResolveName(field_name_));
626631
if (obj.IsField()) {
627-
const Field& field = Field::ZoneHandle(Field::Cast(obj).raw());
632+
const Field& field = Field::ZoneHandle(zone, Field::Cast(obj).raw());
628633
if (!field.is_final()) {
629-
if (Isolate::Current()->TypeChecksEnabled()) {
634+
if (isolate->flags().type_checks()) {
630635
rhs = new AssignableNode(field.token_pos(),
631636
rhs,
632-
AbstractType::ZoneHandle(field.type()),
637+
AbstractType::ZoneHandle(zone, field.type()),
633638
field_name_);
634639
}
635640
return new StoreStaticFieldNode(token_pos(), field, rhs);
636641
}
637642
}
638643

639644
// No field found in library. Look for a setter function.
640-
const String& setter_name = String::Handle(Field::SetterName(field_name_));
645+
const String& setter_name = String::Handle(zone,
646+
Field::SetterName(field_name_));
641647
obj = library.ResolveName(setter_name);
642648
if (obj.IsFunction()) {
643-
const Function& setter = Function::ZoneHandle(Function::Cast(obj).raw());
649+
const Function& setter = Function::ZoneHandle(zone,
650+
Function::Cast(obj).raw());
644651
ASSERT(setter.is_static() && setter.IsSetterFunction());
645652
return new StaticSetterNode(token_pos(), NULL, field_name_, setter, rhs);
646653
}
@@ -651,15 +658,16 @@ AstNode* StaticGetterNode::MakeAssignmentNode(AstNode* rhs) {
651658
}
652659

653660
const Function& setter =
654-
Function::ZoneHandle(cls().LookupSetterFunction(field_name_));
661+
Function::ZoneHandle(zone, cls().LookupSetterFunction(field_name_));
655662
if (!setter.IsNull() && setter.IsStaticFunction()) {
656663
return new StaticSetterNode(token_pos(), NULL, field_name_, setter, rhs);
657664
}
658665
// Could not find a static setter. Look for a field.
659666
// Access to a lazily initialized static field that has not yet been
660667
// initialized is compiled to a static implicit getter.
661668
// A setter may not exist for such a field.
662-
const Field& field = Field::ZoneHandle(cls().LookupStaticField(field_name_));
669+
const Field& field = Field::ZoneHandle(zone,
670+
cls().LookupStaticField(field_name_));
663671
if (!field.IsNull()) {
664672
if (field.is_final()) {
665673
// Attempting to assign to a final variable will cause a NoSuchMethodError
@@ -668,18 +676,19 @@ AstNode* StaticGetterNode::MakeAssignmentNode(AstNode* rhs) {
668676
return new StaticSetterNode(token_pos(), NULL, cls(), field_name_, rhs);
669677
}
670678
#if defined(DEBUG)
671-
const String& getter_name = String::Handle(Field::GetterName(field_name_));
679+
const String& getter_name = String::Handle(zone,
680+
Field::GetterName(field_name_));
672681
const Function& getter =
673-
Function::Handle(cls().LookupStaticFunction(getter_name));
682+
Function::Handle(zone, cls().LookupStaticFunction(getter_name));
674683
ASSERT(!getter.IsNull() &&
675684
(getter.kind() == RawFunction::kImplicitStaticFinalGetter));
676685
#endif
677-
if (Isolate::Current()->TypeChecksEnabled()) {
686+
if (isolate->flags().type_checks()) {
678687
rhs = new AssignableNode(
679688
field.token_pos(),
680689
rhs,
681-
AbstractType::ZoneHandle(field.type()),
682-
String::ZoneHandle(field.name()));
690+
AbstractType::ZoneHandle(zone, field.type()),
691+
String::ZoneHandle(zone, field.name()));
683692
}
684693
return new StoreStaticFieldNode(token_pos(), field, rhs);
685694
}

runtime/vm/benchmark_test.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class Benchmark {
8181

8282
Dart_Isolate CreateIsolate(const uint8_t* buffer) {
8383
char* err = NULL;
84-
isolate_ = Dart_CreateIsolate(NULL, NULL, buffer, NULL, &err);
84+
isolate_ = Dart_CreateIsolate(NULL, NULL, buffer, NULL, NULL, &err);
8585
EXPECT(isolate_ != NULL);
8686
free(err);
8787
return isolate_;

0 commit comments

Comments
 (0)