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

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

Issue 10796004: Consolidate a few fields in RawFunction using bitfields. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 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 | Annotate | Revision Log
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/object.h" 5 #include "vm/object.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 3624 matching lines...) Expand 10 before | Expand all | Expand 10 after
3635 parameter_names.SetAt(index, value); 3635 parameter_names.SetAt(index, value);
3636 } 3636 }
3637 3637
3638 3638
3639 void Function::set_parameter_names(const Array& value) const { 3639 void Function::set_parameter_names(const Array& value) const {
3640 StorePointer(&raw_ptr()->parameter_names_, value.raw()); 3640 StorePointer(&raw_ptr()->parameter_names_, value.raw());
3641 } 3641 }
3642 3642
3643 3643
3644 void Function::set_kind(RawFunction::Kind value) const { 3644 void Function::set_kind(RawFunction::Kind value) const {
3645 raw_ptr()->kind_ = value; 3645 raw()->SetKind(value);
3646 } 3646 }
3647 3647
3648 3648
3649 void Function::set_is_static(bool is_static) const { 3649 void Function::set_is_static(bool is_static) const {
3650 raw_ptr()->is_static_ = is_static; 3650 raw()->SetIsStatic(is_static);
3651 } 3651 }
3652 3652
3653 3653
3654 void Function::set_is_const(bool is_const) const { 3654 void Function::set_is_const(bool is_const) const {
3655 raw_ptr()->is_const_ = is_const; 3655 raw()->SetIsConst(is_const);
3656 } 3656 }
3657 3657
3658 3658
3659 void Function::set_token_pos(intptr_t pos) const { 3659 void Function::set_token_pos(intptr_t pos) const {
3660 ASSERT(pos >= 0); 3660 ASSERT(pos >= 0);
3661 raw_ptr()->token_pos_ = pos; 3661 raw_ptr()->token_pos_ = pos;
3662 } 3662 }
3663 3663
3664 3664
3665 void Function::set_num_fixed_parameters(intptr_t n) const { 3665 void Function::set_num_fixed_parameters(intptr_t n) const {
3666 ASSERT(n >= 0); 3666 ASSERT(n >= 0);
3667 raw_ptr()->num_fixed_parameters_ = n; 3667 raw_ptr()->num_fixed_parameters_ = n;
3668 } 3668 }
3669 3669
3670 3670
3671 void Function::set_num_optional_parameters(intptr_t n) const { 3671 void Function::set_num_optional_parameters(intptr_t n) const {
3672 ASSERT(n >= 0); 3672 ASSERT(n >= 0);
3673 raw_ptr()->num_optional_parameters_ = n; 3673 raw_ptr()->num_optional_parameters_ = n;
3674 } 3674 }
3675 3675
3676 3676
3677 void Function::set_is_optimizable(bool value) const { 3677 void Function::set_is_optimizable(bool value) const {
3678 raw_ptr()->is_optimizable_ = value; 3678 raw()->SetIsOptimizable(value);
3679 } 3679 }
3680 3680
3681 3681
3682 void Function::set_is_native(bool value) const { 3682 void Function::set_is_native(bool value) const {
3683 raw_ptr()->is_native_ = value; 3683 raw()->SetIsNative(value);
3684 }
3685
3686
3687 void Function::set_is_abstract(bool value) const {
3688 raw()->SetIsAbstract(value);
3684 } 3689 }
3685 3690
3686 3691
3687 intptr_t Function::NumberOfParameters() const { 3692 intptr_t Function::NumberOfParameters() const {
3688 return num_fixed_parameters() + num_optional_parameters(); 3693 return num_fixed_parameters() + num_optional_parameters();
3689 } 3694 }
3690 3695
3691 3696
3692 intptr_t Function::NumberOfImplicitParameters() const { 3697 intptr_t Function::NumberOfImplicitParameters() const {
3693 if (kind() == RawFunction::kConstructor) { 3698 if (kind() == RawFunction::kConstructor) {
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
4001 Function::InstanceSize(), 4006 Function::InstanceSize(),
4002 Heap::kOld); 4007 Heap::kOld);
4003 return reinterpret_cast<RawFunction*>(raw); 4008 return reinterpret_cast<RawFunction*>(raw);
4004 } 4009 }
4005 4010
4006 4011
4007 RawFunction* Function::New(const String& name, 4012 RawFunction* Function::New(const String& name,
4008 RawFunction::Kind kind, 4013 RawFunction::Kind kind,
4009 bool is_static, 4014 bool is_static,
4010 bool is_const, 4015 bool is_const,
4016 bool is_abstract,
4011 intptr_t token_pos) { 4017 intptr_t token_pos) {
4012 ASSERT(name.IsOneByteString()); 4018 ASSERT(name.IsOneByteString());
4013 const Function& result = Function::Handle(Function::New()); 4019 const Function& result = Function::Handle(Function::New());
4014 result.set_parameter_types(Array::Handle(Array::Empty())); 4020 result.set_parameter_types(Array::Handle(Array::Empty()));
4015 result.set_parameter_names(Array::Handle(Array::Empty())); 4021 result.set_parameter_names(Array::Handle(Array::Empty()));
4016 result.set_name(name); 4022 result.set_name(name);
4017 result.set_kind(kind); 4023 result.set_kind(kind);
4018 result.set_is_static(is_static); 4024 result.set_is_static(is_static);
4019 result.set_is_const(is_const); 4025 result.set_is_const(is_const);
4020 result.set_token_pos(token_pos); 4026 result.set_token_pos(token_pos);
4021 result.set_end_token_pos(token_pos); 4027 result.set_end_token_pos(token_pos);
4022 result.set_num_fixed_parameters(0); 4028 result.set_num_fixed_parameters(0);
4023 result.set_num_optional_parameters(0); 4029 result.set_num_optional_parameters(0);
4024 result.set_usage_counter(0); 4030 result.set_usage_counter(0);
4025 result.set_deoptimization_counter(0); 4031 result.set_deoptimization_counter(0);
4026 result.set_is_optimizable(true); 4032 result.set_is_optimizable(true);
4027 result.set_is_native(false); 4033 result.set_is_native(false);
4034 result.set_is_abstract(is_abstract);
4028 return result.raw(); 4035 return result.raw();
4029 } 4036 }
4030 4037
4031 4038
4032 RawFunction* Function::NewClosureFunction(const String& name, 4039 RawFunction* Function::NewClosureFunction(const String& name,
4033 const Function& parent, 4040 const Function& parent,
4034 intptr_t token_pos) { 4041 intptr_t token_pos) {
4035 ASSERT(name.IsOneByteString()); 4042 ASSERT(name.IsOneByteString());
4036 ASSERT(!parent.IsNull()); 4043 ASSERT(!parent.IsNull());
4037 const Class& parent_class = Class::Handle(parent.owner()); 4044 const Class& parent_class = Class::Handle(parent.owner());
4038 ASSERT(!parent_class.IsNull()); 4045 ASSERT(!parent_class.IsNull());
4039 const Function& result = Function::Handle( 4046 const Function& result = Function::Handle(
4040 Function::New(name, 4047 Function::New(name,
4041 RawFunction::kClosureFunction, 4048 RawFunction::kClosureFunction,
4042 /* is_static = */ parent.is_static(), 4049 /* is_static = */ parent.is_static(),
4043 /* is_const = */ false, 4050 /* is_const = */ false,
4051 /* is_abstract = */ false,
4044 token_pos)); 4052 token_pos));
4045 result.set_parent_function(parent); 4053 result.set_parent_function(parent);
4046 result.set_owner(parent_class); 4054 result.set_owner(parent_class);
4047 return result.raw(); 4055 return result.raw();
4048 } 4056 }
4049 4057
4050 4058
4051 RawFunction* Function::ImplicitClosureFunction() const { 4059 RawFunction* Function::ImplicitClosureFunction() const {
4052 // Return the existing implicit closure function if any. 4060 // Return the existing implicit closure function if any.
4053 if (raw_ptr()->implicit_closure_function_ != Function::null()) { 4061 if (raw_ptr()->implicit_closure_function_ != Function::null()) {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
4229 return true; 4237 return true;
4230 } 4238 }
4231 4239
4232 4240
4233 bool Function::HasOptimizedCode() const { 4241 bool Function::HasOptimizedCode() const {
4234 return HasCode() && Code::Handle(raw_ptr()->code_).is_optimized(); 4242 return HasCode() && Code::Handle(raw_ptr()->code_).is_optimized();
4235 } 4243 }
4236 4244
4237 4245
4238 const char* Function::ToCString() const { 4246 const char* Function::ToCString() const {
4239 const char* f0 = is_static() ? " static" : ""; 4247 const char* static_str = is_static() ? " static" : "";
4240 const char* f1 = NULL; 4248 const char* abstract_str = is_abstract() ? " abstract" : "";
4241 const char* f2 = is_const() ? " const" : ""; 4249 const char* kind_str = NULL;
4250 const char* const_str = is_const() ? " const" : "";
4242 switch (kind()) { 4251 switch (kind()) {
4243 case RawFunction::kFunction: 4252 case RawFunction::kFunction:
4244 case RawFunction::kClosureFunction: 4253 case RawFunction::kClosureFunction:
4245 case RawFunction::kGetterFunction: 4254 case RawFunction::kGetterFunction:
4246 case RawFunction::kSetterFunction: 4255 case RawFunction::kSetterFunction:
4247 f1 = ""; 4256 kind_str = "";
4248 break; 4257 break;
4249 case RawFunction::kSignatureFunction: 4258 case RawFunction::kSignatureFunction:
4250 f1 = " signature"; 4259 kind_str = " signature";
4251 break;
4252 case RawFunction::kAbstract:
4253 f1 = " abstract";
4254 break; 4260 break;
4255 case RawFunction::kConstructor: 4261 case RawFunction::kConstructor:
4256 f1 = is_static() ? " factory" : " constructor"; 4262 kind_str = is_static() ? " factory" : " constructor";
4257 break; 4263 break;
4258 case RawFunction::kImplicitGetter: 4264 case RawFunction::kImplicitGetter:
4259 f1 = " getter"; 4265 kind_str = " getter";
4260 break; 4266 break;
4261 case RawFunction::kImplicitSetter: 4267 case RawFunction::kImplicitSetter:
4262 f1 = " setter"; 4268 kind_str = " setter";
4263 break; 4269 break;
4264 case RawFunction::kConstImplicitGetter: 4270 case RawFunction::kConstImplicitGetter:
4265 f1 = " const-getter"; 4271 kind_str = " const-getter";
4266 break; 4272 break;
4267 default: 4273 default:
4268 UNREACHABLE(); 4274 UNREACHABLE();
4269 } 4275 }
4270 const char* kFormat = "Function '%s':%s%s%s."; 4276 const char* kFormat = "Function '%s':%s%s%s%s.";
4271 const char* function_name = String::Handle(name()).ToCString(); 4277 const char* function_name = String::Handle(name()).ToCString();
4272 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, f0, f1, f2) + 1; 4278 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name,
4279 static_str, abstract_str, kind_str, const_str) + 1;
4273 char* chars = reinterpret_cast<char*>( 4280 char* chars = reinterpret_cast<char*>(
4274 Isolate::Current()->current_zone()->Allocate(len)); 4281 Isolate::Current()->current_zone()->Allocate(len));
4275 OS::SNPrint(chars, len, kFormat, function_name, f0, f1, f2); 4282 OS::SNPrint(chars, len, kFormat, function_name,
4283 static_str, abstract_str, kind_str, const_str);
4276 return chars; 4284 return chars;
4277 } 4285 }
4278 4286
4279 4287
4280 RawString* Field::GetterName(const String& field_name) { 4288 RawString* Field::GetterName(const String& field_name) {
4281 String& str = String::Handle(); 4289 String& str = String::Handle();
4282 str = String::New(kGetterPrefix); 4290 str = String::New(kGetterPrefix);
4283 str = String::Concat(str, field_name); 4291 str = String::Concat(str, field_name);
4284 return str.raw(); 4292 return str.raw();
4285 } 4293 }
(...skipping 6494 matching lines...) Expand 10 before | Expand all | Expand 10 after
10780 const String& str = String::Handle(pattern()); 10788 const String& str = String::Handle(pattern());
10781 const char* format = "JSRegExp: pattern=%s flags=%s"; 10789 const char* format = "JSRegExp: pattern=%s flags=%s";
10782 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 10790 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
10783 char* chars = reinterpret_cast<char*>( 10791 char* chars = reinterpret_cast<char*>(
10784 Isolate::Current()->current_zone()->Allocate(len + 1)); 10792 Isolate::Current()->current_zone()->Allocate(len + 1));
10785 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 10793 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
10786 return chars; 10794 return chars;
10787 } 10795 }
10788 10796
10789 } // namespace dart 10797 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698