/* Read and handle the "BootstrapMethods" attribute. Return 0 if OK. */ static int jcf_parse_bootstrap_methods (JCF* jcf, int attribute_length ATTRIBUTE_UNUSED) { int i; uint16 num_methods = JCF_readu2 (jcf); jcf->bootstrap_methods.count = num_methods; jcf->bootstrap_methods.methods = (bootstrap_method *) ggc_alloc_atomic (num_methods * sizeof (bootstrap_method)); #ifdef HANDLE_START_BOOTSTRAP_METHODS HANDLE_START_BOOTSTRAP_METHODS (jcf, num_methods); #endif for (i = 0; i < num_methods; i++) { unsigned j; bootstrap_method *m = &jcf->bootstrap_methods.methods[i]; m->method_ref = JCF_readu2 (jcf); m->num_arguments = JCF_readu2 (jcf); m->bootstrap_arguments = (unsigned *) ggc_alloc_atomic (m->num_arguments * sizeof (unsigned)); for (j = 0; j < m->num_arguments; j++) m->bootstrap_arguments[j] = JCF_readu2 (jcf); } #ifdef HANDLE_END_BOOTSTRAP_METHODS HANDLE_END_BOOTSTRAP_METHODS (num_methods); #endif return 0; }
static const char * remap_filename (file_prefix_map *maps, const char *filename) { file_prefix_map *map; char *s; const char *name; size_t name_len; for (map = maps; map; map = map->next) if (filename_ncmp (filename, map->old_prefix, map->old_len) == 0) break; if (!map) return filename; name = filename + map->old_len; name_len = strlen (name) + 1; s = (char *) ggc_alloc_atomic (name_len + map->new_len); memcpy (s, map->new_prefix, map->new_len); memcpy (s + map->new_len, name, name_len); return s; }
/* Read and handle the constant pool. Return 0 if OK. Return -2 if a bad cross-reference (index of other constant) was seen. */ static int jcf_parse_constant_pool (JCF* jcf) { int i, n; JPOOL_SIZE (jcf) = (JCF_FILL (jcf, 2), JCF_readu2 (jcf)); jcf->cpool.tags = (uint8 *) ggc_alloc_atomic (JPOOL_SIZE (jcf)); jcf->cpool.data = ggc_alloc_cpool_entry (sizeof (jword) * JPOOL_SIZE (jcf)); jcf->cpool.tags[0] = 0; #ifdef HANDLE_START_CONSTANT_POOL HANDLE_START_CONSTANT_POOL (JPOOL_SIZE (jcf)); #endif for (i = 1; i < (int) JPOOL_SIZE (jcf); i++) { int constant_kind; /* Make sure at least 9 bytes are available. This is enough for all fixed-sized constant pool entries (so we don't need many more JCF_FILL calls below), but is is small enough that we are guaranteed to not hit EOF (in a valid .class file). */ JCF_FILL (jcf, 9); constant_kind = JCF_readu (jcf); jcf->cpool.tags[i] = constant_kind; switch (constant_kind) { case CONSTANT_String: case CONSTANT_Class: jcf->cpool.data[i].w = JCF_readu2 (jcf); break; case CONSTANT_Fieldref: case CONSTANT_Methodref: case CONSTANT_InterfaceMethodref: case CONSTANT_NameAndType: jcf->cpool.data[i].w = JCF_readu2 (jcf); jcf->cpool.data[i].w |= JCF_readu2 (jcf) << 16; break; case CONSTANT_Integer: case CONSTANT_Float: jcf->cpool.data[i].w = JCF_readu4 (jcf); break; case CONSTANT_Long: case CONSTANT_Double: jcf->cpool.data[i].w = JCF_readu4 (jcf); i++; /* These take up two spots in the constant pool */ jcf->cpool.tags[i] = 0; jcf->cpool.data[i].w = JCF_readu4 (jcf); break; case CONSTANT_Utf8: n = JCF_readu2 (jcf); JCF_FILL (jcf, n); #ifdef HANDLE_CONSTANT_Utf8 HANDLE_CONSTANT_Utf8(jcf, i, n); #else jcf->cpool.data[i].w = JCF_TELL(jcf) - 2; JCF_SKIP (jcf, n); #endif break; case CONSTANT_MethodHandle: jcf->cpool.data[i].w = JCF_readu (jcf); jcf->cpool.data[i].w |= JCF_readu2 (jcf) << 16; break; case CONSTANT_MethodType: jcf->cpool.data[i].w = JCF_readu2 (jcf); break; case CONSTANT_InvokeDynamic: jcf->cpool.data[i].w = JCF_readu2 (jcf); jcf->cpool.data[i].w |= JCF_readu2 (jcf) << 16; break; default: return i; } } return 0; }
static void * stringpool_ggc_alloc (size_t x) { return ggc_alloc_atomic (x); }