1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <android/log.h>
11 JNIEXPORT
void JNICALL
12 Java_org_chromium_memconsumer_ResidentService_nativeUseMemory(JNIEnv
* env
,
19 uint32_t get_random() {
20 static uint32_t m_w
= 1;
21 static uint32_t m_z
= 1;
22 m_z
= 36969 * (m_z
& 65535) + (m_z
>> 16);
23 m_w
= 18000 * (m_w
& 65535) + (m_w
>> 16);
24 return (m_z
<< 16) + m_w
;
29 JNIEXPORT
void JNICALL
30 Java_org_chromium_memconsumer_ResidentService_nativeUseMemory(
34 static uint32_t* g_memory
= NULL
;
41 g_memory
= static_cast<uint32_t*>(malloc(memory
));
43 __android_log_print(ANDROID_LOG_WARN
,
45 "Unable to allocate %ld bytes",
48 // If memory allocation failed, try to allocate as much as possible.
51 g_memory
= static_cast<uint32_t*>(malloc(memory
));
53 for (int i
= 0; i
< memory
/ sizeof(uint32_t); ++i
)
54 *(g_memory
+ i
) = get_random();