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

Unified Diff: tools/android/memconsumer/memconsumer_hook.cc

Issue 1841863002: Update monet. (Closed) Base URL: https://github.com/domokit/monet.git@master
Patch Set: Created 4 years, 9 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
Index: tools/android/memconsumer/memconsumer_hook.cc
diff --git a/tools/android/memconsumer/memconsumer_hook.cc b/tools/android/memconsumer/memconsumer_hook.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9ae0bc14f03c03d77360db44a09c45eb02b9e569
--- /dev/null
+++ b/tools/android/memconsumer/memconsumer_hook.cc
@@ -0,0 +1,55 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <android/log.h>
+#include <jni.h>
+#include <stdio.h>
+#include <string.h>
+
+extern "C" {
+JNIEXPORT void JNICALL
+ Java_org_chromium_memconsumer_ResidentService_nativeUseMemory(JNIEnv* env,
+ jobject clazz,
+ jlong memory);
+}
+
+namespace {
+
+uint32_t get_random() {
+ static uint32_t m_w = 1;
+ static uint32_t m_z = 1;
+ m_z = 36969 * (m_z & 65535) + (m_z >> 16);
+ m_w = 18000 * (m_w & 65535) + (m_w >> 16);
+ return (m_z << 16) + m_w;
+}
+
+} // namespace
+
+JNIEXPORT void JNICALL
+ Java_org_chromium_memconsumer_ResidentService_nativeUseMemory(
+ JNIEnv* env,
+ jobject clazz,
+ jlong memory) {
+ static uint32_t* g_memory = NULL;
+ if (g_memory)
+ free(g_memory);
+ if (memory == 0) {
+ g_memory = NULL;
+ return;
+ }
+ g_memory = static_cast<uint32_t*>(malloc(memory));
+ if (!g_memory) {
+ __android_log_print(ANDROID_LOG_WARN,
+ "MemConsumer",
+ "Unable to allocate %ld bytes",
+ memory);
+ }
+ // If memory allocation failed, try to allocate as much as possible.
+ while (!g_memory) {
+ memory /= 2;
+ g_memory = static_cast<uint32_t*>(malloc(memory));
+ }
+ for (int i = 0; i < memory / sizeof(uint32_t); ++i)
+ *(g_memory + i) = get_random();
+}
« no previous file with comments | « tools/android/memconsumer/java/src/org/chromium/memconsumer/ResidentService.java ('k') | tools/android/memdump/memdump.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698