Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 wireData.length()); | 121 wireData.length()); |
| 122 } | 122 } |
| 123 | 123 |
| 124 SerializedScriptValue::~SerializedScriptValue() { | 124 SerializedScriptValue::~SerializedScriptValue() { |
| 125 // If the allocated memory was not registered before, then this class is | 125 // If the allocated memory was not registered before, then this class is |
| 126 // likely used in a context other than Worker's onmessage environment and the | 126 // likely used in a context other than Worker's onmessage environment and the |
| 127 // presence of current v8 context is not guaranteed. Avoid calling v8 then. | 127 // presence of current v8 context is not guaranteed. Avoid calling v8 then. |
| 128 if (m_externallyAllocatedMemory) { | 128 if (m_externallyAllocatedMemory) { |
| 129 ASSERT(v8::Isolate::GetCurrent()); | 129 ASSERT(v8::Isolate::GetCurrent()); |
| 130 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( | 130 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( |
| 131 -m_externallyAllocatedMemory); | 131 -m_externallyAllocatedMemory + 1); |
| 132 } | 132 } |
| 133 } | 133 } |
| 134 | 134 |
| 135 PassRefPtr<SerializedScriptValue> SerializedScriptValue::nullValue() { | 135 PassRefPtr<SerializedScriptValue> SerializedScriptValue::nullValue() { |
| 136 // UChar rather than uint8_t here to get host endian behavior. | 136 // UChar rather than uint8_t here to get host endian behavior. |
| 137 static const UChar kNullData[] = {0xff09, 0x3000}; | 137 static const UChar kNullData[] = {0xff09, 0x3000}; |
| 138 return create(reinterpret_cast<const char*>(kNullData), sizeof(kNullData)); | 138 return create(reinterpret_cast<const char*>(kNullData), sizeof(kNullData)); |
| 139 } | 139 } |
| 140 | 140 |
| 141 String SerializedScriptValue::toWireString() const { | 141 String SerializedScriptValue::toWireString() const { |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 | 437 |
| 438 if (isNeuterable) { | 438 if (isNeuterable) { |
| 439 for (const auto& bufferHandle : bufferHandles) | 439 for (const auto& bufferHandle : bufferHandles) |
| 440 bufferHandle->Neuter(); | 440 bufferHandle->Neuter(); |
| 441 } | 441 } |
| 442 } | 442 } |
| 443 } | 443 } |
| 444 return contents; | 444 return contents; |
| 445 } | 445 } |
| 446 | 446 |
| 447 void SerializedScriptValue::unregisterMemoryAllocatedByCurrentScriptContext() { | |
| 448 if (m_externallyAllocatedMemory == 1) | |
|
jbroman
2017/03/07 18:00:04
Use of this magic value is confusing. I'd suggest
sof
2017/03/07 19:14:03
It's not particularly clever; I can switch to an i
jbroman
2017/03/07 19:29:05
(u)int64_t + boolean in a bitfield would do the tr
sof
2017/03/07 19:30:20
Done.
| |
| 449 return; | |
| 450 if (m_externallyAllocatedMemory) { | |
| 451 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( | |
| 452 -(m_externallyAllocatedMemory - 1)); | |
| 453 m_externallyAllocatedMemory = 0; | |
| 454 } | |
| 455 // TODO: if other transferables start accounting for their external | |
| 456 // allocations with V8, extend this with corresponding cases. | |
| 457 if (m_arrayBufferContentsArray) { | |
| 458 for (size_t i = 0; i < m_arrayBufferContentsArray->size(); ++i) { | |
| 459 int64_t bufferSize = | |
| 460 static_cast<int64_t>(m_arrayBufferContentsArray->at(i).sizeInBytes()); | |
| 461 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( | |
| 462 -bufferSize); | |
| 463 } | |
| 464 // Mark the value as needing re-registration by its target context. | |
| 465 m_externallyAllocatedMemory = static_cast<intptr_t>(1); | |
| 466 } | |
| 467 } | |
| 468 | |
| 447 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() { | 469 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() { |
| 448 if (m_externallyAllocatedMemory) | 470 if (m_externallyAllocatedMemory != 1) |
| 449 return; | 471 return; |
| 450 | 472 |
| 451 m_externallyAllocatedMemory = static_cast<intptr_t>(dataLengthInBytes()); | 473 bool registerTransferables = |
| 474 m_externallyAllocatedMemory == static_cast<intptr_t>(1); | |
| 475 size_t size = dataLengthInBytes(); | |
| 452 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( | 476 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( |
| 453 m_externallyAllocatedMemory); | 477 static_cast<intptr_t>(size)); |
| 478 m_externallyAllocatedMemory = static_cast<int64_t>(size ? (size + 1) : 0); | |
| 479 if (registerTransferables) { | |
| 480 DCHECK(m_arrayBufferContentsArray); | |
| 481 for (size_t i = 0; i < m_arrayBufferContentsArray->size(); ++i) { | |
| 482 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( | |
| 483 m_arrayBufferContentsArray->at(i).sizeInBytes()); | |
| 484 } | |
| 485 } | |
| 454 } | 486 } |
| 455 | 487 |
| 456 } // namespace blink | 488 } // namespace blink |
| OLD | NEW |