OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 static EntropySource entropy_source; | 56 static EntropySource entropy_source; |
57 | 57 |
58 | 58 |
59 bool V8::Initialize(Deserializer* des) { | 59 bool V8::Initialize(Deserializer* des) { |
60 // Setting --harmony implies all other harmony flags. | 60 // Setting --harmony implies all other harmony flags. |
61 // TODO(rossberg): Is there a better place to put this? | 61 // TODO(rossberg): Is there a better place to put this? |
62 if (FLAG_harmony) { | 62 if (FLAG_harmony) { |
63 FLAG_harmony_typeof = true; | 63 FLAG_harmony_typeof = true; |
64 FLAG_harmony_scoping = true; | 64 FLAG_harmony_scoping = true; |
65 FLAG_harmony_proxies = true; | 65 FLAG_harmony_proxies = true; |
66 FLAG_harmony_weakmaps = true; | 66 FLAG_harmony_collections = true; |
67 } | 67 } |
68 | 68 |
69 InitializeOncePerProcess(); | 69 InitializeOncePerProcess(); |
70 | 70 |
71 // The current thread may not yet had entered an isolate to run. | 71 // The current thread may not yet had entered an isolate to run. |
72 // Note the Isolate::Current() may be non-null because for various | 72 // Note the Isolate::Current() may be non-null because for various |
73 // initialization purposes an initializing thread may be assigned an isolate | 73 // initialization purposes an initializing thread may be assigned an isolate |
74 // but not actually enter it. | 74 // but not actually enter it. |
75 if (i::Isolate::CurrentPerIsolateThreadData() == NULL) { | 75 if (i::Isolate::CurrentPerIsolateThreadData() == NULL) { |
76 i::Isolate::EnterDefaultIsolate(); | 76 i::Isolate::EnterDefaultIsolate(); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 return (state[0] << 14) + (state[1] & 0x3FFFF); | 143 return (state[0] << 14) + (state[1] & 0x3FFFF); |
144 } | 144 } |
145 | 145 |
146 | 146 |
147 void V8::SetEntropySource(EntropySource source) { | 147 void V8::SetEntropySource(EntropySource source) { |
148 entropy_source = source; | 148 entropy_source = source; |
149 } | 149 } |
150 | 150 |
151 | 151 |
152 // Used by JavaScript APIs | 152 // Used by JavaScript APIs |
153 uint32_t V8::Random(Isolate* isolate) { | 153 uint32_t V8::Random(Context* context) { |
154 ASSERT(isolate == Isolate::Current()); | 154 ASSERT(context->IsGlobalContext()); |
155 return random_base(isolate->random_seed()); | 155 ByteArray* seed = context->random_seed(); |
| 156 return random_base(reinterpret_cast<uint32_t*>(seed->GetDataStartAddress())); |
156 } | 157 } |
157 | 158 |
158 | 159 |
159 // Used internally by the JIT and memory allocator for security | 160 // Used internally by the JIT and memory allocator for security |
160 // purposes. So, we keep a different state to prevent informations | 161 // purposes. So, we keep a different state to prevent informations |
161 // leaks that could be used in an exploit. | 162 // leaks that could be used in an exploit. |
162 uint32_t V8::RandomPrivate(Isolate* isolate) { | 163 uint32_t V8::RandomPrivate(Isolate* isolate) { |
163 ASSERT(isolate == Isolate::Current()); | 164 ASSERT(isolate == Isolate::Current()); |
164 return random_base(isolate->private_random_seed()); | 165 return random_base(isolate->private_random_seed()); |
165 } | 166 } |
166 | 167 |
167 | 168 |
168 bool V8::IdleNotification() { | 169 bool V8::IdleNotification() { |
169 // Returning true tells the caller that there is no need to call | 170 // Returning true tells the caller that there is no need to call |
170 // IdleNotification again. | 171 // IdleNotification again. |
171 if (!FLAG_use_idle_notification) return true; | 172 if (!FLAG_use_idle_notification) return true; |
172 | 173 |
173 // Tell the heap that it may want to adjust. | 174 // Tell the heap that it may want to adjust. |
174 return HEAP->IdleNotification(); | 175 return HEAP->IdleNotification(); |
175 } | 176 } |
176 | 177 |
177 | 178 |
178 // Use a union type to avoid type-aliasing optimizations in GCC. | 179 // Use a union type to avoid type-aliasing optimizations in GCC. |
179 typedef union { | 180 typedef union { |
180 double double_value; | 181 double double_value; |
181 uint64_t uint64_t_value; | 182 uint64_t uint64_t_value; |
182 } double_int_union; | 183 } double_int_union; |
183 | 184 |
184 | 185 |
185 Object* V8::FillHeapNumberWithRandom(Object* heap_number, Isolate* isolate) { | 186 Object* V8::FillHeapNumberWithRandom(Object* heap_number, |
186 uint64_t random_bits = Random(isolate); | 187 Context* context) { |
| 188 uint64_t random_bits = Random(context); |
187 // Make a double* from address (heap_number + sizeof(double)). | 189 // Make a double* from address (heap_number + sizeof(double)). |
188 double_int_union* r = reinterpret_cast<double_int_union*>( | 190 double_int_union* r = reinterpret_cast<double_int_union*>( |
189 reinterpret_cast<char*>(heap_number) + | 191 reinterpret_cast<char*>(heap_number) + |
190 HeapNumber::kValueOffset - kHeapObjectTag); | 192 HeapNumber::kValueOffset - kHeapObjectTag); |
191 // Convert 32 random bits to 0.(32 random bits) in a double | 193 // Convert 32 random bits to 0.(32 random bits) in a double |
192 // by computing: | 194 // by computing: |
193 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). | 195 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). |
194 const double binary_million = 1048576.0; | 196 const double binary_million = 1048576.0; |
195 r->double_value = binary_million; | 197 r->double_value = binary_million; |
196 r->uint64_t_value |= random_bits; | 198 r->uint64_t_value |= random_bits; |
(...skipping 30 matching lines...) Expand all Loading... |
227 ElementsAccessor::InitializeOncePerProcess(); | 229 ElementsAccessor::InitializeOncePerProcess(); |
228 | 230 |
229 if (FLAG_stress_compaction) { | 231 if (FLAG_stress_compaction) { |
230 FLAG_force_marking_deque_overflows = true; | 232 FLAG_force_marking_deque_overflows = true; |
231 FLAG_gc_global = true; | 233 FLAG_gc_global = true; |
232 FLAG_max_new_space_size = (1 << (kPageSizeBits - 10)) * 2; | 234 FLAG_max_new_space_size = (1 << (kPageSizeBits - 10)) * 2; |
233 } | 235 } |
234 } | 236 } |
235 | 237 |
236 } } // namespace v8::internal | 238 } } // namespace v8::internal |
OLD | NEW |