< prev index next >

src/hotspot/share/classfile/klassFactory.cpp

Print this page




  66     JvmtiExport::post_class_file_load_hook(class_name,
  67                                            class_loader,
  68                                            protection_domain,
  69                                            &ptr,
  70                                            &end_ptr,
  71                                            &cached_class_file);
  72     if (old_ptr != ptr) {
  73       // JVMTI agent has modified class file data.
  74       // Set new class file stream using JVMTI agent modified class file data.
  75       ClassLoaderData* loader_data =
  76         ClassLoaderData::class_loader_data(class_loader());
  77       int path_index = ik->shared_classpath_index();
  78       ClassFileStream* stream = new ClassFileStream(ptr,
  79                                                     end_ptr - ptr,
  80                                                     cfs->source(),
  81                                                     ClassFileStream::verify);
  82       ClassFileParser parser(stream,
  83                              class_name,
  84                              loader_data,
  85                              protection_domain,
  86                              NULL,
  87                              NULL,


  88                              ClassFileParser::BROADCAST, // publicity level
  89                              CHECK_NULL);
  90       InstanceKlass* new_ik = parser.create_instance_klass(true /* changed_by_loadhook */,


  91                                                            CHECK_NULL);

  92       if (cached_class_file != NULL) {
  93         new_ik->set_cached_class_file(cached_class_file);
  94       }
  95 
  96       if (class_loader.is_null()) {
  97         ResourceMark rm;
  98         ClassLoader::add_package(class_name->as_C_string(), path_index, THREAD);
  99       }
 100 
 101       return new_ik;
 102     }
 103   }
 104 #endif
 105 
 106   return NULL;
 107 }
 108 
 109 
 110 static ClassFileStream* check_class_file_load_hook(ClassFileStream* stream,
 111                                                    Symbol* name,


 149                                            &end_ptr,
 150                                            cached_class_file);
 151 
 152     if (ptr != stream->buffer()) {
 153       // JVMTI agent has modified class file data.
 154       // Set new class file stream using JVMTI agent modified class file data.
 155       stream = new ClassFileStream(ptr,
 156                                    end_ptr - ptr,
 157                                    stream->source(),
 158                                    stream->need_verify());
 159     }
 160   }
 161 
 162   return stream;
 163 }
 164 
 165 
 166 InstanceKlass* KlassFactory::create_from_stream(ClassFileStream* stream,
 167                                                 Symbol* name,
 168                                                 ClassLoaderData* loader_data,
 169                                                 Handle protection_domain,
 170                                                 const InstanceKlass* unsafe_anonymous_host,
 171                                                 GrowableArray<Handle>* cp_patches,
 172                                                 TRAPS) {
 173   assert(stream != NULL, "invariant");
 174   assert(loader_data != NULL, "invariant");
 175   assert(THREAD->is_Java_thread(), "must be a JavaThread");
 176 
 177   ResourceMark rm;
 178   HandleMark hm;
 179 
 180   JvmtiCachedClassFileData* cached_class_file = NULL;
 181 
 182   ClassFileStream* old_stream = stream;
 183 
 184   // increment counter
 185   THREAD->statistical_info().incr_define_class_count();
 186 
 187   // Skip this processing for VM anonymous classes
 188   if (unsafe_anonymous_host == NULL) {



 189     stream = check_class_file_load_hook(stream,
 190                                         name,
 191                                         loader_data,
 192                                         protection_domain,
 193                                         &cached_class_file,
 194                                         CHECK_NULL);
 195   }
 196 
 197   ClassFileParser parser(stream,
 198                          name,
 199                          loader_data,
 200                          protection_domain,
 201                          unsafe_anonymous_host,
 202                          cp_patches,


 203                          ClassFileParser::BROADCAST, // publicity level
 204                          CHECK_NULL);
 205 
 206   InstanceKlass* result = parser.create_instance_klass(old_stream != stream, CHECK_NULL);
 207   assert(result == parser.create_instance_klass(old_stream != stream, THREAD), "invariant");





 208 
 209   if (result == NULL) {
 210     return NULL;
 211   }
 212 
 213   if (cached_class_file != NULL) {
 214     // JVMTI: we have an InstanceKlass now, tell it about the cached bytes
 215     result->set_cached_class_file(cached_class_file);
 216   }
 217 
 218   JFR_ONLY(ON_KLASS_CREATION(result, parser, THREAD);)
 219 
 220 #if INCLUDE_CDS
 221   if (Arguments::is_dumping_archive()) {
 222     ClassLoader::record_result(result, stream, THREAD);
 223   }
 224 #endif // INCLUDE_CDS
 225 
 226   return result;
 227 }


  66     JvmtiExport::post_class_file_load_hook(class_name,
  67                                            class_loader,
  68                                            protection_domain,
  69                                            &ptr,
  70                                            &end_ptr,
  71                                            &cached_class_file);
  72     if (old_ptr != ptr) {
  73       // JVMTI agent has modified class file data.
  74       // Set new class file stream using JVMTI agent modified class file data.
  75       ClassLoaderData* loader_data =
  76         ClassLoaderData::class_loader_data(class_loader());
  77       int path_index = ik->shared_classpath_index();
  78       ClassFileStream* stream = new ClassFileStream(ptr,
  79                                                     end_ptr - ptr,
  80                                                     cfs->source(),
  81                                                     ClassFileStream::verify);
  82       ClassFileParser parser(stream,
  83                              class_name,
  84                              loader_data,
  85                              protection_domain,
  86                              NULL,  // unsafe_anonymous_host
  87                              NULL,  // cp_patches
  88                              false, // is_hidden
  89                              false, // can_access_vm_annotations
  90                              ClassFileParser::BROADCAST, // publicity level
  91                              CHECK_NULL);
  92       ClassInstanceInfo cl_inst_info;
  93       InstanceKlass* new_ik = parser.create_instance_klass(true, // changed_by_loadhook
  94                                                            cl_inst_info,  // dynamic_nest_host and classData
  95                                                            CHECK_NULL);
  96 
  97       if (cached_class_file != NULL) {
  98         new_ik->set_cached_class_file(cached_class_file);
  99       }
 100 
 101       if (class_loader.is_null()) {
 102         ResourceMark rm;
 103         ClassLoader::add_package(class_name->as_C_string(), path_index, THREAD);
 104       }
 105 
 106       return new_ik;
 107     }
 108   }
 109 #endif
 110 
 111   return NULL;
 112 }
 113 
 114 
 115 static ClassFileStream* check_class_file_load_hook(ClassFileStream* stream,
 116                                                    Symbol* name,


 154                                            &end_ptr,
 155                                            cached_class_file);
 156 
 157     if (ptr != stream->buffer()) {
 158       // JVMTI agent has modified class file data.
 159       // Set new class file stream using JVMTI agent modified class file data.
 160       stream = new ClassFileStream(ptr,
 161                                    end_ptr - ptr,
 162                                    stream->source(),
 163                                    stream->need_verify());
 164     }
 165   }
 166 
 167   return stream;
 168 }
 169 
 170 
 171 InstanceKlass* KlassFactory::create_from_stream(ClassFileStream* stream,
 172                                                 Symbol* name,
 173                                                 ClassLoaderData* loader_data,
 174                                                 const ClassLoadInfo& cl_info,


 175                                                 TRAPS) {
 176   assert(stream != NULL, "invariant");
 177   assert(loader_data != NULL, "invariant");
 178   assert(THREAD->is_Java_thread(), "must be a JavaThread");
 179 
 180   ResourceMark rm;
 181   HandleMark hm;
 182 
 183   JvmtiCachedClassFileData* cached_class_file = NULL;
 184 
 185   ClassFileStream* old_stream = stream;
 186 
 187   // increment counter
 188   THREAD->statistical_info().incr_define_class_count();
 189 
 190   assert(!(cl_info.is_hidden() && (cl_info.unsafe_anonymous_host() != NULL)),
 191          "hidden class has an anonymous host");
 192 
 193   // Skip this processing for VM hidden or anonymous classes
 194   if (!cl_info.is_hidden() && (cl_info.unsafe_anonymous_host() == NULL)) {
 195     stream = check_class_file_load_hook(stream,
 196                                         name,
 197                                         loader_data,
 198                                         cl_info.protection_domain(),
 199                                         &cached_class_file,
 200                                         CHECK_NULL);
 201   }
 202 
 203   ClassFileParser parser(stream,
 204                          name,
 205                          loader_data,
 206                          cl_info.protection_domain(),
 207                          cl_info.unsafe_anonymous_host(),
 208                          cl_info.cp_patches(),
 209                          cl_info.is_hidden(),
 210                          cl_info.can_access_vm_annotations(),
 211                          ClassFileParser::BROADCAST, // publicity level
 212                          CHECK_NULL);
 213 
 214   const ClassInstanceInfo* cl_inst_info = cl_info.class_hidden_info_ptr();
 215   InstanceKlass* result = parser.create_instance_klass(old_stream != stream, *cl_inst_info, CHECK_NULL);
 216 #ifdef ASSERT
 217   // Need a NULL dynamic_nest_host here otherwise set_nest_host() may assert.
 218   ClassInstanceInfo cl_inst_info_null(NULL, cl_inst_info->class_data());
 219   assert(result == parser.create_instance_klass(old_stream != stream, cl_inst_info_null, THREAD), "invariant");
 220 #endif
 221 
 222   if (result == NULL) {
 223     return NULL;
 224   }
 225 
 226   if (cached_class_file != NULL) {
 227     // JVMTI: we have an InstanceKlass now, tell it about the cached bytes
 228     result->set_cached_class_file(cached_class_file);
 229   }
 230 
 231   JFR_ONLY(ON_KLASS_CREATION(result, parser, THREAD);)
 232 
 233 #if INCLUDE_CDS
 234   if (Arguments::is_dumping_archive()) {
 235     ClassLoader::record_result(result, stream, THREAD);
 236   }
 237 #endif // INCLUDE_CDS
 238 
 239   return result;
 240 }
< prev index next >