sahilTakiar commented on a change in pull request #595: HDFS-14304: High lock contention on hdfsHashMutex in libhdfs URL: https://github.com/apache/hadoop/pull/595#discussion_r266613020
########## File path: hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/jclasses.h ########## @@ -0,0 +1,87 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LIBHDFS_JCLASSES_H +#define LIBHDFS_JCLASSES_H + +#include <jni.h> + +/** + * A collection of commonly used jclass objects that are used throughout + * hdfs.c. The jclasses are loaded immediately after the JVM is created (see + * jni_helper.h getJNIEnv). By pre-allocated the jclass objects we avoid + * duplicate calls to FindClass every time we want to invoke a Java method via + * the JNI. + */ + +/* HDFS classes */ Review comment: Makes sense. I ended up implementing something similar to what you suggested, although some of the data structure layout is a bit different. All of the logic is encapsulated in `jclasses.h` / `jclasses.c`. Essentially, there is a single array `cachedJavaClasses` that contains `NUM_CACHED_CLASSES` `javaClassAndName` structs (`jclass` and `const char *className`). `jclasses.h` exposes two methods: `getJclass` that returns a `*jclass` from a `CachedJavaClass` and `getClassName` that returns the class name of the `CachedJavaClass`. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
