clazz在“private static class clazz=snappydecompressor.class”源文件中的作用是什么?

i2loujxw  于 2021-06-02  发布在  Hadoop
关注(0)|答案(1)|浏览(550)

我正在研究snappy、zlib等的压缩器实现(java)。靠近源文件顶部的是下面的这一行。有人能给我解释一下这是什么意思吗?

HACK - Use this as a global lock in the JNI layer
@SuppressWarnings({"unchecked", "unused"})
private static Class clazz = SnappyDecompressor.class;

我知道,例如,在snappy中,snappydecompressor.java本质上是snappyc/本机实现的 Package 器,为了调用该c实现,java层通过jni接口进行调用。
snappy(java Package 器)的源代码snappydecompressor.java的顶部如下:

package org.apache.hadoop.io.compress.snappy;
import java.io.IOException;
import java.nio.Buffer;
import java.nio.ByteBuffer;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.io.compress.Decompressor;

/**
 * A {@link Decompressor} based on the snappy compression algorithm.
 * http://code.google.com/p/snappy/
 */
public class SnappyDecompressor implements Decompressor {
  private static final Log LOG =
      LogFactory.getLog(SnappyCompressor.class.getName());
  private static final int DEFAULT_DIRECT_BUFFER_SIZE = 64 * 1024;

  // HACK - Use this as a global lock in the JNI layer
  @SuppressWarnings({"unchecked", "unused"})
  private static Class clazz = SnappyDecompressor.class;

完整来源

doinxwow

doinxwow1#

如注解所示:它是从jni层使用的,似乎是为了从jni层进行一些锁定(查看完整的解压缩程序(源代码)
第76、77行:

SnappyDecompressor_clazz = (*env)->GetStaticFieldID(env, clazz, "clazz",
                                                 "Ljava/lang/Class;");

第83行:

jobject clazz = (*env)->GetStaticObjectField(env,thisj, SnappyDecompressor_clazz);

第100行至第102行:

LOCK_CLASS(env, clazz, "SnappyDecompressor");
const char* compressed_bytes = (const char*)(*env)->GetDirectBufferAddress(env, compressed_direct_buf);
UNLOCK_CLASS(env, clazz, "SnappyDecompressor");

相关问题