| OLD | NEW |
| 1 // Copyright (c) 2014, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dartino 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 #include "src/vm/heap.h" | 5 #include "src/vm/heap.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "src/shared/assert.h" | 9 #include "src/shared/assert.h" |
| 10 #include "src/shared/flags.h" | 10 #include "src/shared/flags.h" |
| 11 #include "src/vm/object.h" | 11 #include "src/vm/object.h" |
| 12 | 12 |
| 13 namespace fletch { | 13 namespace dartino { |
| 14 | 14 |
| 15 Heap::Heap(RandomXorShift* random, int maximum_initial_size) | 15 Heap::Heap(RandomXorShift* random, int maximum_initial_size) |
| 16 : random_(random), | 16 : random_(random), |
| 17 space_(new SemiSpace(maximum_initial_size)), | 17 space_(new SemiSpace(maximum_initial_size)), |
| 18 old_space_(new OldSpace(0)), | 18 old_space_(new OldSpace(0)), |
| 19 weak_pointers_(NULL), | 19 weak_pointers_(NULL), |
| 20 foreign_memory_(0), | 20 foreign_memory_(0), |
| 21 allocations_have_taken_place_(false) { | 21 allocations_have_taken_place_(false) { |
| 22 AdjustAllocationBudget(); | 22 AdjustAllocationBudget(); |
| 23 AdjustOldAllocationBudget(); | 23 AdjustOldAllocationBudget(); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 LargeInteger* result = reinterpret_cast<LargeInteger*>(raw_result); | 102 LargeInteger* result = reinterpret_cast<LargeInteger*>(raw_result); |
| 103 result->set_class(the_class); | 103 result->set_class(the_class); |
| 104 result->set_value(value); | 104 result->set_value(value); |
| 105 return LargeInteger::cast(result); | 105 return LargeInteger::cast(result); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void Heap::TryDeallocInteger(LargeInteger* object) { | 108 void Heap::TryDeallocInteger(LargeInteger* object) { |
| 109 TryDealloc(object, LargeInteger::AllocationSize()); | 109 TryDealloc(object, LargeInteger::AllocationSize()); |
| 110 } | 110 } |
| 111 | 111 |
| 112 Object* Heap::CreateDouble(Class* the_class, fletch_double value) { | 112 Object* Heap::CreateDouble(Class* the_class, dartino_double value) { |
| 113 ASSERT(the_class->instance_format().type() == InstanceFormat::DOUBLE_TYPE); | 113 ASSERT(the_class->instance_format().type() == InstanceFormat::DOUBLE_TYPE); |
| 114 int size = Double::AllocationSize(); | 114 int size = Double::AllocationSize(); |
| 115 Object* raw_result = Allocate(size); | 115 Object* raw_result = Allocate(size); |
| 116 if (raw_result->IsFailure()) return raw_result; | 116 if (raw_result->IsFailure()) return raw_result; |
| 117 Double* result = reinterpret_cast<Double*>(raw_result); | 117 Double* result = reinterpret_cast<Double*>(raw_result); |
| 118 result->set_class(the_class); | 118 result->set_class(the_class); |
| 119 result->set_value(value); | 119 result->set_value(value); |
| 120 return Double::cast(result); | 120 return Double::cast(result); |
| 121 } | 121 } |
| 122 | 122 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 void Heap::RemoveWeakPointer(HeapObject* object) { | 297 void Heap::RemoveWeakPointer(HeapObject* object) { |
| 298 WeakPointer::Remove(&weak_pointers_, object); | 298 WeakPointer::Remove(&weak_pointers_, object); |
| 299 } | 299 } |
| 300 | 300 |
| 301 void Heap::ProcessWeakPointers(Space* space) { | 301 void Heap::ProcessWeakPointers(Space* space) { |
| 302 WeakPointer::Process(space, &weak_pointers_, this); | 302 WeakPointer::Process(space, &weak_pointers_, this); |
| 303 } | 303 } |
| 304 | 304 |
| 305 #ifdef DEBUG | 305 #ifdef DEBUG |
| 306 void Heap::Find(uword word) { | 306 void Heap::Find(uword word) { |
| 307 space_->Find(word, "Fletch heap"); | 307 space_->Find(word, "Dartino heap"); |
| 308 old_space_->Find(word, "oldspace"); | 308 old_space_->Find(word, "oldspace"); |
| 309 #ifdef FLETCH_TARGET_OS_LINUX | 309 #ifdef DARTINO_TARGET_OS_LINUX |
| 310 FILE* fp = fopen("/proc/self/maps", "r"); | 310 FILE* fp = fopen("/proc/self/maps", "r"); |
| 311 if (fp == NULL) return; | 311 if (fp == NULL) return; |
| 312 size_t length; | 312 size_t length; |
| 313 char* line = NULL; | 313 char* line = NULL; |
| 314 while (getline(&line, &length, fp) > 0) { | 314 while (getline(&line, &length, fp) > 0) { |
| 315 char* start; | 315 char* start; |
| 316 char* end; | 316 char* end; |
| 317 char r, w, x, p; // Permissions. | 317 char r, w, x, p; // Permissions. |
| 318 char filename[1000]; | 318 char filename[1000]; |
| 319 memset(filename, 0, 1000); | 319 memset(filename, 0, 1000); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 337 fprintf(stderr, "Found %p in %s at %p\n", reinterpret_cast<void*>(w), | 337 fprintf(stderr, "Found %p in %s at %p\n", reinterpret_cast<void*>(w), |
| 338 filename, current); | 338 filename, current); |
| 339 } | 339 } |
| 340 } | 340 } |
| 341 } | 341 } |
| 342 fclose(fp); | 342 fclose(fp); |
| 343 #endif // __linux | 343 #endif // __linux |
| 344 } | 344 } |
| 345 #endif // DEBUG | 345 #endif // DEBUG |
| 346 | 346 |
| 347 } // namespace fletch | 347 } // namespace dartino |
| OLD | NEW |