1 /* 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 #include <assert.h> 25 #include <jni.h> 26 27 #include <pthread.h> 28 29 JavaVM* jvm; 30 31 void * 32 floobydust (void *p) { 33 JNIEnv *env; 34 jclass class_id; 35 jmethodID method_id; 36 37 (*jvm)->AttachCurrentThread(jvm, (void**)&env, NULL); 38 39 class_id = (*env)->FindClass (env, "DoOverflow"); 40 assert (class_id); 41 42 method_id = (*env)->GetStaticMethodID(env, class_id, "printIt", "()V"); 43 assert (method_id); 44 45 (*env)->CallStaticVoidMethod(env, class_id, method_id, NULL); 46 47 (*jvm)->DetachCurrentThread(jvm); 48 } 49 50 int 51 main (int argc, const char** argv) { 52 JavaVMOption options[1]; 53 options[0].optionString = (char*) "-Xss320k"; 54 55 JavaVMInitArgs vm_args; 56 vm_args.version = JNI_VERSION_1_2; 57 vm_args.ignoreUnrecognized = JNI_TRUE; 58 vm_args.options = options; 59 vm_args.nOptions = 1; 60 61 JNIEnv* env; 62 jint result = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args); 63 assert(result >= 0); 64 65 pthread_t thr; 66 pthread_create(&thr, NULL, floobydust, NULL); 67 pthread_join(thr, NULL); 68 69 floobydust(NULL); 70 71 return 0; 72 }