1 /* 2 * Copyright (c) 2005, 2018, 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 #include <jni.h> 24 #include <stdio.h> 25 26 JNIEXPORT void JNICALL 27 Java_gc_gctests_nativeGC05_nativeGC05_kickOffRefillers 28 (JNIEnv *env, jobject obj, jobject matrix, jobject stack) { 29 jclass matrixClass, stackClass, pairClass = 0; 30 jmethodID stack_pop_mid, stack_empty_mid, matrix_repopulate_mid, pair_geti_mid, pair_getj_mid; 31 jobject pair; 32 jint i, j; 33 jboolean b; 34 35 /* Get class objects associated with the objects passed in */ 36 matrixClass = (*env)->GetObjectClass(env, matrix); 37 stackClass = (*env)->GetObjectClass(env, stack); 38 39 /* GetMethodID's for the pop() and Repopulate() methods */ 40 stack_pop_mid = (*env)->GetMethodID(env, stackClass, "pop", "()Ljava/lang/Object;"); 41 if (stack_pop_mid == 0) { 42 printf("could not get a methodID for Stack::pop()\n"); 43 return; 44 } 45 stack_empty_mid = (*env)->GetMethodID(env, stackClass, "empty", "()Z"); 46 if (stack_empty_mid == 0) { 47 printf("could not get a methodID for Stack::empty()\n"); 48 return; 49 } 50 51 matrix_repopulate_mid = (*env)->GetMethodID(env, matrixClass, "repopulate", "(II)V"); 52 if (matrix_repopulate_mid == 0) { 53 printf("could not get a methodID for Matrix::repopulate(int, int)\n"); 54 return; 55 } 56 57 /** b = stack.empty(); */ 58 b = (*env)->CallBooleanMethod(env, stack, stack_empty_mid); 59 while (b == JNI_FALSE) { 60 /** pair = stack.pop() */ 61 pair = (*env)->CallObjectMethod(env, stack, stack_pop_mid); 62 63 if (pairClass == 0) { 64 pairClass = (*env)->GetObjectClass(env, pair); 65 pair_geti_mid = (*env)->GetMethodID(env, pairClass, "getI", "()I"); 66 if (pair_geti_mid == 0) { 67 printf("could not get a methodID for IndexPair::getI()\n"); 68 return; 69 } 70 pair_getj_mid = (*env)->GetMethodID(env, pairClass, "getJ", "()I"); 71 if (pair_getj_mid == 0) { 72 printf("could not get a methodID for IndexPair::getJ()\n"); 73 return; 74 } 75 } 76 77 /** i = pair.getI(); */ 78 i = (*env)->CallIntMethod(env, pair, pair_geti_mid); 79 /** j = pair.getJ(); */ 80 j = (*env)->CallIntMethod(env, pair, pair_getj_mid); 81 82 /* matrix.repopulate(i, j); */ 83 (*env)->CallVoidMethod(env, matrix, matrix_repopulate_mid, i, j); 84 85 /** b = stack.empty(); */ 86 b = (*env)->CallBooleanMethod(env, stack, stack_empty_mid); 87 } 88 }