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/objects.cc

Issue 169363002: Handlify DescriptorArray::Merge(). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address nit. 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/objects.h ('k') | 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 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
(...skipping 7974 matching lines...) Expand 10 before | Expand all | Expand 10 after
7985 DescriptorArray* src, 7985 DescriptorArray* src,
7986 int src_index, 7986 int src_index,
7987 const WhitenessWitness& witness) { 7987 const WhitenessWitness& witness) {
7988 Object* value = src->GetValue(src_index); 7988 Object* value = src->GetValue(src_index);
7989 PropertyDetails details = src->GetDetails(src_index); 7989 PropertyDetails details = src->GetDetails(src_index);
7990 Descriptor desc(src->GetKey(src_index), value, details); 7990 Descriptor desc(src->GetKey(src_index), value, details);
7991 Set(dst_index, &desc, witness); 7991 Set(dst_index, &desc, witness);
7992 } 7992 }
7993 7993
7994 7994
7995 // Generalize the |other| descriptor array by merging it into the (at least
7996 // partly) updated |desc| descriptor array.
7997 // The method merges two descriptor array in three parts. Both descriptor arrays
7998 // are identical up to |verbatim|. They also overlap in keys up to |valid|.
7999 // Between |verbatim| and |valid|, the resulting descriptor type as well as the
8000 // representation are generalized from both |desc| and |other|. Beyond |valid|,
8001 // the descriptors are copied verbatim from |other| up to |new_size|.
8002 // In case of incompatible types, the type and representation of |other| is
8003 // used.
7995 Handle<DescriptorArray> DescriptorArray::Merge(Handle<DescriptorArray> desc, 8004 Handle<DescriptorArray> DescriptorArray::Merge(Handle<DescriptorArray> desc,
7996 int verbatim, 8005 int verbatim,
7997 int valid, 8006 int valid,
7998 int new_size, 8007 int new_size,
7999 int modify_index, 8008 int modify_index,
8000 StoreMode store_mode, 8009 StoreMode store_mode,
8001 Handle<DescriptorArray> other) { 8010 Handle<DescriptorArray> other) {
8002 CALL_HEAP_FUNCTION(desc->GetIsolate(),
8003 desc->Merge(verbatim, valid, new_size, modify_index,
8004 store_mode, *other),
8005 DescriptorArray);
8006 }
8007
8008
8009 // Generalize the |other| descriptor array by merging it into the (at least
8010 // partly) updated |this| descriptor array.
8011 // The method merges two descriptor array in three parts. Both descriptor arrays
8012 // are identical up to |verbatim|. They also overlap in keys up to |valid|.
8013 // Between |verbatim| and |valid|, the resulting descriptor type as well as the
8014 // representation are generalized from both |this| and |other|. Beyond |valid|,
8015 // the descriptors are copied verbatim from |other| up to |new_size|.
8016 // In case of incompatible types, the type and representation of |other| is
8017 // used.
8018 MaybeObject* DescriptorArray::Merge(int verbatim,
8019 int valid,
8020 int new_size,
8021 int modify_index,
8022 StoreMode store_mode,
8023 DescriptorArray* other) {
8024 ASSERT(verbatim <= valid); 8011 ASSERT(verbatim <= valid);
8025 ASSERT(valid <= new_size); 8012 ASSERT(valid <= new_size);
8026 8013
8027 DescriptorArray* result;
8028 // Allocate a new descriptor array large enough to hold the required 8014 // Allocate a new descriptor array large enough to hold the required
8029 // descriptors, with minimally the exact same size as this descriptor array. 8015 // descriptors, with minimally the exact same size as this descriptor array.
8030 MaybeObject* maybe_descriptors = DescriptorArray::Allocate( 8016 Isolate* isolate = desc->GetIsolate();
8031 GetIsolate(), new_size, 8017 Handle<DescriptorArray> result = isolate->factory()->NewDescriptorArray(
8032 Max(new_size, other->number_of_descriptors()) - new_size); 8018 new_size, Max(new_size, other->number_of_descriptors()) - new_size);
8033 if (!maybe_descriptors->To(&result)) return maybe_descriptors; 8019 ASSERT(result->length() > desc->length() ||
8034 ASSERT(result->length() > length() ||
8035 result->NumberOfSlackDescriptors() > 0 || 8020 result->NumberOfSlackDescriptors() > 0 ||
8036 result->number_of_descriptors() == other->number_of_descriptors()); 8021 result->number_of_descriptors() == other->number_of_descriptors());
8037 ASSERT(result->number_of_descriptors() == new_size); 8022 ASSERT(result->number_of_descriptors() == new_size);
8038 8023
8039 DescriptorArray::WhitenessWitness witness(result);
8040
8041 int descriptor; 8024 int descriptor;
8042 8025
8043 // 0 -> |verbatim| 8026 // 0 -> |verbatim|
8044 int current_offset = 0; 8027 int current_offset = 0;
8045 for (descriptor = 0; descriptor < verbatim; descriptor++) { 8028 for (descriptor = 0; descriptor < verbatim; descriptor++) {
8046 if (GetDetails(descriptor).type() == FIELD) current_offset++; 8029 if (desc->GetDetails(descriptor).type() == FIELD) current_offset++;
8047 result->CopyFrom(descriptor, other, descriptor, witness); 8030 Descriptor d(other->GetKey(descriptor),
8031 other->GetValue(descriptor),
8032 other->GetDetails(descriptor));
8033 result->Set(descriptor, &d);
8048 } 8034 }
8049 8035
8050 // |verbatim| -> |valid| 8036 // |verbatim| -> |valid|
8051 for (; descriptor < valid; descriptor++) { 8037 for (; descriptor < valid; descriptor++) {
8052 Name* key = GetKey(descriptor); 8038 PropertyDetails details = desc->GetDetails(descriptor);
8053 PropertyDetails details = GetDetails(descriptor);
8054 PropertyDetails other_details = other->GetDetails(descriptor); 8039 PropertyDetails other_details = other->GetDetails(descriptor);
8055 8040
8056 if (details.type() == FIELD || other_details.type() == FIELD || 8041 if (details.type() == FIELD || other_details.type() == FIELD ||
8057 (store_mode == FORCE_FIELD && descriptor == modify_index) || 8042 (store_mode == FORCE_FIELD && descriptor == modify_index) ||
8058 (details.type() == CONSTANT && 8043 (details.type() == CONSTANT &&
8059 other_details.type() == CONSTANT && 8044 other_details.type() == CONSTANT &&
8060 GetValue(descriptor) != other->GetValue(descriptor))) { 8045 desc->GetValue(descriptor) != other->GetValue(descriptor))) {
8061 Representation representation = 8046 Representation representation =
8062 details.representation().generalize(other_details.representation()); 8047 details.representation().generalize(other_details.representation());
8063 FieldDescriptor d(key, 8048 FieldDescriptor d(desc->GetKey(descriptor),
8064 current_offset++, 8049 current_offset++,
8065 other_details.attributes(), 8050 other_details.attributes(),
8066 representation); 8051 representation);
8067 result->Set(descriptor, &d, witness); 8052 result->Set(descriptor, &d);
8068 } else { 8053 } else {
8069 result->CopyFrom(descriptor, other, descriptor, witness); 8054 Descriptor d(other->GetKey(descriptor),
8055 other->GetValue(descriptor),
8056 other->GetDetails(descriptor));
8057 result->Set(descriptor, &d);
8070 } 8058 }
8071 } 8059 }
8072 8060
8073 // |valid| -> |new_size| 8061 // |valid| -> |new_size|
8074 for (; descriptor < new_size; descriptor++) { 8062 for (; descriptor < new_size; descriptor++) {
8075 PropertyDetails details = other->GetDetails(descriptor); 8063 PropertyDetails details = other->GetDetails(descriptor);
8064
8076 if (details.type() == FIELD || 8065 if (details.type() == FIELD ||
8077 (store_mode == FORCE_FIELD && descriptor == modify_index)) { 8066 (store_mode == FORCE_FIELD && descriptor == modify_index)) {
8078 Name* key = other->GetKey(descriptor); 8067 FieldDescriptor d(other->GetKey(descriptor),
8079 FieldDescriptor d(key,
8080 current_offset++, 8068 current_offset++,
8081 details.attributes(), 8069 details.attributes(),
8082 details.representation()); 8070 details.representation());
8083 result->Set(descriptor, &d, witness); 8071 result->Set(descriptor, &d);
8084 } else { 8072 } else {
8085 result->CopyFrom(descriptor, other, descriptor, witness); 8073 Descriptor d(other->GetKey(descriptor),
8074 other->GetValue(descriptor),
8075 other->GetDetails(descriptor));
8076 result->Set(descriptor, &d);
8086 } 8077 }
8087 } 8078 }
8088 8079
8089 result->Sort(); 8080 result->Sort();
8090 return result; 8081 return result;
8091 } 8082 }
8092 8083
8093 8084
8094 // Checks whether a merge of |other| into |this| would return a copy of |this|. 8085 // Checks whether a merge of |other| into |this| would return a copy of |this|.
8095 bool DescriptorArray::IsMoreGeneralThan(int verbatim, 8086 bool DescriptorArray::IsMoreGeneralThan(int verbatim,
(...skipping 8400 matching lines...) Expand 10 before | Expand all | Expand 10 after
16496 #define ERROR_MESSAGES_TEXTS(C, T) T, 16487 #define ERROR_MESSAGES_TEXTS(C, T) T,
16497 static const char* error_messages_[] = { 16488 static const char* error_messages_[] = {
16498 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 16489 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
16499 }; 16490 };
16500 #undef ERROR_MESSAGES_TEXTS 16491 #undef ERROR_MESSAGES_TEXTS
16501 return error_messages_[reason]; 16492 return error_messages_[reason];
16502 } 16493 }
16503 16494
16504 16495
16505 } } // namespace v8::internal 16496 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698