hadoop-common-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [hadoop] toddlipcon commented on a change in pull request #595: HDFS-14304: High lock contention on hdfsHashMutex in libhdfs
Date Wed, 13 Mar 2019 19:04:13 GMT
toddlipcon 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_r265286707

 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.
+ */
+#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:
   Here's an idea that may simplify the diff and the code a bit:
   Instead of defining a jclass and a const char* for each class, you did something like this
in the header:
   enum CachedJavaClass {
   extern jclass g_cached_classes[JC_NUM_CACHED_CLASSES];
   and then in jclasses.c:
   jclass g_cached_classes[JC_NUM_CACHED_CLASSES];
   typedef struct idx_with_class {
     int idx;
     const char* clazz;
   static idx_with_class IDS_WITH_CLASSES[] = {
     {JC_CONFIGURATION, "org/apache/hadoop/conf/Configuration"},
     {JC_PATH, "org/apache/hadoop/Path"},
     {-1, NULL}
   static void init_cached_class(int index, const char* class) {
     ... find java class and init g_cached_classes[index];
   void init_cached_classes(JNIEnv* env) {
     for (int i = 0; IDS_WITH_CLASSES[i].idx >= 0; i++) {
       int idx = IDS_WITH_CLASSES[i].idx;
       if (!init_cached_class(IDS_WITH_CLASSES[i].clazz, &g_cached_classes[idx])) {
         FATAL("failed to init class %s', ...);
     for (int i = 0; i < JC_NUM_CACHED_CLASSES; i++) {
       if (!g_cached_classes[i]) {
         // this would be a bug if we missed one in the IDS_WITH_CLASSES list, but cheap enough
to just
         // validate at runtime anyway
         FATAL("missing initialization for class index %d", i);
   Then in the various other call sites you can just pass the class 'ID' and look it up from
this array? Might simplify the code a bit and make it a bit more "declarative" vs the repeated
copy-pasting in the init sequence.

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:

With regards,
Apache Git Services

To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org

View raw message