hotspot/src/share/vm/runtime/reflection.cpp
changeset 2332 5c7b6f4ce0a1
parent 1550 be2fc37a817f
child 4571 80b553bddc26
equal deleted inserted replaced
2259:d3c946e7f127 2332:5c7b6f4ce0a1
     1 /*
     1 /*
     2  * Copyright 1997-2008 Sun Microsystems, Inc.  All Rights Reserved.
     2  * Copyright 1997-2009 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   552 
   552 
   553 bool Reflection::is_same_class_package(klassOop class1, klassOop class2) {
   553 bool Reflection::is_same_class_package(klassOop class1, klassOop class2) {
   554   return instanceKlass::cast(class1)->is_same_class_package(class2);
   554   return instanceKlass::cast(class1)->is_same_class_package(class2);
   555 }
   555 }
   556 
   556 
       
   557 bool Reflection::is_same_package_member(klassOop class1, klassOop class2, TRAPS) {
       
   558   return instanceKlass::cast(class1)->is_same_package_member(class2, THREAD);
       
   559 }
       
   560 
   557 
   561 
   558 // Checks that the 'outer' klass has declared 'inner' as being an inner klass. If not,
   562 // Checks that the 'outer' klass has declared 'inner' as being an inner klass. If not,
   559 // throw an incompatible class change exception
   563 // throw an incompatible class change exception
   560 void Reflection::check_for_inner_class(instanceKlassHandle outer, instanceKlassHandle inner, TRAPS) {
   564 // If inner_is_member, require the inner to be a member of the outer.
       
   565 // If !inner_is_member, require the inner to be anonymous (a non-member).
       
   566 // Caller is responsible for figuring out in advance which case must be true.
       
   567 void Reflection::check_for_inner_class(instanceKlassHandle outer, instanceKlassHandle inner,
       
   568                                        bool inner_is_member, TRAPS) {
   561   const int inner_class_info_index = 0;
   569   const int inner_class_info_index = 0;
   562   const int outer_class_info_index = 1;
   570   const int outer_class_info_index = 1;
   563 
   571 
   564   typeArrayHandle    icls (THREAD, outer->inner_classes());
   572   typeArrayHandle    icls (THREAD, outer->inner_classes());
   565   constantPoolHandle cp   (THREAD, outer->constants());
   573   constantPoolHandle cp   (THREAD, outer->constants());
   566   for(int i = 0; i < icls->length(); i += 4) {
   574   for(int i = 0; i < icls->length(); i += 4) {
   567      int ioff = icls->ushort_at(i + inner_class_info_index);
   575      int ioff = icls->ushort_at(i + inner_class_info_index);
   568      int ooff = icls->ushort_at(i + outer_class_info_index);
   576      int ooff = icls->ushort_at(i + outer_class_info_index);
   569 
   577 
   570      if (ioff != 0 && ooff != 0) {
   578      if (inner_is_member && ioff != 0 && ooff != 0) {
   571         klassOop o = cp->klass_at(ooff, CHECK);
   579         klassOop o = cp->klass_at(ooff, CHECK);
   572         if (o == outer()) {
   580         if (o == outer()) {
   573           klassOop i = cp->klass_at(ioff, CHECK);
   581           klassOop i = cp->klass_at(ioff, CHECK);
   574           if (i == inner()) {
   582           if (i == inner()) {
   575             return;
   583             return;
   576           }
   584           }
       
   585         }
       
   586      }
       
   587      if (!inner_is_member && ioff != 0 && ooff == 0 &&
       
   588          cp->klass_name_at_matches(inner, ioff)) {
       
   589         klassOop i = cp->klass_at(ioff, CHECK);
       
   590         if (i == inner()) {
       
   591           return;
   577         }
   592         }
   578      }
   593      }
   579   }
   594   }
   580 
   595 
   581   // 'inner' not declared as an inner klass in outer
   596   // 'inner' not declared as an inner klass in outer