2015-06-04 14:44:00 +00:00
|
|
|
// Copyright 2015 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
// Test embedded constant pool builder code.
|
2013-10-14 13:35:06 +00:00
|
|
|
|
2019-05-24 13:51:59 +00:00
|
|
|
#include "src/init/v8.h"
|
2013-10-14 13:35:06 +00:00
|
|
|
|
2019-05-21 09:30:15 +00:00
|
|
|
#include "src/codegen/constant-pool.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
2013-10-14 13:35:06 +00:00
|
|
|
|
2017-08-11 11:22:28 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2013-10-14 13:35:06 +00:00
|
|
|
|
2020-02-21 14:37:03 +00:00
|
|
|
#if defined(V8_TARGET_ARCH_PPC) || defined(V8_TARGET_ARCH_PPC64)
|
2018-10-19 10:17:59 +00:00
|
|
|
|
2015-06-04 14:44:00 +00:00
|
|
|
const ConstantPoolEntry::Type kPtrType = ConstantPoolEntry::INTPTR;
|
|
|
|
const ConstantPoolEntry::Type kDblType = ConstantPoolEntry::DOUBLE;
|
|
|
|
const ConstantPoolEntry::Access kRegAccess = ConstantPoolEntry::REGULAR;
|
|
|
|
const ConstantPoolEntry::Access kOvflAccess = ConstantPoolEntry::OVERFLOWED;
|
2014-03-10 19:05:43 +00:00
|
|
|
|
2015-06-04 14:44:00 +00:00
|
|
|
const int kReachBits = 6; // Use reach of 64-bytes to test overflow.
|
|
|
|
const int kReach = 1 << kReachBits;
|
2014-03-10 19:05:43 +00:00
|
|
|
|
2013-10-14 13:35:06 +00:00
|
|
|
|
2015-06-04 14:44:00 +00:00
|
|
|
TEST(ConstantPoolPointers) {
|
|
|
|
ConstantPoolBuilder builder(kReachBits, kReachBits);
|
2020-05-05 15:20:41 +00:00
|
|
|
const int kRegularCount = kReach / kSystemPointerSize;
|
2015-06-04 14:44:00 +00:00
|
|
|
ConstantPoolEntry::Access access;
|
|
|
|
int pos = 0;
|
|
|
|
intptr_t value = 0;
|
|
|
|
bool sharing_ok = true;
|
2014-06-03 16:22:10 +00:00
|
|
|
|
2015-06-04 14:44:00 +00:00
|
|
|
CHECK(builder.IsEmpty());
|
|
|
|
while (builder.NextAccess(kPtrType) == kRegAccess) {
|
|
|
|
access = builder.AddEntry(pos++, value++, sharing_ok);
|
|
|
|
CHECK_EQ(access, kRegAccess);
|
2014-06-03 16:22:10 +00:00
|
|
|
}
|
2015-06-04 14:44:00 +00:00
|
|
|
CHECK(!builder.IsEmpty());
|
|
|
|
CHECK_EQ(pos, kRegularCount);
|
|
|
|
|
|
|
|
access = builder.AddEntry(pos, value, sharing_ok);
|
|
|
|
CHECK_EQ(access, kOvflAccess);
|
2013-10-14 13:35:06 +00:00
|
|
|
}
|
2014-06-03 16:22:10 +00:00
|
|
|
|
|
|
|
|
2015-06-04 14:44:00 +00:00
|
|
|
TEST(ConstantPoolDoubles) {
|
|
|
|
ConstantPoolBuilder builder(kReachBits, kReachBits);
|
|
|
|
const int kRegularCount = kReach / kDoubleSize;
|
|
|
|
ConstantPoolEntry::Access access;
|
|
|
|
int pos = 0;
|
|
|
|
double value = 0.0;
|
2014-06-03 16:22:10 +00:00
|
|
|
|
2015-06-04 14:44:00 +00:00
|
|
|
CHECK(builder.IsEmpty());
|
|
|
|
while (builder.NextAccess(kDblType) == kRegAccess) {
|
|
|
|
access = builder.AddEntry(pos++, value);
|
|
|
|
value += 0.5;
|
|
|
|
CHECK_EQ(access, kRegAccess);
|
2015-06-03 03:02:26 +00:00
|
|
|
}
|
2015-06-04 14:44:00 +00:00
|
|
|
CHECK(!builder.IsEmpty());
|
|
|
|
CHECK_EQ(pos, kRegularCount);
|
2015-06-02 22:50:00 +00:00
|
|
|
|
2015-06-04 14:44:00 +00:00
|
|
|
access = builder.AddEntry(pos, value);
|
|
|
|
CHECK_EQ(access, kOvflAccess);
|
|
|
|
}
|
2015-06-02 22:50:00 +00:00
|
|
|
|
2015-06-04 14:44:00 +00:00
|
|
|
|
|
|
|
TEST(ConstantPoolMixedTypes) {
|
|
|
|
ConstantPoolBuilder builder(kReachBits, kReachBits);
|
2020-05-05 15:20:41 +00:00
|
|
|
const int kRegularCount =
|
|
|
|
(((kReach / (kDoubleSize + kSystemPointerSize)) * 2) +
|
|
|
|
((kSystemPointerSize < kDoubleSize) ? 1 : 0));
|
2015-06-04 14:44:00 +00:00
|
|
|
ConstantPoolEntry::Type type = kPtrType;
|
|
|
|
ConstantPoolEntry::Access access;
|
|
|
|
int pos = 0;
|
|
|
|
intptr_t ptrValue = 0;
|
|
|
|
double dblValue = 0.0;
|
|
|
|
bool sharing_ok = true;
|
|
|
|
|
|
|
|
CHECK(builder.IsEmpty());
|
|
|
|
while (builder.NextAccess(type) == kRegAccess) {
|
|
|
|
if (type == kPtrType) {
|
|
|
|
access = builder.AddEntry(pos++, ptrValue++, sharing_ok);
|
|
|
|
type = kDblType;
|
2015-06-03 03:02:26 +00:00
|
|
|
} else {
|
2015-06-04 14:44:00 +00:00
|
|
|
access = builder.AddEntry(pos++, dblValue);
|
|
|
|
dblValue += 0.5;
|
|
|
|
type = kPtrType;
|
2015-06-03 03:02:26 +00:00
|
|
|
}
|
2015-06-04 14:44:00 +00:00
|
|
|
CHECK_EQ(access, kRegAccess);
|
2015-06-03 03:02:26 +00:00
|
|
|
}
|
2015-06-04 14:44:00 +00:00
|
|
|
CHECK(!builder.IsEmpty());
|
|
|
|
CHECK_EQ(pos, kRegularCount);
|
|
|
|
|
|
|
|
access = builder.AddEntry(pos++, ptrValue, sharing_ok);
|
|
|
|
CHECK_EQ(access, kOvflAccess);
|
|
|
|
access = builder.AddEntry(pos, dblValue);
|
|
|
|
CHECK_EQ(access, kOvflAccess);
|
2014-06-03 16:22:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-04 14:44:00 +00:00
|
|
|
TEST(ConstantPoolMixedReach) {
|
|
|
|
const int ptrReachBits = kReachBits + 2;
|
|
|
|
const int ptrReach = 1 << ptrReachBits;
|
|
|
|
const int dblReachBits = kReachBits;
|
|
|
|
const int dblReach = kReach;
|
2020-11-24 18:13:56 +00:00
|
|
|
const int dblRegularCount = std::min(
|
2020-05-05 15:20:41 +00:00
|
|
|
dblReach / kDoubleSize, ptrReach / (kDoubleSize + kSystemPointerSize));
|
2015-06-04 14:44:00 +00:00
|
|
|
const int ptrRegularCount =
|
2020-05-05 15:20:41 +00:00
|
|
|
((ptrReach - (dblRegularCount * (kDoubleSize + kSystemPointerSize))) /
|
|
|
|
kSystemPointerSize) +
|
2015-06-04 14:44:00 +00:00
|
|
|
dblRegularCount;
|
|
|
|
ConstantPoolBuilder builder(ptrReachBits, dblReachBits);
|
|
|
|
ConstantPoolEntry::Access access;
|
|
|
|
int pos = 0;
|
|
|
|
intptr_t ptrValue = 0;
|
|
|
|
double dblValue = 0.0;
|
|
|
|
bool sharing_ok = true;
|
|
|
|
int ptrCount = 0;
|
|
|
|
int dblCount = 0;
|
|
|
|
|
|
|
|
CHECK(builder.IsEmpty());
|
|
|
|
while (builder.NextAccess(kDblType) == kRegAccess) {
|
|
|
|
access = builder.AddEntry(pos++, dblValue);
|
|
|
|
dblValue += 0.5;
|
|
|
|
dblCount++;
|
|
|
|
CHECK_EQ(access, kRegAccess);
|
|
|
|
|
|
|
|
access = builder.AddEntry(pos++, ptrValue++, sharing_ok);
|
|
|
|
ptrCount++;
|
|
|
|
CHECK_EQ(access, kRegAccess);
|
2014-06-03 16:22:10 +00:00
|
|
|
}
|
2015-06-04 14:44:00 +00:00
|
|
|
CHECK(!builder.IsEmpty());
|
|
|
|
CHECK_EQ(dblCount, dblRegularCount);
|
2014-06-03 16:22:10 +00:00
|
|
|
|
2015-06-04 14:44:00 +00:00
|
|
|
while (ptrCount < ptrRegularCount) {
|
|
|
|
access = builder.AddEntry(pos++, dblValue);
|
|
|
|
dblValue += 0.5;
|
|
|
|
CHECK_EQ(access, kOvflAccess);
|
2014-06-03 16:22:10 +00:00
|
|
|
|
2015-06-04 14:44:00 +00:00
|
|
|
access = builder.AddEntry(pos++, ptrValue++, sharing_ok);
|
|
|
|
ptrCount++;
|
|
|
|
CHECK_EQ(access, kRegAccess);
|
|
|
|
}
|
|
|
|
CHECK_EQ(builder.NextAccess(kPtrType), kOvflAccess);
|
2014-06-03 16:22:10 +00:00
|
|
|
|
2015-06-04 14:44:00 +00:00
|
|
|
access = builder.AddEntry(pos++, ptrValue, sharing_ok);
|
|
|
|
CHECK_EQ(access, kOvflAccess);
|
|
|
|
access = builder.AddEntry(pos, dblValue);
|
|
|
|
CHECK_EQ(access, kOvflAccess);
|
2014-06-03 16:22:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-04 14:44:00 +00:00
|
|
|
TEST(ConstantPoolSharing) {
|
|
|
|
ConstantPoolBuilder builder(kReachBits, kReachBits);
|
2020-05-05 15:20:41 +00:00
|
|
|
const int kRegularCount =
|
|
|
|
(((kReach / (kDoubleSize + kSystemPointerSize)) * 2) +
|
|
|
|
((kSystemPointerSize < kDoubleSize) ? 1 : 0));
|
2015-06-04 14:44:00 +00:00
|
|
|
ConstantPoolEntry::Access access;
|
2014-07-28 10:04:36 +00:00
|
|
|
|
2015-06-04 14:44:00 +00:00
|
|
|
CHECK(builder.IsEmpty());
|
2014-07-28 10:04:36 +00:00
|
|
|
|
2015-06-04 14:44:00 +00:00
|
|
|
ConstantPoolEntry::Type type = kPtrType;
|
|
|
|
int pos = 0;
|
|
|
|
intptr_t ptrValue = 0;
|
|
|
|
double dblValue = 0.0;
|
|
|
|
bool sharing_ok = true;
|
|
|
|
while (builder.NextAccess(type) == kRegAccess) {
|
|
|
|
if (type == kPtrType) {
|
|
|
|
access = builder.AddEntry(pos++, ptrValue++, sharing_ok);
|
|
|
|
type = kDblType;
|
|
|
|
} else {
|
|
|
|
access = builder.AddEntry(pos++, dblValue);
|
|
|
|
dblValue += 0.5;
|
|
|
|
type = kPtrType;
|
|
|
|
}
|
|
|
|
CHECK_EQ(access, kRegAccess);
|
|
|
|
}
|
|
|
|
CHECK(!builder.IsEmpty());
|
|
|
|
CHECK_EQ(pos, kRegularCount);
|
|
|
|
|
|
|
|
type = kPtrType;
|
|
|
|
ptrValue = 0;
|
|
|
|
dblValue = 0.0;
|
|
|
|
while (pos < kRegularCount * 2) {
|
|
|
|
if (type == kPtrType) {
|
|
|
|
access = builder.AddEntry(pos++, ptrValue++, sharing_ok);
|
|
|
|
type = kDblType;
|
|
|
|
} else {
|
|
|
|
access = builder.AddEntry(pos++, dblValue);
|
|
|
|
dblValue += 0.5;
|
|
|
|
type = kPtrType;
|
|
|
|
}
|
|
|
|
CHECK_EQ(access, kRegAccess);
|
|
|
|
}
|
|
|
|
|
|
|
|
access = builder.AddEntry(pos++, ptrValue, sharing_ok);
|
|
|
|
CHECK_EQ(access, kOvflAccess);
|
|
|
|
access = builder.AddEntry(pos, dblValue);
|
|
|
|
CHECK_EQ(access, kOvflAccess);
|
2014-07-28 10:04:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-04 14:44:00 +00:00
|
|
|
TEST(ConstantPoolNoSharing) {
|
|
|
|
ConstantPoolBuilder builder(kReachBits, kReachBits);
|
2020-05-05 15:20:41 +00:00
|
|
|
const int kRegularCount =
|
|
|
|
(((kReach / (kDoubleSize + kSystemPointerSize)) * 2) +
|
|
|
|
((kSystemPointerSize < kDoubleSize) ? 1 : 0));
|
2015-06-04 14:44:00 +00:00
|
|
|
ConstantPoolEntry::Access access;
|
2014-07-28 10:04:36 +00:00
|
|
|
|
2015-06-04 14:44:00 +00:00
|
|
|
CHECK(builder.IsEmpty());
|
2014-07-28 10:04:36 +00:00
|
|
|
|
2015-06-04 14:44:00 +00:00
|
|
|
ConstantPoolEntry::Type type = kPtrType;
|
|
|
|
int pos = 0;
|
|
|
|
intptr_t ptrValue = 0;
|
|
|
|
double dblValue = 0.0;
|
|
|
|
bool sharing_ok = false;
|
|
|
|
while (builder.NextAccess(type) == kRegAccess) {
|
|
|
|
if (type == kPtrType) {
|
|
|
|
access = builder.AddEntry(pos++, ptrValue++, sharing_ok);
|
|
|
|
type = kDblType;
|
|
|
|
} else {
|
|
|
|
access = builder.AddEntry(pos++, dblValue);
|
|
|
|
dblValue += 0.5;
|
|
|
|
type = kPtrType;
|
|
|
|
}
|
|
|
|
CHECK_EQ(access, kRegAccess);
|
|
|
|
}
|
|
|
|
CHECK(!builder.IsEmpty());
|
|
|
|
CHECK_EQ(pos, kRegularCount);
|
|
|
|
|
|
|
|
type = kPtrType;
|
|
|
|
ptrValue = 0;
|
|
|
|
dblValue = 0.0;
|
|
|
|
sharing_ok = true;
|
|
|
|
while (pos < kRegularCount * 2) {
|
|
|
|
if (type == kPtrType) {
|
|
|
|
access = builder.AddEntry(pos++, ptrValue++, sharing_ok);
|
|
|
|
type = kDblType;
|
|
|
|
CHECK_EQ(access, kOvflAccess);
|
|
|
|
} else {
|
|
|
|
access = builder.AddEntry(pos++, dblValue);
|
|
|
|
dblValue += 0.5;
|
|
|
|
type = kPtrType;
|
|
|
|
CHECK_EQ(access, kRegAccess);
|
|
|
|
}
|
|
|
|
}
|
2014-07-28 10:04:36 +00:00
|
|
|
|
2015-06-04 14:44:00 +00:00
|
|
|
access = builder.AddEntry(pos++, ptrValue, sharing_ok);
|
|
|
|
CHECK_EQ(access, kOvflAccess);
|
|
|
|
access = builder.AddEntry(pos, dblValue);
|
|
|
|
CHECK_EQ(access, kOvflAccess);
|
2014-07-28 10:04:36 +00:00
|
|
|
}
|
2017-08-11 11:22:28 +00:00
|
|
|
|
2020-02-21 14:37:03 +00:00
|
|
|
#endif // defined(V8_TARGET_ARCH_PPC) || defined(V8_TARGET_ARCH_PPC64)
|
2018-10-19 10:17:59 +00:00
|
|
|
|
2017-08-11 11:22:28 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|