OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 // We want to test our deprecated API entries, too. | |
29 #define V8_DISABLE_DEPRECATIONS 1 | |
30 | |
31 #include <limits.h> | 28 #include <limits.h> |
32 | 29 |
33 #ifndef WIN32 | 30 #ifndef WIN32 |
34 #include <signal.h> // kill | 31 #include <signal.h> // kill |
35 #include <unistd.h> // getpid | 32 #include <unistd.h> // getpid |
36 #endif // WIN32 | 33 #endif // WIN32 |
37 | 34 |
38 #include "v8.h" | 35 #include "v8.h" |
39 | 36 |
40 #include "api.h" | 37 #include "api.h" |
(...skipping 2011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2052 CHECK_EQ(aligned, obj->GetPointerFromInternalField(0)); | 2049 CHECK_EQ(aligned, obj->GetPointerFromInternalField(0)); |
2053 | 2050 |
2054 obj->SetInternalField(0, v8::External::Wrap(unaligned)); | 2051 obj->SetInternalField(0, v8::External::Wrap(unaligned)); |
2055 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 2052 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
2056 CHECK_EQ(unaligned, obj->GetPointerFromInternalField(0)); | 2053 CHECK_EQ(unaligned, obj->GetPointerFromInternalField(0)); |
2057 | 2054 |
2058 delete[] data; | 2055 delete[] data; |
2059 } | 2056 } |
2060 | 2057 |
2061 | 2058 |
2062 static void CheckAlignedPointerInInternalField(Handle<v8::Object> obj, | |
2063 void* value) { | |
2064 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1)); | |
2065 obj->SetPointerInInternalField(0, value); | |
2066 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | |
2067 CHECK_EQ(value, obj->GetPointerFromInternalField(0)); | |
2068 } | |
2069 | |
2070 | |
2071 THREADED_TEST(InternalFieldsAlignedPointers) { | |
2072 v8::HandleScope scope; | |
2073 LocalContext env; | |
2074 | |
2075 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); | |
2076 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); | |
2077 instance_templ->SetInternalFieldCount(1); | |
2078 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); | |
2079 CHECK_EQ(1, obj->InternalFieldCount()); | |
2080 | |
2081 CheckAlignedPointerInInternalField(obj, NULL); | |
2082 | |
2083 int* heap_allocated = new int[100]; | |
2084 CheckAlignedPointerInInternalField(obj, heap_allocated); | |
2085 delete[] heap_allocated; | |
2086 | |
2087 int stack_allocated[100]; | |
2088 CheckAlignedPointerInInternalField(obj, stack_allocated); | |
2089 | |
2090 void* huge = reinterpret_cast<void*>(~static_cast<uintptr_t>(1)); | |
2091 CheckAlignedPointerInInternalField(obj, huge); | |
2092 } | |
2093 | |
2094 | |
2095 static void CheckAlignedPointerInEmbedderData(LocalContext* env, | |
2096 int index, | |
2097 void* value) { | |
2098 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1)); | |
2099 (*env)->SetAlignedPointerInEmbedderData(index, value); | |
2100 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | |
2101 CHECK_EQ(value, (*env)->GetAlignedPointerFromEmbedderData(index)); | |
2102 } | |
2103 | |
2104 | |
2105 static void* AlignedTestPointer(int i) { | |
2106 return reinterpret_cast<void*>(i * 1234); | |
2107 } | |
2108 | |
2109 | |
2110 THREADED_TEST(EmbedderDataAlignedPointers) { | |
2111 v8::HandleScope scope; | |
2112 LocalContext env; | |
2113 | |
2114 CheckAlignedPointerInEmbedderData(&env, 0, NULL); | |
2115 | |
2116 int* heap_allocated = new int[100]; | |
2117 CheckAlignedPointerInEmbedderData(&env, 1, heap_allocated); | |
2118 delete[] heap_allocated; | |
2119 | |
2120 int stack_allocated[100]; | |
2121 CheckAlignedPointerInEmbedderData(&env, 2, stack_allocated); | |
2122 | |
2123 void* huge = reinterpret_cast<void*>(~static_cast<uintptr_t>(1)); | |
2124 CheckAlignedPointerInEmbedderData(&env, 3, huge); | |
2125 | |
2126 // Test growing of the embedder data's backing store. | |
2127 for (int i = 0; i < 100; i++) { | |
2128 env->SetAlignedPointerInEmbedderData(i, AlignedTestPointer(i)); | |
2129 } | |
2130 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | |
2131 for (int i = 0; i < 100; i++) { | |
2132 CHECK_EQ(AlignedTestPointer(i), env->GetAlignedPointerFromEmbedderData(i)); | |
2133 } | |
2134 } | |
2135 | |
2136 | |
2137 static void CheckEmbedderData(LocalContext* env, | |
2138 int index, | |
2139 v8::Handle<Value> data) { | |
2140 (*env)->SetEmbedderData(index, data); | |
2141 CHECK((*env)->GetEmbedderData(index)->StrictEquals(data)); | |
2142 } | |
2143 | |
2144 THREADED_TEST(EmbedderData) { | |
2145 v8::HandleScope scope; | |
2146 LocalContext env; | |
2147 | |
2148 CheckEmbedderData(&env, 3, v8::String::New("The quick brown fox jumps")); | |
2149 CheckEmbedderData(&env, 2, v8::String::New("over the lazy dog.")); | |
2150 CheckEmbedderData(&env, 1, v8::Number::New(1.2345)); | |
2151 CheckEmbedderData(&env, 0, v8::Boolean::New(true)); | |
2152 } | |
2153 | |
2154 | |
2155 THREADED_TEST(IdentityHash) { | 2059 THREADED_TEST(IdentityHash) { |
2156 v8::HandleScope scope; | 2060 v8::HandleScope scope; |
2157 LocalContext env; | 2061 LocalContext env; |
2158 | 2062 |
2159 // Ensure that the test starts with an fresh heap to test whether the hash | 2063 // Ensure that the test starts with an fresh heap to test whether the hash |
2160 // code is based on the address. | 2064 // code is based on the address. |
2161 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 2065 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
2162 Local<v8::Object> obj = v8::Object::New(); | 2066 Local<v8::Object> obj = v8::Object::New(); |
2163 int hash = obj->GetIdentityHash(); | 2067 int hash = obj->GetIdentityHash(); |
2164 int hash1 = obj->GetIdentityHash(); | 2068 int hash1 = obj->GetIdentityHash(); |
(...skipping 15818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17983 | 17887 |
17984 i::Semaphore* sem_; | 17888 i::Semaphore* sem_; |
17985 volatile int sem_value_; | 17889 volatile int sem_value_; |
17986 }; | 17890 }; |
17987 | 17891 |
17988 | 17892 |
17989 THREADED_TEST(SemaphoreInterruption) { | 17893 THREADED_TEST(SemaphoreInterruption) { |
17990 ThreadInterruptTest().RunTest(); | 17894 ThreadInterruptTest().RunTest(); |
17991 } | 17895 } |
17992 #endif // WIN32 | 17896 #endif // WIN32 |
OLD | NEW |