src/share/vm/classfile/stackMapTableFormat.hpp

Mon, 25 Jun 2012 21:33:35 -0400

author
coleenp
date
Mon, 25 Jun 2012 21:33:35 -0400
changeset 3875
246d977b51f2
parent 2314
f95d63e2154a
child 3992
4ee06e614636
permissions
-rw-r--r--

7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
Summary: Cannot delete _buckets and HashtableEntries in shared space (CDS)
Reviewed-by: acorn, kvn, dlong, dcubed, kamg

     1 /*
     2  * Copyright (c) 2010, 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  *
    23  */
    25 #ifndef SHARE_VM_CLASSFILE_STACKMAPTABLEFORMAT_HPP
    26 #define SHARE_VM_CLASSFILE_STACKMAPTABLEFORMAT_HPP
    28 #include "classfile/verificationType.hpp"
    30 // These classes represent the stack-map substructures described in the JVMS
    31 // (hence the non-conforming naming scheme).
    33 // These classes work with the types in their compressed form in-place (as they
    34 // would appear in the classfile).  No virtual methods or fields allowed.
    36 class verification_type_info {
    37  private:
    38   // u1 tag
    39   // u2 cpool_index || u2 bci (for ITEM_Object & ITEM_Uninitailized only)
    41   address tag_addr() const { return (address)this; }
    42   address cpool_index_addr() const { return tag_addr() + sizeof(u1); }
    43   address bci_addr() const { return cpool_index_addr(); }
    45  protected:
    46   // No constructors  - should be 'private', but GCC issues a warning if it is
    47   verification_type_info() {}
    48   verification_type_info(const verification_type_info&) {}
    50  public:
    52   static verification_type_info* at(address addr) {
    53     return (verification_type_info*)addr;
    54   }
    56   static verification_type_info* create_at(address addr, u1 tag) {
    57     verification_type_info* vti = (verification_type_info*)addr;
    58     vti->set_tag(tag);
    59     return vti;
    60   }
    62   static verification_type_info* create_object_at(address addr, u2 cp_idx) {
    63     verification_type_info* vti = (verification_type_info*)addr;
    64     vti->set_tag(ITEM_Object);
    65     vti->set_cpool_index(cp_idx);
    66     return vti;
    67   }
    69   static verification_type_info* create_uninit_at(address addr, u2 bci) {
    70     verification_type_info* vti = (verification_type_info*)addr;
    71     vti->set_tag(ITEM_Uninitialized);
    72     vti->set_bci(bci);
    73     return vti;
    74   }
    76   static size_t calculate_size(u1 tag) {
    77     if (tag == ITEM_Object || tag == ITEM_Uninitialized) {
    78       return sizeof(u1) + sizeof(u2);
    79     } else {
    80       return sizeof(u1);
    81     }
    82   }
    84   static size_t max_size() { return sizeof(u1) + sizeof(u2); }
    86   u1 tag() const { return *(u1*)tag_addr(); }
    87   void set_tag(u1 tag) { *((u1*)tag_addr()) = tag; }
    89   bool is_object() const { return tag() == ITEM_Object; }
    90   bool is_uninitialized() const { return tag() == ITEM_Uninitialized; }
    92   u2 cpool_index() const {
    93     assert(is_object(), "This type has no cp_index");
    94     return Bytes::get_Java_u2(cpool_index_addr());
    95   }
    96   void set_cpool_index(u2 idx) {
    97     assert(is_object(), "This type has no cp_index");
    98     Bytes::put_Java_u2(cpool_index_addr(), idx);
    99   }
   101   u2 bci() const {
   102     assert(is_uninitialized(), "This type has no bci");
   103     return Bytes::get_Java_u2(bci_addr());
   104   }
   106   void set_bci(u2 bci) {
   107     assert(is_uninitialized(), "This type has no bci");
   108     Bytes::put_Java_u2(bci_addr(), bci);
   109   }
   111   void copy_from(verification_type_info* from) {
   112     set_tag(from->tag());
   113     if (from->is_object()) {
   114       set_cpool_index(from->cpool_index());
   115     } else if (from->is_uninitialized()) {
   116       set_bci(from->bci());
   117     }
   118   }
   120   size_t size() const {
   121     return calculate_size(tag());
   122   }
   124   verification_type_info* next() {
   125     return (verification_type_info*)((address)this + size());
   126   }
   128   // This method is used when reading unverified data in order to ensure
   129   // that we don't read past a particular memory limit.  It returns false
   130   // if any part of the data structure is outside the specified memory bounds.
   131   bool verify(address start, address end) {
   132     return ((address)this >= start &&
   133             (address)this < end &&
   134             (bci_addr() + sizeof(u2) <= end ||
   135                 !is_object() && !is_uninitialized()));
   136   }
   138 #ifdef ASSERT
   139   void print_on(outputStream* st) {
   140     switch (tag()) {
   141       case ITEM_Top: st->print("Top"); break;
   142       case ITEM_Integer: st->print("Integer"); break;
   143       case ITEM_Float: st->print("Float"); break;
   144       case ITEM_Double: st->print("Double"); break;
   145       case ITEM_Long: st->print("Long"); break;
   146       case ITEM_Null: st->print("Null"); break;
   147       case ITEM_UninitializedThis:
   148         st->print("UninitializedThis"); break;
   149       case ITEM_Uninitialized:
   150         st->print("Uninitialized[#%d]", bci()); break;
   151       case ITEM_Object:
   152         st->print("Object[#%d]", cpool_index()); break;
   153       default:
   154         assert(false, "Bad verification_type_info");
   155     }
   156   }
   157 #endif
   158 };
   160 #define FOR_EACH_STACKMAP_FRAME_TYPE(macro, arg1, arg2) \
   161   macro(same_frame, arg1, arg2) \
   162   macro(same_frame_extended, arg1, arg2) \
   163   macro(same_frame_1_stack_item_frame, arg1, arg2) \
   164   macro(same_frame_1_stack_item_extended, arg1, arg2) \
   165   macro(chop_frame, arg1, arg2) \
   166   macro(append_frame, arg1, arg2) \
   167   macro(full_frame, arg1, arg2)
   169 #define SM_FORWARD_DECL(type, arg1, arg2) class type;
   170 FOR_EACH_STACKMAP_FRAME_TYPE(SM_FORWARD_DECL, x, x)
   171 #undef SM_FORWARD_DECL
   173 class stack_map_frame {
   174  protected:
   175   address frame_type_addr() const { return (address)this; }
   177   // No constructors  - should be 'private', but GCC issues a warning if it is
   178   stack_map_frame() {}
   179   stack_map_frame(const stack_map_frame&) {}
   181  public:
   183   static stack_map_frame* at(address addr) {
   184     return (stack_map_frame*)addr;
   185   }
   187   stack_map_frame* next() const {
   188     return at((address)this + size());
   189   }
   191   u1 frame_type() const { return *(u1*)frame_type_addr(); }
   192   void set_frame_type(u1 type) { *((u1*)frame_type_addr()) = type; }
   194   // pseudo-virtual methods
   195   inline size_t size() const;
   196   inline int offset_delta() const;
   197   inline void set_offset_delta(int offset_delta);
   198   inline int number_of_types() const; // number of types contained in the frame
   199   inline verification_type_info* types() const; // pointer to first type
   200   inline bool is_valid_offset(int offset_delta) const;
   202   // This method must be used when reading unverified data in order to ensure
   203   // that we don't read past a particular memory limit.  It returns false
   204   // if any part of the data structure is outside the specified memory bounds.
   205   inline bool verify(address start, address end) const;
   206 #ifdef ASSERT
   207   inline void print_on(outputStream* st) const;
   208 #endif
   210   // Create as_xxx and is_xxx methods for the subtypes
   211 #define FRAME_TYPE_DECL(stackmap_frame_type, arg1, arg2) \
   212   inline stackmap_frame_type* as_##stackmap_frame_type() const; \
   213   bool is_##stackmap_frame_type() { \
   214     return as_##stackmap_frame_type() != NULL; \
   215   }
   217   FOR_EACH_STACKMAP_FRAME_TYPE(FRAME_TYPE_DECL, x, x)
   218 #undef FRAME_TYPE_DECL
   219 };
   221 class same_frame : public stack_map_frame {
   222  private:
   223   static int frame_type_to_offset_delta(u1 frame_type) {
   224       return frame_type + 1; }
   225   static u1 offset_delta_to_frame_type(int offset_delta) {
   226       return (u1)(offset_delta - 1); }
   228  public:
   230   static bool is_frame_type(u1 tag) {
   231     return tag < 64;
   232   }
   234   static same_frame* at(address addr) {
   235     assert(is_frame_type(*addr), "Wrong frame id");
   236     return (same_frame*)addr;
   237   }
   239   static same_frame* create_at(address addr, int offset_delta) {
   240     same_frame* sm = (same_frame*)addr;
   241     sm->set_offset_delta(offset_delta);
   242     return sm;
   243   }
   245   static size_t calculate_size() { return sizeof(u1); }
   247   size_t size() const { return calculate_size(); }
   248   int offset_delta() const { return frame_type_to_offset_delta(frame_type()); }
   250   void set_offset_delta(int offset_delta) {
   251     assert(offset_delta <= 64, "Offset too large for same_frame");
   252     set_frame_type(offset_delta_to_frame_type(offset_delta));
   253   }
   255   int number_of_types() const { return 0; }
   256   verification_type_info* types() const { return NULL; }
   258   bool is_valid_offset(int offset_delta) const {
   259     return is_frame_type(offset_delta_to_frame_type(offset_delta));
   260   }
   262   bool verify_subtype(address start, address end) const {
   263     return true;
   264   }
   266 #ifdef ASSERT
   267   void print_on(outputStream* st) const {
   268     st->print("same_frame(%d)", offset_delta());
   269   }
   270 #endif
   271 };
   273 class same_frame_extended : public stack_map_frame {
   274  private:
   275   enum { _frame_id = 251 };
   276   address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); }
   278  public:
   279   static bool is_frame_type(u1 tag) {
   280     return tag == _frame_id;
   281   }
   283   static same_frame_extended* at(address addr) {
   284     assert(is_frame_type(*addr), "Wrong frame type");
   285     return (same_frame_extended*)addr;
   286   }
   288   static same_frame_extended* create_at(address addr, u2 offset_delta) {
   289     same_frame_extended* sm = (same_frame_extended*)addr;
   290     sm->set_frame_type(_frame_id);
   291     sm->set_offset_delta(offset_delta);
   292     return sm;
   293   }
   295   static size_t calculate_size() { return sizeof(u1) + sizeof(u2); }
   297   size_t size() const { return calculate_size(); }
   298   int offset_delta() const {
   299     return Bytes::get_Java_u2(offset_delta_addr()) + 1;
   300   }
   302   void set_offset_delta(int offset_delta) {
   303     Bytes::put_Java_u2(offset_delta_addr(), offset_delta - 1);
   304   }
   306   int number_of_types() const { return 0; }
   307   verification_type_info* types() const { return NULL; }
   308   bool is_valid_offset(int offset) const { return true; }
   310   bool verify_subtype(address start, address end) const {
   311     return frame_type_addr() + size() <= end;
   312   }
   314 #ifdef ASSERT
   315   void print_on(outputStream* st) const {
   316     st->print("same_frame_extended(%d)", offset_delta());
   317   }
   318 #endif
   319 };
   321 class same_frame_1_stack_item_frame : public stack_map_frame {
   322  private:
   323   address type_addr() const { return frame_type_addr() + sizeof(u1); }
   325   static int frame_type_to_offset_delta(u1 frame_type) {
   326       return frame_type - 63; }
   327   static u1 offset_delta_to_frame_type(int offset_delta) {
   328       return (u1)(offset_delta + 63); }
   330  public:
   331   static bool is_frame_type(u1 tag) {
   332     return tag >= 64 && tag < 128;
   333   }
   335   static same_frame_1_stack_item_frame* at(address addr) {
   336     assert(is_frame_type(*addr), "Wrong frame id");
   337     return (same_frame_1_stack_item_frame*)addr;
   338   }
   340   static same_frame_1_stack_item_frame* create_at(
   341       address addr, int offset_delta, verification_type_info* vti) {
   342     same_frame_1_stack_item_frame* sm = (same_frame_1_stack_item_frame*)addr;
   343     sm->set_offset_delta(offset_delta);
   344     if (vti != NULL) {
   345       sm->set_type(vti);
   346     }
   347     return sm;
   348   }
   350   static size_t calculate_size(verification_type_info* vti) {
   351     return sizeof(u1) + vti->size();
   352   }
   354   static size_t max_size() {
   355     return sizeof(u1) + verification_type_info::max_size();
   356   }
   358   size_t size() const { return calculate_size(types()); }
   359   int offset_delta() const { return frame_type_to_offset_delta(frame_type()); }
   361   void set_offset_delta(int offset_delta) {
   362     assert(offset_delta > 0 && offset_delta <= 64,
   363            "Offset too large for this frame type");
   364     set_frame_type(offset_delta_to_frame_type(offset_delta));
   365   }
   367   void set_type(verification_type_info* vti) {
   368     verification_type_info* cur = types();
   369     cur->copy_from(vti);
   370   }
   372   int number_of_types() const { return 1; }
   373   verification_type_info* types() const {
   374     return verification_type_info::at(type_addr());
   375   }
   377   bool is_valid_offset(int offset_delta) const {
   378     return is_frame_type(offset_delta_to_frame_type(offset_delta));
   379   }
   381   bool verify_subtype(address start, address end) const {
   382     return types()->verify(start, end);
   383   }
   385 #ifdef ASSERT
   386   void print_on(outputStream* st) const {
   387     st->print("same_frame_1_stack_item_frame(%d,", offset_delta());
   388     types()->print_on(st);
   389     st->print(")");
   390   }
   391 #endif
   392 };
   394 class same_frame_1_stack_item_extended : public stack_map_frame {
   395  private:
   396   address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); }
   397   address type_addr() const { return offset_delta_addr() + sizeof(u2); }
   399   enum { _frame_id = 247 };
   401  public:
   402   static bool is_frame_type(u1 tag) {
   403     return tag == _frame_id;
   404   }
   406   static same_frame_1_stack_item_extended* at(address addr) {
   407     assert(is_frame_type(*addr), "Wrong frame id");
   408     return (same_frame_1_stack_item_extended*)addr;
   409   }
   411   static same_frame_1_stack_item_extended* create_at(
   412       address addr, int offset_delta, verification_type_info* vti) {
   413     same_frame_1_stack_item_extended* sm =
   414        (same_frame_1_stack_item_extended*)addr;
   415     sm->set_frame_type(_frame_id);
   416     sm->set_offset_delta(offset_delta);
   417     if (vti != NULL) {
   418       sm->set_type(vti);
   419     }
   420     return sm;
   421   }
   423   static size_t calculate_size(verification_type_info* vti) {
   424     return sizeof(u1) + sizeof(u2) + vti->size();
   425   }
   427   size_t size() const { return calculate_size(types()); }
   428   int offset_delta() const {
   429     return Bytes::get_Java_u2(offset_delta_addr()) + 1;
   430   }
   432   void set_offset_delta(int offset_delta) {
   433     Bytes::put_Java_u2(offset_delta_addr(), offset_delta - 1);
   434   }
   436   void set_type(verification_type_info* vti) {
   437     verification_type_info* cur = types();
   438     cur->copy_from(vti);
   439   }
   441   int number_of_types() const { return 1; }
   442   verification_type_info* types() const {
   443     return verification_type_info::at(type_addr());
   444   }
   445   bool is_valid_offset(int offset) { return true; }
   447   bool verify_subtype(address start, address end) const {
   448     return type_addr() < end && types()->verify(start, end);
   449   }
   451 #ifdef ASSERT
   452   void print_on(outputStream* st) const {
   453     st->print("same_frame_1_stack_item_extended(%d,", offset_delta());
   454     types()->print_on(st);
   455     st->print(")");
   456   }
   457 #endif
   458 };
   460 class chop_frame : public stack_map_frame {
   461  private:
   462   address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); }
   464   static int frame_type_to_chops(u1 frame_type) {
   465     int chop = 251 - frame_type;
   466     return chop;
   467   }
   469   static u1 chops_to_frame_type(int chop) {
   470     return 251 - chop;
   471   }
   473  public:
   474   static bool is_frame_type(u1 tag) {
   475     return frame_type_to_chops(tag) > 0 && frame_type_to_chops(tag) < 4;
   476   }
   478   static chop_frame* at(address addr) {
   479     assert(is_frame_type(*addr), "Wrong frame id");
   480     return (chop_frame*)addr;
   481   }
   483   static chop_frame* create_at(address addr, int offset_delta, int chops) {
   484     chop_frame* sm = (chop_frame*)addr;
   485     sm->set_chops(chops);
   486     sm->set_offset_delta(offset_delta);
   487     return sm;
   488   }
   490   static size_t calculate_size() {
   491     return sizeof(u1) + sizeof(u2);
   492   }
   494   size_t size() const { return calculate_size(); }
   495   int offset_delta() const {
   496     return Bytes::get_Java_u2(offset_delta_addr()) + 1;
   497   }
   498   void set_offset_delta(int offset_delta) {
   499     Bytes::put_Java_u2(offset_delta_addr(), offset_delta - 1);
   500   }
   502   int chops() const {
   503     int chops = frame_type_to_chops(frame_type());
   504     assert(chops > 0 && chops < 4, "Invalid number of chops in frame");
   505     return chops;
   506   }
   507   void set_chops(int chops) {
   508     assert(chops > 0 && chops <= 3, "Bad number of chops");
   509     set_frame_type(chops_to_frame_type(chops));
   510   }
   512   int number_of_types() const { return 0; }
   513   verification_type_info* types() const { return NULL; }
   514   bool is_valid_offset(int offset) { return true; }
   516   bool verify_subtype(address start, address end) const {
   517     return frame_type_addr() + size() <= end;
   518   }
   520 #ifdef ASSERT
   521   void print_on(outputStream* st) const {
   522     st->print("chop_frame(%d,%d)", offset_delta(), chops());
   523   }
   524 #endif
   525 };
   527 class append_frame : public stack_map_frame {
   528  private:
   529   address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); }
   530   address types_addr() const { return offset_delta_addr() + sizeof(u2); }
   532   static int frame_type_to_appends(u1 frame_type) {
   533     int append = frame_type - 251;
   534     return append;
   535   }
   537   static u1 appends_to_frame_type(int appends) {
   538     assert(appends > 0 && appends < 4, "Invalid append amount");
   539     return 251 + appends;
   540   }
   542  public:
   543   static bool is_frame_type(u1 tag) {
   544     return frame_type_to_appends(tag) > 0 && frame_type_to_appends(tag) < 4;
   545   }
   547   static append_frame* at(address addr) {
   548     assert(is_frame_type(*addr), "Wrong frame id");
   549     return (append_frame*)addr;
   550   }
   552   static append_frame* create_at(
   553       address addr, int offset_delta, int appends,
   554       verification_type_info* types) {
   555     append_frame* sm = (append_frame*)addr;
   556     sm->set_appends(appends);
   557     sm->set_offset_delta(offset_delta);
   558     if (types != NULL) {
   559       verification_type_info* cur = sm->types();
   560       for (int i = 0; i < appends; ++i) {
   561         cur->copy_from(types);
   562         cur = cur->next();
   563         types = types->next();
   564       }
   565     }
   566     return sm;
   567   }
   569   static size_t calculate_size(int appends, verification_type_info* types) {
   570     size_t sz = sizeof(u1) + sizeof(u2);
   571     for (int i = 0; i < appends; ++i) {
   572       sz += types->size();
   573       types = types->next();
   574     }
   575     return sz;
   576   }
   578   static size_t max_size() {
   579     return sizeof(u1) + sizeof(u2) + 3 * verification_type_info::max_size();
   580   }
   582   size_t size() const { return calculate_size(number_of_types(), types()); }
   583   int offset_delta() const {
   584     return Bytes::get_Java_u2(offset_delta_addr()) + 1;
   585   }
   587   void set_offset_delta(int offset_delta) {
   588     Bytes::put_Java_u2(offset_delta_addr(), offset_delta - 1);
   589   }
   591   void set_appends(int appends) {
   592     assert(appends > 0 && appends < 4, "Bad number of appends");
   593     set_frame_type(appends_to_frame_type(appends));
   594   }
   596   int number_of_types() const {
   597     int appends = frame_type_to_appends(frame_type());
   598     assert(appends > 0 && appends < 4, "Invalid number of appends in frame");
   599     return appends;
   600   }
   601   verification_type_info* types() const {
   602     return verification_type_info::at(types_addr());
   603   }
   604   bool is_valid_offset(int offset) const { return true; }
   606   bool verify_subtype(address start, address end) const {
   607     verification_type_info* vti = types();
   608     if ((address)vti < end && vti->verify(start, end)) {
   609       int nof = number_of_types();
   610       vti = vti->next();
   611       if (nof < 2 || vti->verify(start, end)) {
   612         vti = vti->next();
   613         if (nof < 3 || vti->verify(start, end)) {
   614           return true;
   615         }
   616       }
   617     }
   618     return false;
   619   }
   621 #ifdef ASSERT
   622   void print_on(outputStream* st) const {
   623     st->print("append_frame(%d,", offset_delta());
   624     verification_type_info* vti = types();
   625     for (int i = 0; i < number_of_types(); ++i) {
   626       vti->print_on(st);
   627       if (i != number_of_types() - 1) {
   628         st->print(",");
   629       }
   630       vti = vti->next();
   631     }
   632     st->print(")");
   633   }
   634 #endif
   635 };
   637 class full_frame : public stack_map_frame {
   638  private:
   639   address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); }
   640   address num_locals_addr() const { return offset_delta_addr() + sizeof(u2); }
   641   address locals_addr() const { return num_locals_addr() + sizeof(u2); }
   642   address stack_slots_addr(address end_of_locals) const {
   643       return end_of_locals; }
   644   address stack_addr(address end_of_locals) const {
   645       return stack_slots_addr(end_of_locals) + sizeof(u2); }
   647   enum { _frame_id = 255 };
   649  public:
   650   static bool is_frame_type(u1 tag) {
   651     return tag == _frame_id;
   652   }
   654   static full_frame* at(address addr) {
   655     assert(is_frame_type(*addr), "Wrong frame id");
   656     return (full_frame*)addr;
   657   }
   659   static full_frame* create_at(
   660       address addr, int offset_delta, int num_locals,
   661       verification_type_info* locals,
   662       int stack_slots, verification_type_info* stack) {
   663     full_frame* sm = (full_frame*)addr;
   664     sm->set_frame_type(_frame_id);
   665     sm->set_offset_delta(offset_delta);
   666     sm->set_num_locals(num_locals);
   667     if (locals != NULL) {
   668       verification_type_info* cur = sm->locals();
   669       for (int i = 0; i < num_locals; ++i) {
   670         cur->copy_from(locals);
   671         cur = cur->next();
   672         locals = locals->next();
   673       }
   674       address end_of_locals = (address)cur;
   675       sm->set_stack_slots(end_of_locals, stack_slots);
   676       cur = sm->stack(end_of_locals);
   677       for (int i = 0; i < stack_slots; ++i) {
   678         cur->copy_from(stack);
   679         cur = cur->next();
   680         stack = stack->next();
   681       }
   682     }
   683     return sm;
   684   }
   686   static size_t calculate_size(
   687       int num_locals, verification_type_info* locals,
   688       int stack_slots, verification_type_info* stack) {
   689     size_t sz = sizeof(u1) + sizeof(u2) + sizeof(u2) + sizeof(u2);
   690     verification_type_info* vti = locals;
   691     for (int i = 0; i < num_locals; ++i) {
   692       sz += vti->size();
   693       vti = vti->next();
   694     }
   695     vti = stack;
   696     for (int i = 0; i < stack_slots; ++i) {
   697       sz += vti->size();
   698       vti = vti->next();
   699     }
   700     return sz;
   701   }
   703   static size_t max_size(int locals, int stack) {
   704     return sizeof(u1) + 3 * sizeof(u2) +
   705         (locals + stack) * verification_type_info::max_size();
   706   }
   708   size_t size() const {
   709     address eol = end_of_locals();
   710     return calculate_size(num_locals(), locals(), stack_slots(eol), stack(eol));
   711   }
   713   int offset_delta() const {
   714     return Bytes::get_Java_u2(offset_delta_addr()) + 1;
   715   }
   716   int num_locals() const { return Bytes::get_Java_u2(num_locals_addr()); }
   717   verification_type_info* locals() const {
   718     return verification_type_info::at(locals_addr());
   719   }
   720   address end_of_locals() const {
   721     verification_type_info* vti = locals();
   722     for (int i = 0; i < num_locals(); ++i) {
   723       vti = vti->next();
   724     }
   725     return (address)vti;
   726   }
   727   int stack_slots(address end_of_locals) const {
   728     return Bytes::get_Java_u2(stack_slots_addr(end_of_locals));
   729   }
   730   verification_type_info* stack(address end_of_locals) const {
   731     return verification_type_info::at(stack_addr(end_of_locals));
   732   }
   734   void set_offset_delta(int offset_delta) {
   735     Bytes::put_Java_u2(offset_delta_addr(), offset_delta - 1);
   736   }
   737   void set_num_locals(int num_locals) {
   738     Bytes::put_Java_u2(num_locals_addr(), num_locals);
   739   }
   740   void set_stack_slots(address end_of_locals, int stack_slots) {
   741     Bytes::put_Java_u2(stack_slots_addr(end_of_locals), stack_slots);
   742   }
   744   // These return only the locals.  Extra processing is required for stack
   745   // types of full frames.
   746   int number_of_types() const { return num_locals(); }
   747   verification_type_info* types() const { return locals(); }
   748   bool is_valid_offset(int offset) { return true; }
   750   bool verify_subtype(address start, address end) const {
   751     verification_type_info* vti = types();
   752     if ((address)vti >= end) {
   753       return false;
   754     }
   755     int count = number_of_types();
   756     for (int i = 0; i < count; ++i) {
   757       if (!vti->verify(start, end)) {
   758         return false;
   759       }
   760       vti = vti->next();
   761     }
   762     address eol = (address)vti;
   763     if (eol + sizeof(u2) > end) {
   764       return false;
   765     }
   766     count = stack_slots(eol);
   767     vti = stack(eol);
   768     for (int i = 0; i < stack_slots(eol); ++i) {
   769       if (!vti->verify(start, end)) {
   770         return false;
   771       }
   772       vti = vti->next();
   773     }
   774     return true;
   775   }
   777 #ifdef ASSERT
   778   void print_on(outputStream* st) const {
   779     st->print("full_frame(%d,{", offset_delta());
   780     verification_type_info* vti = locals();
   781     for (int i = 0; i < num_locals(); ++i) {
   782       vti->print_on(st);
   783       if (i != num_locals() - 1) {
   784         st->print(",");
   785       }
   786       vti = vti->next();
   787     }
   788     st->print("},{");
   789     address end_of_locals = (address)vti;
   790     vti = stack(end_of_locals);
   791     int ss = stack_slots(end_of_locals);
   792     for (int i = 0; i < ss; ++i) {
   793       vti->print_on(st);
   794       if (i != ss - 1) {
   795         st->print(",");
   796       }
   797       vti = vti->next();
   798     }
   799     st->print("})");
   800   }
   801 #endif
   802 };
   804 #define VIRTUAL_DISPATCH(stack_frame_type, func_name, args) \
   805   stack_frame_type* item_##stack_frame_type = as_##stack_frame_type(); \
   806   if (item_##stack_frame_type != NULL) { \
   807     return item_##stack_frame_type->func_name args;  \
   808   }
   810 #define VOID_VIRTUAL_DISPATCH(stack_frame_type, func_name, args) \
   811   stack_frame_type* item_##stack_frame_type = as_##stack_frame_type(); \
   812   if (item_##stack_frame_type != NULL) { \
   813     item_##stack_frame_type->func_name args;  \
   814     return; \
   815   }
   817 size_t stack_map_frame::size() const {
   818   FOR_EACH_STACKMAP_FRAME_TYPE(VIRTUAL_DISPATCH, size, ());
   819   return 0;
   820 }
   822 int stack_map_frame::offset_delta() const {
   823   FOR_EACH_STACKMAP_FRAME_TYPE(VIRTUAL_DISPATCH, offset_delta, ());
   824   return 0;
   825 }
   827 void stack_map_frame::set_offset_delta(int offset_delta) {
   828   FOR_EACH_STACKMAP_FRAME_TYPE(
   829       VOID_VIRTUAL_DISPATCH, set_offset_delta, (offset_delta));
   830 }
   832 int stack_map_frame::number_of_types() const {
   833   FOR_EACH_STACKMAP_FRAME_TYPE(VIRTUAL_DISPATCH, number_of_types, ());
   834   return 0;
   835 }
   837 verification_type_info* stack_map_frame::types() const {
   838   FOR_EACH_STACKMAP_FRAME_TYPE(VIRTUAL_DISPATCH, types, ());
   839   return NULL;
   840 }
   842 bool stack_map_frame::is_valid_offset(int offset) const {
   843   FOR_EACH_STACKMAP_FRAME_TYPE(VIRTUAL_DISPATCH, is_valid_offset, (offset));
   844   return true;
   845 }
   847 bool stack_map_frame::verify(address start, address end) const {
   848   if (frame_type_addr() >= start && frame_type_addr() < end) {
   849     FOR_EACH_STACKMAP_FRAME_TYPE(
   850        VIRTUAL_DISPATCH, verify_subtype, (start, end));
   851   }
   852   return false;
   853 }
   855 #ifdef ASSERT
   856 void stack_map_frame::print_on(outputStream* st) const {
   857   FOR_EACH_STACKMAP_FRAME_TYPE(VOID_VIRTUAL_DISPATCH, print_on, (st));
   858 }
   859 #endif
   861 #undef VIRTUAL_DISPATCH
   862 #undef VOID_VIRTUAL_DISPATCH
   864 #define AS_SUBTYPE_DEF(stack_frame_type, arg1, arg2) \
   865 stack_frame_type* stack_map_frame::as_##stack_frame_type() const { \
   866   if (stack_frame_type::is_frame_type(frame_type())) { \
   867     return (stack_frame_type*)this; \
   868   } else { \
   869     return NULL; \
   870   } \
   871 }
   873 FOR_EACH_STACKMAP_FRAME_TYPE(AS_SUBTYPE_DEF, x, x)
   874 #undef AS_SUBTYPE_DEF
   876 class stack_map_table_attribute {
   877  private:
   878   address name_index_addr() const {
   879       return (address)this; }
   880   address attribute_length_addr() const {
   881       return name_index_addr() + sizeof(u2); }
   882   address number_of_entries_addr() const {
   883       return attribute_length_addr() + sizeof(u4); }
   884   address entries_addr() const {
   885       return number_of_entries_addr() + sizeof(u2); }
   887  protected:
   888   // No constructors  - should be 'private', but GCC issues a warning if it is
   889   stack_map_table_attribute() {}
   890   stack_map_table_attribute(const stack_map_table_attribute&) {}
   892  public:
   894   static stack_map_table_attribute* at(address addr) {
   895     return (stack_map_table_attribute*)addr;
   896   }
   898   u2 name_index() const {
   899        return Bytes::get_Java_u2(name_index_addr()); }
   900   u4 attribute_length() const {
   901       return Bytes::get_Java_u4(attribute_length_addr()); }
   902   u2 number_of_entries() const {
   903       return Bytes::get_Java_u2(number_of_entries_addr()); }
   904   stack_map_frame* entries() const {
   905     return stack_map_frame::at(entries_addr());
   906   }
   908   static size_t header_size() {
   909       return sizeof(u2) + sizeof(u4);
   910   }
   912   void set_name_index(u2 idx) {
   913     Bytes::put_Java_u2(name_index_addr(), idx);
   914   }
   915   void set_attribute_length(u4 len) {
   916     Bytes::put_Java_u4(attribute_length_addr(), len);
   917   }
   918   void set_number_of_entries(u2 num) {
   919     Bytes::put_Java_u2(number_of_entries_addr(), num);
   920   }
   921 };
   923 #endif // SHARE_VM_CLASSFILE_STACKMAPTABLEFORMAT_HPP

mercurial