Top


定義場所(file name)

jdk/src/share/native/java/lang/ClassLoader.c

名前(function name)

JNIEXPORT jclass JNICALL
Java_java_lang_ClassLoader_defineClass2(JNIEnv *env,
                                        jobject loader,
                                        jstring name,
                                        jobject data,
                                        jint offset,
                                        jint length,
                                        jobject pd,
                                        jstring source)
{

本体部(body)

  {- -------------------------------------------
  (1) (変数宣言など)
      ---------------------------------------- -}

        jbyte *body;
        char *utfName;
        jclass result = 0;
        char buf[128];
        char* utfSource;
        char sourceBuf[1024];

  {- -------------------------------------------
  (1) (assert)
      ---------------------------------------- -}

        assert(data != NULL); // caller fails if data is null.
        assert(length >= 0);  // caller passes ByteBuffer.remaining() for length, so never neg.
        // caller passes ByteBuffer.position() for offset, and capacity() >= position() + remaining()
        assert((*env)->GetDirectBufferCapacity(env, data) >= (offset + length));

  {- -------------------------------------------
  (1) 作業用のバッファの確保.
      (なお, 確保できなかった場合は NullPointerException)
      ---------------------------------------- -}

        body = (*env)->GetDirectBufferAddress(env, data);

        if (body == 0) {
            JNU_ThrowNullPointerException(env, 0);
            return 0;
        }

        body += offset;

  {- -------------------------------------------
  (1) utfName 局所変数を初期化
      (なお, 確保できなかった場合は OutOfMemoryError)
      ---------------------------------------- -}

        if (name != NULL) {
            utfName = getUTF(env, name, buf, sizeof(buf));
            if (utfName == NULL) {
                JNU_ThrowOutOfMemoryError(env, NULL);
                return result;
            }
            VerifyFixClassname(utfName);
        } else {
            utfName = NULL;
        }

  {- -------------------------------------------
  (1) utfSource 局所変数を初期化
      (なお, 確保できなかった場合は OutOfMemoryError)
      ---------------------------------------- -}

        if (source != NULL) {
            utfSource = getUTF(env, source, sourceBuf, sizeof(sourceBuf));
            if (utfSource == NULL) {
                JNU_ThrowOutOfMemoryError(env, NULL);
                goto free_utfName;
            }
        } else {
            utfSource = NULL;
        }

  {- -------------------------------------------
  (1) JVM_DefineClassWithSource() を呼んで, クラスのロード処理を行う.
      ---------------------------------------- -}

        result = JVM_DefineClassWithSource(env, utfName, loader, body, length, pd, utfSource);

  {- -------------------------------------------
  (1) 確保したメモリを解放しておく.
      ---------------------------------------- -}

        if (utfSource && utfSource != sourceBuf)
            free(utfSource);

     free_utfName:
        if (utfName && utfName != buf)
            free(utfName);

  {- -------------------------------------------
  (1) 結果をリターン
      ---------------------------------------- -}

        return result;
    }

This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.