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

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

Issue 10837303: Make stackmaps store their actual length. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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 | 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 "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/bigint_operations.h" 10 #include "vm/bigint_operations.h"
(...skipping 6919 matching lines...) Expand 10 before | Expand all | Expand 10 after
6930 ASSERT(DeoptId(k) != deopt_id); 6930 ASSERT(DeoptId(k) != deopt_id);
6931 } 6931 }
6932 ASSERT(pc != PC(k)); 6932 ASSERT(pc != PC(k));
6933 } 6933 }
6934 } 6934 }
6935 } 6935 }
6936 #endif // DEBUG 6936 #endif // DEBUG
6937 } 6937 }
6938 6938
6939 6939
6940 void Stackmap::SetCode(const Code& code) const { 6940 void Stackmap::SetCode(const dart::Code& code) const {
srdjan 2012/08/21 16:06:04 Why dart:: ?
Kevin Millikin (Google) 2012/08/22 07:34:18 Because C++. Class Code is shadowed by the access
6941 StorePointer(&raw_ptr()->code_, code.raw()); 6941 StorePointer(&raw_ptr()->code_, code.raw());
6942 } 6942 }
6943 6943
6944 6944
6945 bool Stackmap::GetBit(intptr_t bit_index) const { 6945 bool Stackmap::GetBit(intptr_t bit_index) const {
6946 ASSERT(InRange(bit_index)); 6946 ASSERT(InRange(bit_index));
6947 int byte_index = bit_index >> kBitsPerByteLog2; 6947 int byte_index = bit_index >> kBitsPerByteLog2;
6948 int bit_remainder = bit_index & (kBitsPerByte - 1); 6948 int bit_remainder = bit_index & (kBitsPerByte - 1);
6949 uint8_t byte_mask = 1U << bit_remainder; 6949 uint8_t byte_mask = 1U << bit_remainder;
6950 uint8_t byte = raw_ptr()->data_[byte_index]; 6950 uint8_t byte = raw_ptr()->data_[byte_index];
6951 return (byte & byte_mask); 6951 return (byte & byte_mask);
6952 } 6952 }
6953 6953
6954 6954
6955 void Stackmap::SetBit(intptr_t bit_index, bool value) const { 6955 void Stackmap::SetBit(intptr_t bit_index, bool value) const {
6956 ASSERT(InRange(bit_index)); 6956 ASSERT(InRange(bit_index));
6957 int byte_index = bit_index >> kBitsPerByteLog2; 6957 int byte_index = bit_index >> kBitsPerByteLog2;
6958 int bit_remainder = bit_index & (kBitsPerByte - 1); 6958 int bit_remainder = bit_index & (kBitsPerByte - 1);
6959 uint8_t byte_mask = 1U << bit_remainder; 6959 uint8_t byte_mask = 1U << bit_remainder;
6960 uint8_t* byte_addr = &(raw_ptr()->data_[byte_index]); 6960 uint8_t* byte_addr = &(raw_ptr()->data_[byte_index]);
6961 if (value) { 6961 if (value) {
6962 *byte_addr |= byte_mask; 6962 *byte_addr |= byte_mask;
6963 } else { 6963 } else {
6964 *byte_addr &= ~byte_mask; 6964 *byte_addr &= ~byte_mask;
6965 } 6965 }
6966 } 6966 }
6967 6967
6968 6968
6969 RawStackmap* Stackmap::New(intptr_t pc_offset, 6969 RawStackmap* Stackmap::New(intptr_t pc_offset,
6970 intptr_t length_in_bits, 6970 intptr_t length,
6971 BitmapBuilder* bmap) { 6971 BitmapBuilder* bmap) {
6972 ASSERT(Object::stackmap_class() != Class::null()); 6972 ASSERT(Object::stackmap_class() != Class::null());
6973 ASSERT(bmap != NULL); 6973 ASSERT(bmap != NULL);
6974 Stackmap& result = Stackmap::Handle(); 6974 Stackmap& result = Stackmap::Handle();
6975 intptr_t length_in_bytes = 6975 // Guard against integer overflow of the instance size computation.
6976 Utils::RoundUp(length_in_bits, kBitsPerByte) / kBitsPerByte; 6976 intptr_t payload_size =
6977 if (length_in_bytes < 0 || length_in_bytes > kMaxLengthInBytes) { 6977 Utils::RoundUp(length, kBitsPerByte) / kBitsPerByte;
6978 if (payload_size < 0 ||
6979 payload_size >
6980 (kSmiMax - static_cast<intptr_t>(sizeof(RawStackmap)))) {
srdjan 2012/08/21 16:06:04 Add parenthesis
Kevin Millikin (Google) 2012/08/22 07:34:18 OK. Incorporated in an outstanding change list.
6978 // This should be caught before we reach here. 6981 // This should be caught before we reach here.
6979 FATAL1("Fatal error in Stackmap::New: invalid length %" PRIdPTR "\n", 6982 FATAL1("Fatal error in Stackmap::New: invalid length %" PRIdPTR "\n",
6980 length_in_bytes); 6983 length);
6981 } 6984 }
6982 { 6985 {
6983 // Stackmap data objects are associated with a code object, allocate them 6986 // Stackmap data objects are associated with a code object, allocate them
6984 // in old generation. 6987 // in old generation.
6985 RawObject* raw = Object::Allocate(Stackmap::kClassId, 6988 RawObject* raw = Object::Allocate(Stackmap::kClassId,
6986 Stackmap::InstanceSize(length_in_bytes), 6989 Stackmap::InstanceSize(length),
6987 Heap::kOld); 6990 Heap::kOld);
6988 NoGCScope no_gc; 6991 NoGCScope no_gc;
6989 result ^= raw; 6992 result ^= raw;
6990 result.set_bitmap_size_in_bytes(length_in_bytes); 6993 result.SetLength(length);
6991 } 6994 }
6992 // When constructing a stackmap we store the pc offset in the stackmap's 6995 // When constructing a stackmap we store the pc offset in the stackmap's
6993 // PC. StackmapTableBuilder::FinalizeStackmaps will replace it with the pc 6996 // PC. StackmapTableBuilder::FinalizeStackmaps will replace it with the pc
6994 // address. 6997 // address.
6995 ASSERT(pc_offset >= 0); 6998 ASSERT(pc_offset >= 0);
6996 result.SetPC(pc_offset); 6999 result.SetPC(pc_offset);
6997 for (intptr_t i = 0; i < length_in_bits; i++) { 7000 for (intptr_t i = 0; i < length; ++i) {
6998 result.SetBit(i, bmap->Get(i)); 7001 result.SetBit(i, bmap->Get(i));
6999 } 7002 }
7000 ASSERT(bmap->Maximum() < length_in_bits); 7003 ASSERT(bmap->Maximum() < length);
7001 result.SetMinBitIndex(bmap->Minimum());
7002 result.SetMaxBitIndex(bmap->Maximum());
7003 return result.raw(); 7004 return result.raw();
7004 } 7005 }
7005 7006
7006 7007
7007 void Stackmap::set_bitmap_size_in_bytes(intptr_t value) const {
7008 // This is only safe because we create a new Smi, which does not cause
7009 // heap allocation.
7010 raw_ptr()->bitmap_size_in_bytes_ = Smi::New(value);
7011 }
7012
7013
7014 const char* Stackmap::ToCString() const { 7008 const char* Stackmap::ToCString() const {
7015 if (IsNull()) { 7009 if (IsNull()) {
7016 return "{null}"; 7010 return "{null}";
7017 } else { 7011 } else {
7018 // Guard against integer overflow, though it is highly unlikely. 7012 const char* kFormat = "0x%" PRIxPTR ": ";
7019 if (MaximumBitIndex() > kIntptrMax / 4) { 7013 intptr_t fixed_length = OS::SNPrint(NULL, 0, kFormat, PC()) + 1;
7020 FATAL1("MaximumBitIndex() is unexpectedly large (%" PRIdPTR ")", 7014 Isolate* isolate = Isolate::Current();
7021 MaximumBitIndex()); 7015 // Guard against integer overflow in the computation of alloc_size.
7016 //
7017 // TODO(kmillikin): We could just truncate the string if someone
7018 // tries to print a 2 billion plus entry stackmap.
7019 if (Length() > (kIntptrMax - fixed_length)) {
7020 FATAL1("Length() is unexpectedly large (%" PRIdPTR ")", Length());
7022 } 7021 }
7023 intptr_t index = OS::SNPrint(NULL, 0, "0x%" PRIxPTR " { ", PC()); 7022 intptr_t alloc_size = fixed_length + Length();
7024 intptr_t alloc_size =
7025 index + ((MaximumBitIndex() + 1) * 2) + 2; // "{ 1 0 .... }".
7026 Isolate* isolate = Isolate::Current();
7027 char* chars = isolate->current_zone()->Alloc<char>(alloc_size); 7023 char* chars = isolate->current_zone()->Alloc<char>(alloc_size);
7028 index = OS::SNPrint(chars, alloc_size, "0x%" PRIxPTR " { ", PC()); 7024 intptr_t index = OS::SNPrint(chars, alloc_size, kFormat, PC());
7029 for (intptr_t i = 0; i <= MaximumBitIndex(); i++) { 7025 for (intptr_t i = 0; i < Length(); i++) {
7030 index += OS::SNPrint((chars + index), 7026 chars[index++] = IsObject(i) ? '1' : '0';
7031 (alloc_size - index),
7032 "%d ",
7033 IsObject(i) ? 1 : 0);
7034 } 7027 }
7035 OS::SNPrint((chars + index), (alloc_size - index), "}"); 7028 chars[index] = '\0';
7036 return chars; 7029 return chars;
7037 } 7030 }
7038 } 7031 }
7039 7032
7040 7033
7041 RawString* LocalVarDescriptors::GetName(intptr_t var_index) const { 7034 RawString* LocalVarDescriptors::GetName(intptr_t var_index) const {
7042 ASSERT(var_index < Length()); 7035 ASSERT(var_index < Length());
7043 const Array& names = Array::Handle(raw_ptr()->names_); 7036 const Array& names = Array::Handle(raw_ptr()->names_);
7044 ASSERT(Length() == names.Length()); 7037 ASSERT(Length() == names.Length());
7045 const String& name = String::CheckedHandle(names.At(var_index)); 7038 const String& name = String::CheckedHandle(names.At(var_index));
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
7337 } 7330 }
7338 ASSERT(Object::code_class() != Class::null()); 7331 ASSERT(Object::code_class() != Class::null());
7339 Code& result = Code::Handle(); 7332 Code& result = Code::Handle();
7340 { 7333 {
7341 uword size = Code::InstanceSize(pointer_offsets_length); 7334 uword size = Code::InstanceSize(pointer_offsets_length);
7342 RawObject* raw = Object::Allocate(Code::kClassId, size, Heap::kOld); 7335 RawObject* raw = Object::Allocate(Code::kClassId, size, Heap::kOld);
7343 NoGCScope no_gc; 7336 NoGCScope no_gc;
7344 result ^= raw; 7337 result ^= raw;
7345 result.set_pointer_offsets_length(pointer_offsets_length); 7338 result.set_pointer_offsets_length(pointer_offsets_length);
7346 result.set_is_optimized(false); 7339 result.set_is_optimized(false);
7347 result.set_spill_slot_count(0);
7348 result.set_comments(Comments::New(0)); 7340 result.set_comments(Comments::New(0));
7349 } 7341 }
7350 return result.raw(); 7342 return result.raw();
7351 } 7343 }
7352 7344
7353 7345
7354 RawCode* Code::FinalizeCode(const char* name, Assembler* assembler) { 7346 RawCode* Code::FinalizeCode(const char* name, Assembler* assembler) {
7355 ASSERT(assembler != NULL); 7347 ASSERT(assembler != NULL);
7356 7348
7357 // Allocate the Instructions object. 7349 // Allocate the Instructions object.
(...skipping 3984 matching lines...) Expand 10 before | Expand all | Expand 10 after
11342 } 11334 }
11343 return result.raw(); 11335 return result.raw();
11344 } 11336 }
11345 11337
11346 11338
11347 const char* WeakProperty::ToCString() const { 11339 const char* WeakProperty::ToCString() const {
11348 return "WeakProperty"; 11340 return "WeakProperty";
11349 } 11341 }
11350 11342
11351 } // namespace dart 11343 } // namespace dart
OLDNEW
« runtime/vm/object.h ('K') | « runtime/vm/object.h ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698