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

Side by Side Diff: src/allocation.cc

Issue 5005001: Split globals.h into two parts, where only one depends on V8. (Closed)
Patch Set: Addressed review comments. Created 10 years, 1 month 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
« no previous file with comments | « src/allocation.h ('k') | src/api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include <stdlib.h> 28 #include <stdlib.h>
29 29
30 #include "v8.h" 30 #include "../include/v8stdint.h"
31 #include "globals.h"
32 #include "checks.h"
33 #include "allocation.h"
34 #include "utils.h"
31 35
32 namespace v8 { 36 namespace v8 {
33 namespace internal { 37 namespace internal {
34 38
35
36 void* Malloced::New(size_t size) { 39 void* Malloced::New(size_t size) {
37 ASSERT(NativeAllocationChecker::allocation_allowed()); 40 ASSERT(NativeAllocationChecker::allocation_allowed());
38 void* result = malloc(size); 41 void* result = malloc(size);
39 if (result == NULL) V8::FatalProcessOutOfMemory("Malloced operator new"); 42 if (result == NULL) {
43 v8::internal::FatalProcessOutOfMemory("Malloced operator new");
44 }
40 return result; 45 return result;
41 } 46 }
42 47
43 48
44 void Malloced::Delete(void* p) { 49 void Malloced::Delete(void* p) {
45 free(p); 50 free(p);
46 } 51 }
47 52
48 53
49 void Malloced::FatalProcessOutOfMemory() { 54 void Malloced::FatalProcessOutOfMemory() {
50 V8::FatalProcessOutOfMemory("Out of memory"); 55 v8::internal::FatalProcessOutOfMemory("Out of memory");
51 } 56 }
52 57
53 58
54 #ifdef DEBUG 59 #ifdef DEBUG
55 60
56 static void* invalid = static_cast<void*>(NULL); 61 static void* invalid = static_cast<void*>(NULL);
57 62
58 void* Embedded::operator new(size_t size) { 63 void* Embedded::operator new(size_t size) {
59 UNREACHABLE(); 64 UNREACHABLE();
60 return invalid; 65 return invalid;
(...skipping 14 matching lines...) Expand all
75 void AllStatic::operator delete(void* p) { 80 void AllStatic::operator delete(void* p) {
76 UNREACHABLE(); 81 UNREACHABLE();
77 } 82 }
78 83
79 #endif 84 #endif
80 85
81 86
82 char* StrDup(const char* str) { 87 char* StrDup(const char* str) {
83 int length = StrLength(str); 88 int length = StrLength(str);
84 char* result = NewArray<char>(length + 1); 89 char* result = NewArray<char>(length + 1);
85 memcpy(result, str, length * kCharSize); 90 memcpy(result, str, length);
86 result[length] = '\0'; 91 result[length] = '\0';
87 return result; 92 return result;
88 } 93 }
89 94
90 95
91 char* StrNDup(const char* str, int n) { 96 char* StrNDup(const char* str, int n) {
92 int length = StrLength(str); 97 int length = StrLength(str);
93 if (n < length) length = n; 98 if (n < length) length = n;
94 char* result = NewArray<char>(length + 1); 99 char* result = NewArray<char>(length + 1);
95 memcpy(result, str, length * kCharSize); 100 memcpy(result, str, length);
96 result[length] = '\0'; 101 result[length] = '\0';
97 return result; 102 return result;
98 } 103 }
99 104
100 105
101 int NativeAllocationChecker::allocation_disallowed_ = 0; 106 int NativeAllocationChecker::allocation_disallowed_ = 0;
102 107
103 108
104 PreallocatedStorage PreallocatedStorage::in_use_list_(0); 109 PreallocatedStorage PreallocatedStorage::in_use_list_(0);
105 PreallocatedStorage PreallocatedStorage::free_list_(0); 110 PreallocatedStorage PreallocatedStorage::free_list_(0);
(...skipping 11 matching lines...) Expand all
117 preallocated_ = true; 122 preallocated_ = true;
118 } 123 }
119 124
120 125
121 void* PreallocatedStorage::New(size_t size) { 126 void* PreallocatedStorage::New(size_t size) {
122 if (!preallocated_) { 127 if (!preallocated_) {
123 return FreeStoreAllocationPolicy::New(size); 128 return FreeStoreAllocationPolicy::New(size);
124 } 129 }
125 ASSERT(free_list_.next_ != &free_list_); 130 ASSERT(free_list_.next_ != &free_list_);
126 ASSERT(free_list_.previous_ != &free_list_); 131 ASSERT(free_list_.previous_ != &free_list_);
132
127 size = (size + kPointerSize - 1) & ~(kPointerSize - 1); 133 size = (size + kPointerSize - 1) & ~(kPointerSize - 1);
128 // Search for exact fit. 134 // Search for exact fit.
129 for (PreallocatedStorage* storage = free_list_.next_; 135 for (PreallocatedStorage* storage = free_list_.next_;
130 storage != &free_list_; 136 storage != &free_list_;
131 storage = storage->next_) { 137 storage = storage->next_) {
132 if (storage->size_ == size) { 138 if (storage->size_ == size) {
133 storage->Unlink(); 139 storage->Unlink();
134 storage->LinkTo(&in_use_list_); 140 storage->LinkTo(&in_use_list_);
135 return reinterpret_cast<void*>(storage + 1); 141 return reinterpret_cast<void*>(storage + 1);
136 } 142 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 previous_->next_ = next_; 195 previous_->next_ = next_;
190 } 196 }
191 197
192 198
193 PreallocatedStorage::PreallocatedStorage(size_t size) 199 PreallocatedStorage::PreallocatedStorage(size_t size)
194 : size_(size) { 200 : size_(size) {
195 previous_ = next_ = this; 201 previous_ = next_ = this;
196 } 202 }
197 203
198 } } // namespace v8::internal 204 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/allocation.h ('k') | src/api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698