| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-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 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "factory.h" | 30 #include "factory.h" |
| 31 #include "string-stream.h" | 31 #include "string-stream.h" |
| 32 | 32 |
| 33 namespace v8 { | 33 namespace v8 { |
| 34 namespace internal { | 34 namespace internal { |
| 35 | 35 |
| 36 static const int kMentionedObjectCacheMaxSize = 256; | 36 static const int kMentionedObjectCacheMaxSize = 256; |
| 37 static List<HeapObject*, PreallocatedStorage>* debug_object_cache = NULL; | |
| 38 static Object* current_security_token = NULL; | |
| 39 | |
| 40 | 37 |
| 41 char* HeapStringAllocator::allocate(unsigned bytes) { | 38 char* HeapStringAllocator::allocate(unsigned bytes) { |
| 42 space_ = NewArray<char>(bytes); | 39 space_ = NewArray<char>(bytes); |
| 43 return space_; | 40 return space_; |
| 44 } | 41 } |
| 45 | 42 |
| 46 | 43 |
| 47 NoAllocationStringAllocator::NoAllocationStringAllocator(char* memory, | 44 NoAllocationStringAllocator::NoAllocationStringAllocator(char* memory, |
| 48 unsigned size) { | 45 unsigned size) { |
| 49 size_ = size; | 46 size_ = size; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 void StringStream::PrintObject(Object* o) { | 185 void StringStream::PrintObject(Object* o) { |
| 189 o->ShortPrint(this); | 186 o->ShortPrint(this); |
| 190 if (o->IsString()) { | 187 if (o->IsString()) { |
| 191 if (String::cast(o)->length() <= String::kMaxShortPrintLength) { | 188 if (String::cast(o)->length() <= String::kMaxShortPrintLength) { |
| 192 return; | 189 return; |
| 193 } | 190 } |
| 194 } else if (o->IsNumber() || o->IsOddball()) { | 191 } else if (o->IsNumber() || o->IsOddball()) { |
| 195 return; | 192 return; |
| 196 } | 193 } |
| 197 if (o->IsHeapObject()) { | 194 if (o->IsHeapObject()) { |
| 195 DebugObjectCache* debug_object_cache = Isolate::Current()-> |
| 196 string_stream_debug_object_cache(); |
| 198 for (int i = 0; i < debug_object_cache->length(); i++) { | 197 for (int i = 0; i < debug_object_cache->length(); i++) { |
| 199 if ((*debug_object_cache)[i] == o) { | 198 if ((*debug_object_cache)[i] == o) { |
| 200 Add("#%d#", i); | 199 Add("#%d#", i); |
| 201 return; | 200 return; |
| 202 } | 201 } |
| 203 } | 202 } |
| 204 if (debug_object_cache->length() < kMentionedObjectCacheMaxSize) { | 203 if (debug_object_cache->length() < kMentionedObjectCacheMaxSize) { |
| 205 Add("#%d#", debug_object_cache->length()); | 204 Add("#%d#", debug_object_cache->length()); |
| 206 debug_object_cache->Add(HeapObject::cast(o)); | 205 debug_object_cache->Add(HeapObject::cast(o)); |
| 207 } else { | 206 } else { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 internal::PrintF("%s", &buffer_[position]); | 278 internal::PrintF("%s", &buffer_[position]); |
| 280 } | 279 } |
| 281 | 280 |
| 282 | 281 |
| 283 Handle<String> StringStream::ToString() { | 282 Handle<String> StringStream::ToString() { |
| 284 return Factory::NewStringFromUtf8(Vector<const char>(buffer_, length_)); | 283 return Factory::NewStringFromUtf8(Vector<const char>(buffer_, length_)); |
| 285 } | 284 } |
| 286 | 285 |
| 287 | 286 |
| 288 void StringStream::ClearMentionedObjectCache() { | 287 void StringStream::ClearMentionedObjectCache() { |
| 289 current_security_token = NULL; | 288 Isolate* isolate = Isolate::Current(); |
| 290 if (debug_object_cache == NULL) { | 289 isolate->set_string_stream_current_security_token(NULL); |
| 291 debug_object_cache = new List<HeapObject*, PreallocatedStorage>(0); | 290 if (isolate->string_stream_debug_object_cache() == NULL) { |
| 291 isolate->set_string_stream_debug_object_cache( |
| 292 new List<HeapObject*, PreallocatedStorage>(0)); |
| 292 } | 293 } |
| 293 debug_object_cache->Clear(); | 294 isolate->string_stream_debug_object_cache()->Clear(); |
| 294 } | 295 } |
| 295 | 296 |
| 296 | 297 |
| 297 #ifdef DEBUG | 298 #ifdef DEBUG |
| 298 bool StringStream::IsMentionedObjectCacheClear() { | 299 bool StringStream::IsMentionedObjectCacheClear() { |
| 299 return (debug_object_cache->length() == 0); | 300 return ( |
| 301 Isolate::Current()->string_stream_debug_object_cache()->length() == 0); |
| 300 } | 302 } |
| 301 #endif | 303 #endif |
| 302 | 304 |
| 303 | 305 |
| 304 bool StringStream::Put(String* str) { | 306 bool StringStream::Put(String* str) { |
| 305 return Put(str, 0, str->length()); | 307 return Put(str, 0, str->length()); |
| 306 } | 308 } |
| 307 | 309 |
| 308 | 310 |
| 309 bool StringStream::Put(String* str, int start, int end) { | 311 bool StringStream::Put(String* str, int start, int end) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 } | 407 } |
| 406 Add("\n"); | 408 Add("\n"); |
| 407 } | 409 } |
| 408 if (limit >= 10) { | 410 if (limit >= 10) { |
| 409 Add(" ...\n"); | 411 Add(" ...\n"); |
| 410 } | 412 } |
| 411 } | 413 } |
| 412 | 414 |
| 413 | 415 |
| 414 void StringStream::PrintMentionedObjectCache() { | 416 void StringStream::PrintMentionedObjectCache() { |
| 417 DebugObjectCache* debug_object_cache = |
| 418 Isolate::Current()->string_stream_debug_object_cache(); |
| 415 Add("==== Key ============================================\n\n"); | 419 Add("==== Key ============================================\n\n"); |
| 416 for (int i = 0; i < debug_object_cache->length(); i++) { | 420 for (int i = 0; i < debug_object_cache->length(); i++) { |
| 417 HeapObject* printee = (*debug_object_cache)[i]; | 421 HeapObject* printee = (*debug_object_cache)[i]; |
| 418 Add(" #%d# %p: ", i, printee); | 422 Add(" #%d# %p: ", i, printee); |
| 419 printee->ShortPrint(this); | 423 printee->ShortPrint(this); |
| 420 Add("\n"); | 424 Add("\n"); |
| 421 if (printee->IsJSObject()) { | 425 if (printee->IsJSObject()) { |
| 422 if (printee->IsJSValue()) { | 426 if (printee->IsJSValue()) { |
| 423 Add(" value(): %o\n", JSValue::cast(printee)->value()); | 427 Add(" value(): %o\n", JSValue::cast(printee)->value()); |
| 424 } | 428 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 437 PrintByteArray(ByteArray::cast(printee)); | 441 PrintByteArray(ByteArray::cast(printee)); |
| 438 } else if (printee->IsFixedArray()) { | 442 } else if (printee->IsFixedArray()) { |
| 439 unsigned int limit = FixedArray::cast(printee)->length(); | 443 unsigned int limit = FixedArray::cast(printee)->length(); |
| 440 PrintFixedArray(FixedArray::cast(printee), limit); | 444 PrintFixedArray(FixedArray::cast(printee), limit); |
| 441 } | 445 } |
| 442 } | 446 } |
| 443 } | 447 } |
| 444 | 448 |
| 445 | 449 |
| 446 void StringStream::PrintSecurityTokenIfChanged(Object* f) { | 450 void StringStream::PrintSecurityTokenIfChanged(Object* f) { |
| 447 if (!f->IsHeapObject() || !HEAP->Contains(HeapObject::cast(f))) { | 451 Isolate* isolate = Isolate::Current(); |
| 452 Heap* heap = isolate->heap(); |
| 453 if (!f->IsHeapObject() || !heap->Contains(HeapObject::cast(f))) { |
| 448 return; | 454 return; |
| 449 } | 455 } |
| 450 Map* map = HeapObject::cast(f)->map(); | 456 Map* map = HeapObject::cast(f)->map(); |
| 451 if (!map->IsHeapObject() || | 457 if (!map->IsHeapObject() || |
| 452 !HEAP->Contains(map) || | 458 !heap->Contains(map) || |
| 453 !map->IsMap() || | 459 !map->IsMap() || |
| 454 !f->IsJSFunction()) { | 460 !f->IsJSFunction()) { |
| 455 return; | 461 return; |
| 456 } | 462 } |
| 457 | 463 |
| 458 JSFunction* fun = JSFunction::cast(f); | 464 JSFunction* fun = JSFunction::cast(f); |
| 459 Object* perhaps_context = fun->unchecked_context(); | 465 Object* perhaps_context = fun->unchecked_context(); |
| 460 if (perhaps_context->IsHeapObject() && | 466 if (perhaps_context->IsHeapObject() && |
| 461 HEAP->Contains(HeapObject::cast(perhaps_context)) && | 467 heap->Contains(HeapObject::cast(perhaps_context)) && |
| 462 perhaps_context->IsContext()) { | 468 perhaps_context->IsContext()) { |
| 463 Context* context = fun->context(); | 469 Context* context = fun->context(); |
| 464 if (!HEAP->Contains(context)) { | 470 if (!heap->Contains(context)) { |
| 465 Add("(Function context is outside heap)\n"); | 471 Add("(Function context is outside heap)\n"); |
| 466 return; | 472 return; |
| 467 } | 473 } |
| 468 Object* token = context->global_context()->security_token(); | 474 Object* token = context->global_context()->security_token(); |
| 469 if (token != current_security_token) { | 475 if (token != isolate->string_stream_current_security_token()) { |
| 470 Add("Security context: %o\n", token); | 476 Add("Security context: %o\n", token); |
| 471 current_security_token = token; | 477 isolate->set_string_stream_current_security_token(token); |
| 472 } | 478 } |
| 473 } else { | 479 } else { |
| 474 Add("(Function context is corrupt)\n"); | 480 Add("(Function context is corrupt)\n"); |
| 475 } | 481 } |
| 476 } | 482 } |
| 477 | 483 |
| 478 | 484 |
| 479 void StringStream::PrintFunction(Object* f, Object* receiver, Code** code) { | 485 void StringStream::PrintFunction(Object* f, Object* receiver, Code** code) { |
| 480 if (f->IsHeapObject() && | 486 if (f->IsHeapObject() && |
| 481 HEAP->Contains(HeapObject::cast(f)) && | 487 HEAP->Contains(HeapObject::cast(f)) && |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 | 581 |
| 576 // Only grow once to the maximum allowable size. | 582 // Only grow once to the maximum allowable size. |
| 577 char* NoAllocationStringAllocator::grow(unsigned* bytes) { | 583 char* NoAllocationStringAllocator::grow(unsigned* bytes) { |
| 578 ASSERT(size_ >= *bytes); | 584 ASSERT(size_ >= *bytes); |
| 579 *bytes = size_; | 585 *bytes = size_; |
| 580 return space_; | 586 return space_; |
| 581 } | 587 } |
| 582 | 588 |
| 583 | 589 |
| 584 } } // namespace v8::internal | 590 } } // namespace v8::internal |
| OLD | NEW |