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

Side by Side Diff: src/api.cc

Issue 20305004: Check that ExternalString objects get aligned resources. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added missing checks. Created 7 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 isolate->set_context_exit_happened(true); 773 isolate->set_context_exit_happened(true);
774 } 774 }
775 775
776 776
777 static void* DecodeSmiToAligned(i::Object* value, const char* location) { 777 static void* DecodeSmiToAligned(i::Object* value, const char* location) {
778 ApiCheck(value->IsSmi(), location, "Not a Smi"); 778 ApiCheck(value->IsSmi(), location, "Not a Smi");
779 return reinterpret_cast<void*>(value); 779 return reinterpret_cast<void*>(value);
780 } 780 }
781 781
782 782
783 static i::Smi* EncodeAlignedAsSmi(void* value, const char* location) { 783 static i::Smi* EncodeAlignedAsSmi(const void* value, const char* location) {
784 i::Smi* smi = reinterpret_cast<i::Smi*>(value); 784 i::Smi* smi = const_cast<i::Smi*>(reinterpret_cast<const i::Smi*>(value));
785 ApiCheck(smi->IsSmi(), location, "Pointer is not aligned"); 785 ApiCheck(smi->IsSmi(), location, "Pointer is not aligned");
786 return smi; 786 return smi;
787 } 787 }
788 788
789 789
790 static i::Handle<i::FixedArray> EmbedderDataFor(Context* context, 790 static i::Handle<i::FixedArray> EmbedderDataFor(Context* context,
791 int index, 791 int index,
792 bool can_grow, 792 bool can_grow,
793 const char* location) { 793 const char* location) {
794 i::Handle<i::Context> env = Utils::OpenHandle(context); 794 i::Handle<i::Context> env = Utils::OpenHandle(context);
(...skipping 5136 matching lines...) Expand 10 before | Expand all | Expand 10 after
5931 } 5931 }
5932 5932
5933 5933
5934 Local<String> v8::String::NewExternal( 5934 Local<String> v8::String::NewExternal(
5935 v8::String::ExternalStringResource* resource) { 5935 v8::String::ExternalStringResource* resource) {
5936 i::Isolate* isolate = i::Isolate::Current(); 5936 i::Isolate* isolate = i::Isolate::Current();
5937 EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); 5937 EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()");
5938 LOG_API(isolate, "String::NewExternal"); 5938 LOG_API(isolate, "String::NewExternal");
5939 ENTER_V8(isolate); 5939 ENTER_V8(isolate);
5940 CHECK(resource && resource->data()); 5940 CHECK(resource && resource->data());
5941 // Resource pointers need to look like Smis since ExternalString objects
5942 // are sometimes put into old pointer space (see i::String::MakeExternal).
5943 CHECK(EncodeAlignedAsSmi(resource, "v8::String::NewExternal()"));
5944 CHECK(EncodeAlignedAsSmi(resource->data(), "v8::String::NewExternal()"));
5941 i::Handle<i::String> result = NewExternalStringHandle(isolate, resource); 5945 i::Handle<i::String> result = NewExternalStringHandle(isolate, resource);
5942 isolate->heap()->external_string_table()->AddString(*result); 5946 isolate->heap()->external_string_table()->AddString(*result);
5943 return Utils::ToLocal(result); 5947 return Utils::ToLocal(result);
5944 } 5948 }
5945 5949
5946 5950
5947 bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { 5951 bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) {
5948 i::Handle<i::String> obj = Utils::OpenHandle(this); 5952 i::Handle<i::String> obj = Utils::OpenHandle(this);
5949 i::Isolate* isolate = obj->GetIsolate(); 5953 i::Isolate* isolate = obj->GetIsolate();
5950 if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false; 5954 if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false;
5951 if (i::StringShape(*obj).IsExternalTwoByte()) { 5955 if (i::StringShape(*obj).IsExternalTwoByte()) {
5952 return false; // Already an external string. 5956 return false; // Already an external string.
5953 } 5957 }
5954 ENTER_V8(isolate); 5958 ENTER_V8(isolate);
5955 if (isolate->string_tracker()->IsFreshUnusedString(obj)) { 5959 if (isolate->string_tracker()->IsFreshUnusedString(obj)) {
5956 return false; 5960 return false;
5957 } 5961 }
5958 if (isolate->heap()->IsInGCPostProcessing()) { 5962 if (isolate->heap()->IsInGCPostProcessing()) {
5959 return false; 5963 return false;
5960 } 5964 }
5961 CHECK(resource && resource->data()); 5965 CHECK(resource && resource->data());
5966 // Resource pointers need to look like Smis since ExternalString objects
5967 // are sometimes put into old pointer space (see i::String::MakeExternal).
5968 CHECK(EncodeAlignedAsSmi(resource, "v8::String::MakeExternal()"));
5969 CHECK(EncodeAlignedAsSmi(resource->data(), "v8::String::MakeExternal()"));
5962 bool result = obj->MakeExternal(resource); 5970 bool result = obj->MakeExternal(resource);
5963 if (result && !obj->IsInternalizedString()) { 5971 if (result && !obj->IsInternalizedString()) {
5964 isolate->heap()->external_string_table()->AddString(*obj); 5972 isolate->heap()->external_string_table()->AddString(*obj);
5965 } 5973 }
5966 return result; 5974 return result;
5967 } 5975 }
5968 5976
5969 5977
5970 Local<String> v8::String::NewExternal( 5978 Local<String> v8::String::NewExternal(
5971 v8::String::ExternalAsciiStringResource* resource) { 5979 v8::String::ExternalAsciiStringResource* resource) {
5972 i::Isolate* isolate = i::Isolate::Current(); 5980 i::Isolate* isolate = i::Isolate::Current();
5973 EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); 5981 EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()");
5974 LOG_API(isolate, "String::NewExternal"); 5982 LOG_API(isolate, "String::NewExternal");
5975 ENTER_V8(isolate); 5983 ENTER_V8(isolate);
5976 CHECK(resource && resource->data()); 5984 CHECK(resource && resource->data());
5985 // Resource pointers need to look like Smis since ExternalString objects
5986 // are sometimes put into old pointer space (see i::String::MakeExternal).
5987 CHECK(EncodeAlignedAsSmi(resource, "v8::String::NewExternal()"));
5988 CHECK(EncodeAlignedAsSmi(resource->data(), "v8::String::NewExternal()"));
5977 i::Handle<i::String> result = NewExternalAsciiStringHandle(isolate, resource); 5989 i::Handle<i::String> result = NewExternalAsciiStringHandle(isolate, resource);
5978 isolate->heap()->external_string_table()->AddString(*result); 5990 isolate->heap()->external_string_table()->AddString(*result);
5979 return Utils::ToLocal(result); 5991 return Utils::ToLocal(result);
5980 } 5992 }
5981 5993
5982 5994
5983 bool v8::String::MakeExternal( 5995 bool v8::String::MakeExternal(
5984 v8::String::ExternalAsciiStringResource* resource) { 5996 v8::String::ExternalAsciiStringResource* resource) {
5985 i::Handle<i::String> obj = Utils::OpenHandle(this); 5997 i::Handle<i::String> obj = Utils::OpenHandle(this);
5986 i::Isolate* isolate = obj->GetIsolate(); 5998 i::Isolate* isolate = obj->GetIsolate();
5987 if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false; 5999 if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false;
5988 if (i::StringShape(*obj).IsExternalTwoByte()) { 6000 if (i::StringShape(*obj).IsExternalTwoByte()) {
5989 return false; // Already an external string. 6001 return false; // Already an external string.
5990 } 6002 }
5991 ENTER_V8(isolate); 6003 ENTER_V8(isolate);
5992 if (isolate->string_tracker()->IsFreshUnusedString(obj)) { 6004 if (isolate->string_tracker()->IsFreshUnusedString(obj)) {
5993 return false; 6005 return false;
5994 } 6006 }
5995 if (isolate->heap()->IsInGCPostProcessing()) { 6007 if (isolate->heap()->IsInGCPostProcessing()) {
5996 return false; 6008 return false;
5997 } 6009 }
5998 CHECK(resource && resource->data()); 6010 CHECK(resource && resource->data());
6011 // Resource pointers need to look like Smis since ExternalString objects
6012 // are sometimes put into old pointer space (see i::String::MakeExternal).
6013 CHECK(EncodeAlignedAsSmi(resource, "v8::String::MakeExternal()"));
6014 CHECK(EncodeAlignedAsSmi(resource->data(), "v8::String::MakeExternal()"));
5999 bool result = obj->MakeExternal(resource); 6015 bool result = obj->MakeExternal(resource);
6000 if (result && !obj->IsInternalizedString()) { 6016 if (result && !obj->IsInternalizedString()) {
6001 isolate->heap()->external_string_table()->AddString(*obj); 6017 isolate->heap()->external_string_table()->AddString(*obj);
6002 } 6018 }
6003 return result; 6019 return result;
6004 } 6020 }
6005 6021
6006 6022
6007 bool v8::String::CanMakeExternal() { 6023 bool v8::String::CanMakeExternal() {
6008 if (!internal::FLAG_clever_optimizations) return false; 6024 if (!internal::FLAG_clever_optimizations) return false;
(...skipping 2044 matching lines...) Expand 10 before | Expand all | Expand 10 after
8053 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 8069 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
8054 Address callback_address = 8070 Address callback_address =
8055 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8071 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8056 VMState<EXTERNAL> state(isolate); 8072 VMState<EXTERNAL> state(isolate);
8057 ExternalCallbackScope call_scope(isolate, callback_address); 8073 ExternalCallbackScope call_scope(isolate, callback_address);
8058 return callback(info); 8074 return callback(info);
8059 } 8075 }
8060 8076
8061 8077
8062 } } // namespace v8::internal 8078 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698