| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 #include <vector> | 28 #include <vector> |
| 29 | 29 |
| 30 #define private public /* To test private methods :) */ | 30 #include "cctest.h" |
| 31 #define protected public | |
| 32 #include "types.h" | 31 #include "types.h" |
| 33 #undef private | |
| 34 #undef protected | |
| 35 | |
| 36 #include "cctest.h" | |
| 37 #include "utils/random-number-generator.h" | 32 #include "utils/random-number-generator.h" |
| 38 | 33 |
| 39 using namespace v8::internal; | 34 using namespace v8::internal; |
| 40 | 35 |
| 41 // Testing auxiliaries (breaking the Type abstraction). | 36 // Testing auxiliaries (breaking the Type abstraction). |
| 42 struct ZoneRep { | 37 struct ZoneRep { |
| 43 typedef void* Struct; | 38 typedef void* Struct; |
| 44 | 39 |
| 45 static bool IsStruct(Type* t, int tag) { | 40 static bool IsStruct(Type* t, int tag) { |
| 46 return !IsBitset(t) && reinterpret_cast<intptr_t>(AsStruct(t)[0]) == tag; | 41 return !IsBitset(t) && reinterpret_cast<intptr_t>(AsStruct(t)[0]) == tag; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 69 return *static_cast<Type**>(AsStruct(t)[2]); | 64 return *static_cast<Type**>(AsStruct(t)[2]); |
| 70 } | 65 } |
| 71 static Struct* AsUnion(Type* t) { | 66 static Struct* AsUnion(Type* t) { |
| 72 return AsStruct(t); | 67 return AsStruct(t); |
| 73 } | 68 } |
| 74 static int Length(Struct* structured) { | 69 static int Length(Struct* structured) { |
| 75 return static_cast<int>(reinterpret_cast<intptr_t>(structured[1])); | 70 return static_cast<int>(reinterpret_cast<intptr_t>(structured[1])); |
| 76 } | 71 } |
| 77 | 72 |
| 78 static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; } | 73 static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; } |
| 74 |
| 75 struct BitsetType : Type::BitsetType { |
| 76 using Type::BitsetType::New; |
| 77 using Type::BitsetType::Glb; |
| 78 using Type::BitsetType::Lub; |
| 79 using Type::BitsetType::InherentLub; |
| 80 }; |
| 79 }; | 81 }; |
| 80 | 82 |
| 81 | 83 |
| 82 struct HeapRep { | 84 struct HeapRep { |
| 83 typedef FixedArray Struct; | 85 typedef FixedArray Struct; |
| 84 | 86 |
| 85 static bool IsStruct(Handle<HeapType> t, int tag) { | 87 static bool IsStruct(Handle<HeapType> t, int tag) { |
| 86 return t->IsFixedArray() && Smi::cast(AsStruct(t)->get(0))->value() == tag; | 88 return t->IsFixedArray() && Smi::cast(AsStruct(t)->get(0))->value() == tag; |
| 87 } | 89 } |
| 88 static bool IsBitset(Handle<HeapType> t) { return t->IsSmi(); } | 90 static bool IsBitset(Handle<HeapType> t) { return t->IsSmi(); } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 101 return t->IsMap() ? Map::cast(*t) : Map::cast(AsStruct(t)->get(2)); | 103 return t->IsMap() ? Map::cast(*t) : Map::cast(AsStruct(t)->get(2)); |
| 102 } | 104 } |
| 103 static Object* AsConstant(Handle<HeapType> t) { return AsStruct(t)->get(2); } | 105 static Object* AsConstant(Handle<HeapType> t) { return AsStruct(t)->get(2); } |
| 104 static HeapType* AsContext(Handle<HeapType> t) { | 106 static HeapType* AsContext(Handle<HeapType> t) { |
| 105 return HeapType::cast(AsStruct(t)->get(1)); | 107 return HeapType::cast(AsStruct(t)->get(1)); |
| 106 } | 108 } |
| 107 static Struct* AsUnion(Handle<HeapType> t) { return AsStruct(t); } | 109 static Struct* AsUnion(Handle<HeapType> t) { return AsStruct(t); } |
| 108 static int Length(Struct* structured) { return structured->length() - 1; } | 110 static int Length(Struct* structured) { return structured->length() - 1; } |
| 109 | 111 |
| 110 static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; } | 112 static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; } |
| 113 |
| 114 struct BitsetType : HeapType::BitsetType { |
| 115 using HeapType::BitsetType::New; |
| 116 using HeapType::BitsetType::Glb; |
| 117 using HeapType::BitsetType::Lub; |
| 118 using HeapType::BitsetType::InherentLub; |
| 119 static int Glb(Handle<HeapType> type) { return Glb(*type); } |
| 120 static int Lub(Handle<HeapType> type) { return Lub(*type); } |
| 121 static int InherentLub(Handle<HeapType> type) { return InherentLub(*type); } |
| 122 }; |
| 111 }; | 123 }; |
| 112 | 124 |
| 113 | 125 |
| 114 template<class Type, class TypeHandle, class Region> | 126 template<class Type, class TypeHandle, class Region> |
| 115 class Types { | 127 class Types { |
| 116 public: | 128 public: |
| 117 Types(Region* region, Isolate* isolate) : region_(region) { | 129 Types(Region* region, Isolate* isolate) : region_(region) { |
| 118 #define DECLARE_TYPE(name, value) \ | 130 #define DECLARE_TYPE(name, value) \ |
| 119 name = Type::name(region); \ | 131 name = Type::name(region); \ |
| 120 types.push_back(name); | 132 types.push_back(name); |
| (...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 CHECK(!const_type->Is(type) || | 744 CHECK(!const_type->Is(type) || |
| 733 (nowof_type->Is(type) || type->Maybe(const_type))); | 745 (nowof_type->Is(type) || type->Maybe(const_type))); |
| 734 } | 746 } |
| 735 } | 747 } |
| 736 } | 748 } |
| 737 | 749 |
| 738 void Bounds() { | 750 void Bounds() { |
| 739 // Ordering: (T->BitsetGlb())->Is(T->BitsetLub()) | 751 // Ordering: (T->BitsetGlb())->Is(T->BitsetLub()) |
| 740 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 752 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
| 741 TypeHandle type = *it; | 753 TypeHandle type = *it; |
| 742 TypeHandle glb = Type::BitsetType::New(type->BitsetGlb(), T.region()); | 754 TypeHandle glb = |
| 743 TypeHandle lub = Type::BitsetType::New(type->BitsetLub(), T.region()); | 755 Rep::BitsetType::New(Rep::BitsetType::Glb(type), T.region()); |
| 756 TypeHandle lub = |
| 757 Rep::BitsetType::New(Rep::BitsetType::Lub(type), T.region()); |
| 744 CHECK(glb->Is(lub)); | 758 CHECK(glb->Is(lub)); |
| 745 } | 759 } |
| 746 | 760 |
| 747 // Lower bound: (T->BitsetGlb())->Is(T) | 761 // Lower bound: (T->BitsetGlb())->Is(T) |
| 748 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 762 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
| 749 TypeHandle type = *it; | 763 TypeHandle type = *it; |
| 750 TypeHandle glb = Type::BitsetType::New(type->BitsetGlb(), T.region()); | 764 TypeHandle glb = |
| 765 Rep::BitsetType::New(Rep::BitsetType::Glb(type), T.region()); |
| 751 CHECK(glb->Is(type)); | 766 CHECK(glb->Is(type)); |
| 752 } | 767 } |
| 753 | 768 |
| 754 // Upper bound: T->Is(T->BitsetLub()) | 769 // Upper bound: T->Is(T->BitsetLub()) |
| 755 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 770 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
| 756 TypeHandle type = *it; | 771 TypeHandle type = *it; |
| 757 TypeHandle lub = Type::BitsetType::New(type->BitsetLub(), T.region()); | 772 TypeHandle lub = |
| 773 Rep::BitsetType::New(Rep::BitsetType::Lub(type), T.region()); |
| 758 CHECK(type->Is(lub)); | 774 CHECK(type->Is(lub)); |
| 759 } | 775 } |
| 760 | 776 |
| 761 // Inherent bound: (T->BitsetLub())->Is(T->InherentBitsetLub()) | 777 // Inherent bound: (T->BitsetLub())->Is(T->InherentBitsetLub()) |
| 762 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 778 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
| 763 TypeHandle type = *it; | 779 TypeHandle type = *it; |
| 764 TypeHandle lub = Type::BitsetType::New(type->BitsetLub(), T.region()); | 780 TypeHandle lub = |
| 781 Rep::BitsetType::New(Rep::BitsetType::Lub(type), T.region()); |
| 765 TypeHandle inherent = | 782 TypeHandle inherent = |
| 766 Type::BitsetType::New(type->InherentBitsetLub(), T.region()); | 783 Rep::BitsetType::New(Rep::BitsetType::InherentLub(type), T.region()); |
| 767 CHECK(lub->Is(inherent)); | 784 CHECK(lub->Is(inherent)); |
| 768 } | 785 } |
| 769 } | 786 } |
| 770 | 787 |
| 771 void Is() { | 788 void Is() { |
| 772 // Least Element (Bottom): None->Is(T) | 789 // Least Element (Bottom): None->Is(T) |
| 773 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 790 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
| 774 TypeHandle type = *it; | 791 TypeHandle type = *it; |
| 775 CHECK(T.None->Is(type)); | 792 CHECK(T.None->Is(type)); |
| 776 } | 793 } |
| (...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1887 ZoneTests().Distributivity(); | 1904 ZoneTests().Distributivity(); |
| 1888 HeapTests().Distributivity(); | 1905 HeapTests().Distributivity(); |
| 1889 } | 1906 } |
| 1890 | 1907 |
| 1891 | 1908 |
| 1892 TEST(Convert) { | 1909 TEST(Convert) { |
| 1893 CcTest::InitializeVM(); | 1910 CcTest::InitializeVM(); |
| 1894 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); | 1911 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); |
| 1895 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); | 1912 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); |
| 1896 } | 1913 } |
| OLD | NEW |