src/share/vm/prims/jni.cpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2011, 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  *


 361 DT_RETURN_MARK_DECL(DefineClass, jclass);
 362 #else /* USDT2 */
 363 DT_RETURN_MARK_DECL(DefineClass, jclass
 364                     , HOTSPOT_JNI_DEFINECLASS_RETURN(_ret_ref));
 365 #endif /* USDT2 */
 366 
 367 JNI_ENTRY(jclass, jni_DefineClass(JNIEnv *env, const char *name, jobject loaderRef,
 368                                   const jbyte *buf, jsize bufLen))
 369   JNIWrapper("DefineClass");
 370 
 371 #ifndef USDT2
 372   DTRACE_PROBE5(hotspot_jni, DefineClass__entry,
 373     env, name, loaderRef, buf, bufLen);
 374 #else /* USDT2 */
 375   HOTSPOT_JNI_DEFINECLASS_ENTRY(
 376     env, (char*) name, loaderRef, (char*) buf, bufLen);
 377 #endif /* USDT2 */
 378   jclass cls = NULL;
 379   DT_RETURN_MARK(DefineClass, jclass, (const jclass&)cls);
 380 

 381   // Since exceptions can be thrown, class initialization can take place
 382   // if name is NULL no check for class name in .class stream has to be made.
 383   if (name != NULL) {
 384     const int str_len = (int)strlen(name);
 385     if (str_len > Symbol::max_length()) {
 386       // It's impossible to create this class;  the name cannot fit
 387       // into the constant pool.
 388       THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name);
 389     }

 390   }
 391   TempNewSymbol class_name = SymbolTable::new_symbol(name, THREAD);
 392 
 393   ResourceMark rm(THREAD);
 394   ClassFileStream st((u1*) buf, bufLen, NULL);
 395   Handle class_loader (THREAD, JNIHandles::resolve(loaderRef));
 396 
 397   if (UsePerfData && !class_loader.is_null()) {
 398     // check whether the current caller thread holds the lock or not.
 399     // If not, increment the corresponding counter
 400     if (ObjectSynchronizer::
 401         query_lock_ownership((JavaThread*)THREAD, class_loader) !=
 402         ObjectSynchronizer::owner_self) {
 403       ClassLoader::sync_JNIDefineClassLockFreeCounter()->inc();
 404     }
 405   }
 406   klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
 407                                                      Handle(), &st, true,
 408                                                      CHECK_NULL);
 409 
 410   if (TraceClassResolution && k != NULL) {
 411     trace_class_resolution(k);
 412   }


   1 /*
   2  * Copyright (c) 1997, 2012, 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  *


 361 DT_RETURN_MARK_DECL(DefineClass, jclass);
 362 #else /* USDT2 */
 363 DT_RETURN_MARK_DECL(DefineClass, jclass
 364                     , HOTSPOT_JNI_DEFINECLASS_RETURN(_ret_ref));
 365 #endif /* USDT2 */
 366 
 367 JNI_ENTRY(jclass, jni_DefineClass(JNIEnv *env, const char *name, jobject loaderRef,
 368                                   const jbyte *buf, jsize bufLen))
 369   JNIWrapper("DefineClass");
 370 
 371 #ifndef USDT2
 372   DTRACE_PROBE5(hotspot_jni, DefineClass__entry,
 373     env, name, loaderRef, buf, bufLen);
 374 #else /* USDT2 */
 375   HOTSPOT_JNI_DEFINECLASS_ENTRY(
 376     env, (char*) name, loaderRef, (char*) buf, bufLen);
 377 #endif /* USDT2 */
 378   jclass cls = NULL;
 379   DT_RETURN_MARK(DefineClass, jclass, (const jclass&)cls);
 380 
 381   TempNewSymbol class_name = NULL;
 382   // Since exceptions can be thrown, class initialization can take place
 383   // if name is NULL no check for class name in .class stream has to be made.
 384   if (name != NULL) {
 385     const int str_len = (int)strlen(name);
 386     if (str_len > Symbol::max_length()) {
 387       // It's impossible to create this class;  the name cannot fit
 388       // into the constant pool.
 389       THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name);
 390     }
 391     class_name = SymbolTable::new_symbol(name, CHECK_NULL);
 392   }


 393   ResourceMark rm(THREAD);
 394   ClassFileStream st((u1*) buf, bufLen, NULL);
 395   Handle class_loader (THREAD, JNIHandles::resolve(loaderRef));
 396 
 397   if (UsePerfData && !class_loader.is_null()) {
 398     // check whether the current caller thread holds the lock or not.
 399     // If not, increment the corresponding counter
 400     if (ObjectSynchronizer::
 401         query_lock_ownership((JavaThread*)THREAD, class_loader) !=
 402         ObjectSynchronizer::owner_self) {
 403       ClassLoader::sync_JNIDefineClassLockFreeCounter()->inc();
 404     }
 405   }
 406   klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
 407                                                      Handle(), &st, true,
 408                                                      CHECK_NULL);
 409 
 410   if (TraceClassResolution && k != NULL) {
 411     trace_class_resolution(k);
 412   }