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

Unified Diff: third_party/WebKit/Source/modules/webaudio/PeriodicWave.cpp

Issue 1632753002: Report PeriodicWave memory usage to v8 so GC can be properly scheduled (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added virtual Created 4 years, 11 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 | « third_party/WebKit/Source/modules/webaudio/PeriodicWave.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/webaudio/PeriodicWave.cpp
diff --git a/third_party/WebKit/Source/modules/webaudio/PeriodicWave.cpp b/third_party/WebKit/Source/modules/webaudio/PeriodicWave.cpp
index 7bfedbe0b1b9f2a46b6c85d4afaa09ec19be91e5..db4c8b2cc9a016be3fa4e516175edb83966d166c 100644
--- a/third_party/WebKit/Source/modules/webaudio/PeriodicWave.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/PeriodicWave.cpp
@@ -87,7 +87,8 @@ PeriodicWave* PeriodicWave::createTriangle(float sampleRate)
}
PeriodicWave::PeriodicWave(float sampleRate)
- : m_sampleRate(sampleRate)
+ : m_v8ExternalMemory(0)
+ , m_sampleRate(sampleRate)
, m_centsPerRange(CentsPerRange)
{
float nyquist = 0.5 * m_sampleRate;
@@ -98,6 +99,11 @@ PeriodicWave::PeriodicWave(float sampleRate)
m_numberOfRanges = 0.5 + kNumberOfOctaveBands * log2f(periodicWaveSize());
}
+PeriodicWave::~PeriodicWave()
+{
+ adjustV8ExternalMemory(-static_cast<int64_t>(m_v8ExternalMemory));
+}
+
unsigned PeriodicWave::periodicWaveSize() const
{
// Choose an appropriate wave size for the given sample rate. This allows us to use shorter
@@ -162,6 +168,13 @@ unsigned PeriodicWave::numberOfPartialsForRange(unsigned rangeIndex) const
return numberOfPartials;
}
+// Tell V8 about the memory we're using so it can properly schedule garbage collects.
+void PeriodicWave::adjustV8ExternalMemory(int delta)
+{
+ v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(delta);
+ m_v8ExternalMemory += delta;
+}
+
// Convert into time-domain wave buffers.
// One table is created for each range for non-aliasing playback at different playback rates.
// Thus, higher ranges have more high-frequency partials culled out.
@@ -208,7 +221,9 @@ void PeriodicWave::createBandLimitedTables(const float* realData, const float* i
imagP[0] = 0;
// Create the band-limited table.
- OwnPtr<AudioFloatArray> table = adoptPtr(new AudioFloatArray(periodicWaveSize()));
+ unsigned waveSize = periodicWaveSize();
+ OwnPtr<AudioFloatArray> table = adoptPtr(new AudioFloatArray(waveSize));
+ adjustV8ExternalMemory(waveSize * sizeof(float));
m_bandLimitedTables.append(table.release());
// Apply an inverse FFT to generate the time-domain table data.
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/PeriodicWave.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698