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 |
28 #include <limits.h> | 31 #include <limits.h> |
29 | 32 |
30 #ifndef WIN32 | 33 #ifndef WIN32 |
31 #include <signal.h> // kill | 34 #include <signal.h> // kill |
32 #include <unistd.h> // getpid | 35 #include <unistd.h> // getpid |
33 #endif // WIN32 | 36 #endif // WIN32 |
34 | 37 |
35 #include "v8.h" | 38 #include "v8.h" |
36 | 39 |
37 #include "api.h" | 40 #include "api.h" |
(...skipping 2011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2049 CHECK_EQ(aligned, obj->GetPointerFromInternalField(0)); | 2052 CHECK_EQ(aligned, obj->GetPointerFromInternalField(0)); |
2050 | 2053 |
2051 obj->SetInternalField(0, v8::External::Wrap(unaligned)); | 2054 obj->SetInternalField(0, v8::External::Wrap(unaligned)); |
2052 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 2055 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
2053 CHECK_EQ(unaligned, obj->GetPointerFromInternalField(0)); | 2056 CHECK_EQ(unaligned, obj->GetPointerFromInternalField(0)); |
2054 | 2057 |
2055 delete[] data; | 2058 delete[] data; |
2056 } | 2059 } |
2057 | 2060 |
2058 | 2061 |
| 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 |
2059 THREADED_TEST(IdentityHash) { | 2155 THREADED_TEST(IdentityHash) { |
2060 v8::HandleScope scope; | 2156 v8::HandleScope scope; |
2061 LocalContext env; | 2157 LocalContext env; |
2062 | 2158 |
2063 // Ensure that the test starts with an fresh heap to test whether the hash | 2159 // Ensure that the test starts with an fresh heap to test whether the hash |
2064 // code is based on the address. | 2160 // code is based on the address. |
2065 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 2161 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
2066 Local<v8::Object> obj = v8::Object::New(); | 2162 Local<v8::Object> obj = v8::Object::New(); |
2067 int hash = obj->GetIdentityHash(); | 2163 int hash = obj->GetIdentityHash(); |
2068 int hash1 = obj->GetIdentityHash(); | 2164 int hash1 = obj->GetIdentityHash(); |
(...skipping 15830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17899 | 17995 |
17900 i::Semaphore* sem_; | 17996 i::Semaphore* sem_; |
17901 volatile int sem_value_; | 17997 volatile int sem_value_; |
17902 }; | 17998 }; |
17903 | 17999 |
17904 | 18000 |
17905 THREADED_TEST(SemaphoreInterruption) { | 18001 THREADED_TEST(SemaphoreInterruption) { |
17906 ThreadInterruptTest().RunTest(); | 18002 ThreadInterruptTest().RunTest(); |
17907 } | 18003 } |
17908 #endif // WIN32 | 18004 #endif // WIN32 |
OLD | NEW |