| OLD | NEW |
| 1 // Copyright 2007-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2010 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 i::Isolate* isolate = new TestIsolate(enable_serializer); | 58 i::Isolate* isolate = new TestIsolate(enable_serializer); |
| 59 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); | 59 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
| 60 v8::Isolate::Scope isolate_scope(v8_isolate); | 60 v8::Isolate::Scope isolate_scope(v8_isolate); |
| 61 isolate->Init(NULL); | 61 isolate->Init(NULL); |
| 62 return v8_isolate; | 62 return v8_isolate; |
| 63 } | 63 } |
| 64 explicit TestIsolate(bool enable_serializer) : Isolate(enable_serializer) {} | 64 explicit TestIsolate(bool enable_serializer) : Isolate(enable_serializer) {} |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 | 67 |
| 68 template <class T> | |
| 69 static Address AddressOf(T id) { | |
| 70 return ExternalReference(id, CcTest::i_isolate()).address(); | |
| 71 } | |
| 72 | |
| 73 | |
| 74 template <class T> | |
| 75 static uint32_t Encode(const ExternalReferenceEncoder& encoder, T id) { | |
| 76 return encoder.Encode(AddressOf(id)); | |
| 77 } | |
| 78 | |
| 79 | |
| 80 static uint32_t make_code(TypeCode type, int id) { | |
| 81 return static_cast<uint32_t>(type) << kReferenceTypeShift | id; | |
| 82 } | |
| 83 | |
| 84 | |
| 85 TEST(ExternalReferenceEncoder) { | |
| 86 Isolate* isolate = CcTest::i_isolate(); | |
| 87 v8::V8::Initialize(); | |
| 88 | |
| 89 ExternalReferenceEncoder encoder(isolate); | |
| 90 CHECK_EQ(make_code(BUILTIN, Builtins::kArrayCode), | |
| 91 Encode(encoder, Builtins::kArrayCode)); | |
| 92 CHECK_EQ(make_code(v8::internal::RUNTIME_FUNCTION, Runtime::kAbort), | |
| 93 Encode(encoder, Runtime::kAbort)); | |
| 94 ExternalReference stack_limit_address = | |
| 95 ExternalReference::address_of_stack_limit(isolate); | |
| 96 CHECK_EQ(make_code(UNCLASSIFIED, 2), | |
| 97 encoder.Encode(stack_limit_address.address())); | |
| 98 ExternalReference real_stack_limit_address = | |
| 99 ExternalReference::address_of_real_stack_limit(isolate); | |
| 100 CHECK_EQ(make_code(UNCLASSIFIED, 3), | |
| 101 encoder.Encode(real_stack_limit_address.address())); | |
| 102 CHECK_EQ(make_code(UNCLASSIFIED, 8), | |
| 103 encoder.Encode(ExternalReference::debug_break(isolate).address())); | |
| 104 CHECK_EQ( | |
| 105 make_code(UNCLASSIFIED, 4), | |
| 106 encoder.Encode(ExternalReference::new_space_start(isolate).address())); | |
| 107 CHECK_EQ( | |
| 108 make_code(UNCLASSIFIED, 1), | |
| 109 encoder.Encode(ExternalReference::roots_array_start(isolate).address())); | |
| 110 CHECK_EQ(make_code(UNCLASSIFIED, 33), | |
| 111 encoder.Encode(ExternalReference::cpu_features().address())); | |
| 112 } | |
| 113 | |
| 114 | |
| 115 TEST(ExternalReferenceDecoder) { | |
| 116 Isolate* isolate = CcTest::i_isolate(); | |
| 117 v8::V8::Initialize(); | |
| 118 | |
| 119 ExternalReferenceDecoder decoder(isolate); | |
| 120 CHECK_EQ(AddressOf(Builtins::kArrayCode), | |
| 121 decoder.Decode(make_code(BUILTIN, Builtins::kArrayCode))); | |
| 122 CHECK_EQ(AddressOf(Runtime::kAbort), | |
| 123 decoder.Decode(make_code(v8::internal::RUNTIME_FUNCTION, | |
| 124 Runtime::kAbort))); | |
| 125 CHECK_EQ(ExternalReference::address_of_stack_limit(isolate).address(), | |
| 126 decoder.Decode(make_code(UNCLASSIFIED, 2))); | |
| 127 CHECK_EQ(ExternalReference::address_of_real_stack_limit(isolate).address(), | |
| 128 decoder.Decode(make_code(UNCLASSIFIED, 3))); | |
| 129 CHECK_EQ(ExternalReference::debug_break(isolate).address(), | |
| 130 decoder.Decode(make_code(UNCLASSIFIED, 8))); | |
| 131 CHECK_EQ(ExternalReference::new_space_start(isolate).address(), | |
| 132 decoder.Decode(make_code(UNCLASSIFIED, 4))); | |
| 133 } | |
| 134 | |
| 135 | |
| 136 void WritePayload(const Vector<const byte>& payload, const char* file_name) { | 68 void WritePayload(const Vector<const byte>& payload, const char* file_name) { |
| 137 FILE* file = v8::base::OS::FOpen(file_name, "wb"); | 69 FILE* file = v8::base::OS::FOpen(file_name, "wb"); |
| 138 if (file == NULL) { | 70 if (file == NULL) { |
| 139 PrintF("Unable to write to snapshot file \"%s\"\n", file_name); | 71 PrintF("Unable to write to snapshot file \"%s\"\n", file_name); |
| 140 exit(1); | 72 exit(1); |
| 141 } | 73 } |
| 142 size_t written = fwrite(payload.begin(), 1, payload.length(), file); | 74 size_t written = fwrite(payload.begin(), 1, payload.length(), file); |
| 143 if (written != static_cast<size_t>(payload.length())) { | 75 if (written != static_cast<size_t>(payload.length())) { |
| 144 i::PrintF("Writing snapshot file failed.. Aborting.\n"); | 76 i::PrintF("Writing snapshot file failed.. Aborting.\n"); |
| 145 exit(1); | 77 exit(1); |
| (...skipping 1395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1541 v8::Local<v8::Context> context = v8::Context::New(isolate); | 1473 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 1542 delete[] data.data; // We can dispose of the snapshot blob now. | 1474 delete[] data.data; // We can dispose of the snapshot blob now. |
| 1543 v8::Context::Scope c_scope(context); | 1475 v8::Context::Scope c_scope(context); |
| 1544 v8::Handle<v8::Function> foo = | 1476 v8::Handle<v8::Function> foo = |
| 1545 v8::Handle<v8::Function>::Cast(CompileRun("foo")); | 1477 v8::Handle<v8::Function>::Cast(CompileRun("foo")); |
| 1546 CHECK(v8::Utils::OpenHandle(*foo)->code()->is_turbofanned()); | 1478 CHECK(v8::Utils::OpenHandle(*foo)->code()->is_turbofanned()); |
| 1547 CHECK_EQ(3, CompileRun("foo(4)")->ToInt32(isolate)->Int32Value()); | 1479 CHECK_EQ(3, CompileRun("foo(4)")->ToInt32(isolate)->Int32Value()); |
| 1548 } | 1480 } |
| 1549 isolate->Dispose(); | 1481 isolate->Dispose(); |
| 1550 } | 1482 } |
| OLD | NEW |