Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1073)

Unified Diff: test/cctest/test-api.cc

Issue 155723005: A64: Synchronize with r19001. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/cctest.status ('k') | test/cctest/test-debug.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index c0ba7fd397902bb3c97edc700ddd51964e349761..38c8ac78bc52eb577b675d1877b6c46445d81327 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -462,13 +462,13 @@ static uint16_t* AsciiToTwoByteString(const char* source) {
class TestResource: public String::ExternalStringResource {
public:
- explicit TestResource(uint16_t* data, int* counter = NULL)
- : data_(data), length_(0), counter_(counter) {
+ TestResource(uint16_t* data, int* counter = NULL, bool owning_data = true)
+ : data_(data), length_(0), counter_(counter), owning_data_(owning_data) {
while (data[length_]) ++length_;
}
~TestResource() {
- i::DeleteArray(data_);
+ if (owning_data_) i::DeleteArray(data_);
if (counter_ != NULL) ++*counter_;
}
@@ -479,20 +479,25 @@ class TestResource: public String::ExternalStringResource {
size_t length() const {
return length_;
}
+
private:
uint16_t* data_;
size_t length_;
int* counter_;
+ bool owning_data_;
};
class TestAsciiResource: public String::ExternalAsciiStringResource {
public:
- explicit TestAsciiResource(const char* data, int* counter = NULL)
- : data_(data), length_(strlen(data)), counter_(counter) { }
+ TestAsciiResource(const char* data, int* counter = NULL, size_t offset = 0)
+ : orig_data_(data),
+ data_(data + offset),
+ length_(strlen(data) - offset),
+ counter_(counter) { }
~TestAsciiResource() {
- i::DeleteArray(data_);
+ i::DeleteArray(orig_data_);
if (counter_ != NULL) ++*counter_;
}
@@ -503,7 +508,9 @@ class TestAsciiResource: public String::ExternalAsciiStringResource {
size_t length() const {
return length_;
}
+
private:
+ const char* orig_data_;
const char* data_;
size_t length_;
int* counter_;
@@ -733,11 +740,11 @@ TEST(MakingExternalUnalignedAsciiString) {
int dispose_count = 0;
const char* c_cons = "_abcdefghijklmnopqrstuvwxyz";
bool success = cons->MakeExternal(
- new TestAsciiResource(i::StrDup(c_cons) + 1, &dispose_count));
+ new TestAsciiResource(i::StrDup(c_cons), &dispose_count, 1));
CHECK(success);
const char* c_slice = "_bcdefghijklmnopqrstuvwxyz";
success = slice->MakeExternal(
- new TestAsciiResource(i::StrDup(c_slice) + 1, &dispose_count));
+ new TestAsciiResource(i::StrDup(c_slice), &dispose_count, 1));
CHECK(success);
// Trigger GCs and force evacuation.
@@ -6613,7 +6620,7 @@ static const char* kSimpleExtensionSource =
"}";
-THREADED_TEST(SimpleExtensions) {
+TEST(SimpleExtensions) {
v8::HandleScope handle_scope(CcTest::isolate());
v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource));
const char* extension_names[] = { "simpletest" };
@@ -6626,7 +6633,7 @@ THREADED_TEST(SimpleExtensions) {
}
-THREADED_TEST(NullExtensions) {
+TEST(NullExtensions) {
v8::HandleScope handle_scope(CcTest::isolate());
v8::RegisterExtension(new Extension("nulltest", NULL));
const char* extension_names[] = { "nulltest" };
@@ -6645,7 +6652,7 @@ static const char* kEmbeddedExtensionSource =
static const int kEmbeddedExtensionSourceValidLen = 34;
-THREADED_TEST(ExtensionMissingSourceLength) {
+TEST(ExtensionMissingSourceLength) {
v8::HandleScope handle_scope(CcTest::isolate());
v8::RegisterExtension(new Extension("srclentest_fail",
kEmbeddedExtensionSource));
@@ -6657,7 +6664,7 @@ THREADED_TEST(ExtensionMissingSourceLength) {
}
-THREADED_TEST(ExtensionWithSourceLength) {
+TEST(ExtensionWithSourceLength) {
for (int source_len = kEmbeddedExtensionSourceValidLen - 1;
source_len <= kEmbeddedExtensionSourceValidLen + 1; ++source_len) {
v8::HandleScope handle_scope(CcTest::isolate());
@@ -6699,7 +6706,7 @@ static const char* kEvalExtensionSource2 =
"})()";
-THREADED_TEST(UseEvalFromExtension) {
+TEST(UseEvalFromExtension) {
v8::HandleScope handle_scope(CcTest::isolate());
v8::RegisterExtension(new Extension("evaltest1", kEvalExtensionSource1));
v8::RegisterExtension(new Extension("evaltest2", kEvalExtensionSource2));
@@ -6733,7 +6740,7 @@ static const char* kWithExtensionSource2 =
"})()";
-THREADED_TEST(UseWithFromExtension) {
+TEST(UseWithFromExtension) {
v8::HandleScope handle_scope(CcTest::isolate());
v8::RegisterExtension(new Extension("withtest1", kWithExtensionSource1));
v8::RegisterExtension(new Extension("withtest2", kWithExtensionSource2));
@@ -6749,7 +6756,7 @@ THREADED_TEST(UseWithFromExtension) {
}
-THREADED_TEST(AutoExtensions) {
+TEST(AutoExtensions) {
v8::HandleScope handle_scope(CcTest::isolate());
Extension* extension = new Extension("autotest", kSimpleExtensionSource);
extension->set_auto_enable(true);
@@ -6768,7 +6775,7 @@ static const char* kSyntaxErrorInExtensionSource =
// Test that a syntax error in an extension does not cause a fatal
// error but results in an empty context.
-THREADED_TEST(SyntaxErrorExtensions) {
+TEST(SyntaxErrorExtensions) {
v8::HandleScope handle_scope(CcTest::isolate());
v8::RegisterExtension(new Extension("syntaxerror",
kSyntaxErrorInExtensionSource));
@@ -6786,7 +6793,7 @@ static const char* kExceptionInExtensionSource =
// Test that an exception when installing an extension does not cause
// a fatal error but results in an empty context.
-THREADED_TEST(ExceptionExtensions) {
+TEST(ExceptionExtensions) {
v8::HandleScope handle_scope(CcTest::isolate());
v8::RegisterExtension(new Extension("exception",
kExceptionInExtensionSource));
@@ -6808,7 +6815,7 @@ static const char* kNativeCallTest =
"call_runtime_last_index_of('bobbobboellebobboellebobbob');";
// Test that a native runtime calls are supported in extensions.
-THREADED_TEST(NativeCallInExtensions) {
+TEST(NativeCallInExtensions) {
v8::HandleScope handle_scope(CcTest::isolate());
v8::RegisterExtension(new Extension("nativecall",
kNativeCallInExtensionSource));
@@ -6844,7 +6851,7 @@ class NativeFunctionExtension : public Extension {
};
-THREADED_TEST(NativeFunctionDeclaration) {
+TEST(NativeFunctionDeclaration) {
v8::HandleScope handle_scope(CcTest::isolate());
const char* name = "nativedecl";
v8::RegisterExtension(new NativeFunctionExtension(name,
@@ -6859,7 +6866,7 @@ THREADED_TEST(NativeFunctionDeclaration) {
}
-THREADED_TEST(NativeFunctionDeclarationError) {
+TEST(NativeFunctionDeclarationError) {
v8::HandleScope handle_scope(CcTest::isolate());
const char* name = "nativedeclerr";
// Syntax error in extension code.
@@ -6873,7 +6880,7 @@ THREADED_TEST(NativeFunctionDeclarationError) {
}
-THREADED_TEST(NativeFunctionDeclarationErrorEscape) {
+TEST(NativeFunctionDeclarationErrorEscape) {
v8::HandleScope handle_scope(CcTest::isolate());
const char* name = "nativedeclerresc";
// Syntax error in extension code - escape code in "native" means that
@@ -7135,7 +7142,7 @@ void WhammyPropertyGetter(Local<String> name,
}
-THREADED_TEST(WeakReference) {
+TEST(WeakReference) {
i::FLAG_expose_gc = true;
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handle_scope(isolate);
@@ -10668,9 +10675,9 @@ THREADED_TEST(FunctionDescriptorException) {
" (new Fun()).blah()"
" } catch (e) {"
" var str = String(e);"
- " if (str.indexOf('TypeError') == -1) return 1;"
- " if (str.indexOf('[object Fun]') != -1) return 2;"
- " if (str.indexOf('#<Fun>') == -1) return 3;"
+ // " if (str.indexOf('TypeError') == -1) return 1;"
+ // " if (str.indexOf('[object Fun]') != -1) return 2;"
+ // " if (str.indexOf('#<Fun>') == -1) return 3;"
" return 0;"
" }"
" return 4;"
@@ -10945,7 +10952,8 @@ THREADED_TEST(CallAsFunction) {
CHECK(value.IsEmpty());
CHECK(try_catch.HasCaught());
String::Utf8Value exception_value1(try_catch.Exception());
- CHECK_EQ("TypeError: Property 'obj2' of object #<Object> is not a function",
+ // TODO(verwaest): Better message
+ CHECK_EQ("TypeError: object is not a function",
*exception_value1);
try_catch.Reset();
@@ -12328,7 +12336,8 @@ THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) {
" }"
"}");
CHECK(try_catch.HasCaught());
- CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"),
+ // TODO(verwaest): Adjust message.
+ CHECK_EQ(v8_str("TypeError: undefined is not a function"),
try_catch.Exception()->ToString());
CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
CHECK_GE(interceptor_call_count, 50);
@@ -12502,7 +12511,8 @@ THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss2) {
" }"
"}");
CHECK(try_catch.HasCaught());
- CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"),
+ // TODO(verwaest): Adjust message.
+ CHECK_EQ(v8_str("TypeError: undefined is not a function"),
try_catch.Exception()->ToString());
CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
}
@@ -15213,13 +15223,10 @@ TEST(CompileExternalTwoByteSource) {
// Compile the sources as external two byte strings.
for (int i = 0; ascii_sources[i] != NULL; i++) {
uint16_t* two_byte_string = AsciiToTwoByteString(ascii_sources[i]);
- UC16VectorResource uc16_resource(
- i::Vector<const uint16_t>(two_byte_string,
- i::StrLength(ascii_sources[i])));
+ TestResource* uc16_resource = new TestResource(two_byte_string);
v8::Local<v8::String> source =
- v8::String::NewExternal(context->GetIsolate(), &uc16_resource);
+ v8::String::NewExternal(context->GetIsolate(), uc16_resource);
v8::Script::Compile(source);
- i::DeleteArray(two_byte_string);
}
}
@@ -17866,12 +17873,12 @@ TEST(VisitExternalStrings) {
resource[0] = new TestResource(two_byte_string);
v8::Local<v8::String> string0 =
v8::String::NewExternal(env->GetIsolate(), resource[0]);
- resource[1] = new TestResource(two_byte_string);
+ resource[1] = new TestResource(two_byte_string, NULL, false);
v8::Local<v8::String> string1 =
v8::String::NewExternal(env->GetIsolate(), resource[1]);
// Externalized symbol.
- resource[2] = new TestResource(two_byte_string);
+ resource[2] = new TestResource(two_byte_string, NULL, false);
v8::Local<v8::String> string2 = v8::String::NewFromUtf8(
env->GetIsolate(), string, v8::String::kInternalizedString);
CHECK(string2->MakeExternal(resource[2]));
@@ -18947,8 +18954,9 @@ TEST(ContainsOnlyOneByte) {
}
string_contents[length-1] = 0;
// Simple case.
- Handle<String> string;
- string = String::NewExternal(isolate, new TestResource(string_contents));
+ Handle<String> string =
+ String::NewExternal(isolate,
+ new TestResource(string_contents, NULL, false));
CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte());
// Counter example.
string = String::NewFromTwoByte(isolate, string_contents);
@@ -18965,7 +18973,9 @@ TEST(ContainsOnlyOneByte) {
balanced = String::Concat(balanced, right);
Handle<String> cons_strings[] = {left, balanced, right};
Handle<String> two_byte =
- String::NewExternal(isolate, new TestResource(string_contents));
+ String::NewExternal(isolate,
+ new TestResource(string_contents, NULL, false));
+ USE(two_byte); USE(cons_strings);
for (size_t i = 0; i < ARRAY_SIZE(cons_strings); i++) {
// Base assumptions.
string = cons_strings[i];
@@ -18986,7 +18996,8 @@ TEST(ContainsOnlyOneByte) {
int shift = 8 + (i % 7);
string_contents[alignment + i] = 1 << shift;
string = String::NewExternal(
- isolate, new TestResource(string_contents + alignment));
+ isolate,
+ new TestResource(string_contents + alignment, NULL, false));
CHECK_EQ(size, string->Length());
CHECK(!string->ContainsOnlyOneByte());
string_contents[alignment + i] = 0x41;
@@ -20594,7 +20605,11 @@ static void StubCacheHelper(bool primary) {
int updates = updates_counter - initial_updates;
CHECK_LT(updates, 10);
CHECK_LT(misses, 10);
- CHECK_GE(probes, 10000);
+ // TODO(verwaest): Update this test to overflow the degree of polymorphism
+ // before megamorphism. The number of probes will only work once we teach the
+ // serializer to embed references to counters in the stubs, given that the
+ // megamorphic_stub_cache_probes is updated in a snapshot-generated stub.
+ CHECK_GE(probes, 0);
#endif
}
@@ -21840,3 +21855,132 @@ TEST(Regress239669) {
" new C1();"
"}");
}
+
+
+class ApiCallOptimizationChecker {
+ private:
+ static Local<Object> data;
+ static Local<Object> receiver;
+ static Local<Object> holder;
+ static Local<Object> callee;
+ static int count;
+
+ static void OptimizationCallback(
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
+ CHECK(callee == info.Callee());
+ CHECK(data == info.Data());
+ CHECK(receiver == info.This());
+ CHECK(holder == info.Holder());
+ count++;
+ }
+
+ public:
+ void Run(bool use_signature, bool global) {
+ v8::Isolate* isolate = CcTest::isolate();
+ v8::HandleScope scope(isolate);
+ // Build a template for signature checks.
+ Local<v8::ObjectTemplate> signature_template;
+ Local<v8::Signature> signature;
+ {
+ Local<v8::FunctionTemplate> parent_template =
+ FunctionTemplate::New(isolate);
+ parent_template->SetHiddenPrototype(true);
+ Local<v8::FunctionTemplate> function_template
+ = FunctionTemplate::New(isolate);
+ function_template->Inherit(parent_template);
+ if (use_signature) {
+ signature = v8::Signature::New(isolate, parent_template);
+ }
+ signature_template = function_template->InstanceTemplate();
+ }
+ // Global object must pass checks.
+ Local<v8::Context> context =
+ v8::Context::New(isolate, NULL, signature_template);
+ v8::Context::Scope context_scope(context);
+ // Install regular object that can pass signature checks.
+ Local<Object> function_receiver = signature_template->NewInstance();
+ context->Global()->Set(v8_str("function_receiver"), function_receiver);
+ // Get the holder objects.
+ Local<Object> inner_global =
+ Local<Object>::Cast(context->Global()->GetPrototype());
+ Local<Object> function_holder =
+ Local<Object>::Cast(function_receiver->GetPrototype());
+ // Install function on hidden prototype object.
+ data = Object::New(isolate);
+ Local<FunctionTemplate> function_template = FunctionTemplate::New(
+ isolate, OptimizationCallback, data, signature);
+ Local<Function> function = function_template->GetFunction();
+ Local<Object>::Cast(
+ inner_global->GetPrototype())->Set(v8_str("global_f"), function);
+ function_holder->Set(v8_str("f"), function);
+ // Initialize expected values.
+ callee = function;
+ count = 0;
+ if (global) {
+ receiver = context->Global();
+ holder = inner_global;
+ } else {
+ holder = function_receiver;
+ // If not using a signature, add something else to the prototype chain
+ // to test the case that holder != receiver
+ if (!use_signature) {
+ receiver = Local<Object>::Cast(CompileRun(
+ "var receiver_subclass = {};\n"
+ "receiver_subclass.__proto__ = function_receiver;\n"
+ "receiver_subclass"));
+ } else {
+ receiver = Local<Object>::Cast(CompileRun(
+ "var receiver_subclass = function_receiver;\n"
+ "receiver_subclass"));
+ }
+ }
+ // With no signature, the holder is not set.
+ if (!use_signature) holder = receiver;
+ // build wrap_function
+ int key = (use_signature ? 1 : 0) + 2 * (global ? 1 : 0);
+ i::ScopedVector<char> wrap_function(100);
+ if (global) {
+ i::OS::SNPrintF(
+ wrap_function,
+ "function wrap_%d() { var f = global_f; return f(); }\n",
+ key);
+ } else {
+ i::OS::SNPrintF(
+ wrap_function,
+ "function wrap_%d() { return receiver_subclass.f(); }\n",
+ key);
+ }
+ // build source string
+ i::ScopedVector<char> source(500);
+ i::OS::SNPrintF(
+ source,
+ "%s\n" // wrap_function
+ "function wrap2() { wrap_%d(); }\n"
+ "wrap2();\n"
+ "wrap2();\n"
+ "%%OptimizeFunctionOnNextCall(wrap_%d);\n"
+ "wrap2();\n",
+ wrap_function.start(), key, key);
+ v8::TryCatch try_catch;
+ CompileRun(source.start());
+ ASSERT(!try_catch.HasCaught());
+ CHECK_EQ(3, count);
+ }
+};
+
+
+Local<Object> ApiCallOptimizationChecker::data;
+Local<Object> ApiCallOptimizationChecker::receiver;
+Local<Object> ApiCallOptimizationChecker::holder;
+Local<Object> ApiCallOptimizationChecker::callee;
+int ApiCallOptimizationChecker::count = 0;
+
+
+TEST(TestFunctionCallOptimization) {
+ i::FLAG_allow_natives_syntax = true;
+ ApiCallOptimizationChecker checker;
+ checker.Run(true, true);
+ checker.Run(false, true);
+ checker.Run(true, false);
+ checker.Run(false, false);
+}
« no previous file with comments | « test/cctest/cctest.status ('k') | test/cctest/test-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698