Sat, 16 Mar 2013 21:44:52 -0700
Merge
1.1 --- a/.hgtags Fri Mar 15 22:07:42 2013 -0700 1.2 +++ b/.hgtags Sat Mar 16 21:44:52 2013 -0700 1.3 @@ -322,3 +322,5 @@ 1.4 df5396524152118535c36da5801d828b560d19a2 hs25-b21 1.5 4a198b201f3ce84433fa94a3ca65d061473e7c4c jdk8-b80 1.6 dd6350b4abc4a6c19c89dd982cc0e4f3d119885c hs25-b22 1.7 +65b797426a3bec6e91b64085a0cfb94adadb634a jdk8-b81 1.8 +0631ebcc45f05c73b09a56c2586685af1f781c1d hs25-b23
2.1 --- a/agent/src/os/linux/ps_core.c Fri Mar 15 22:07:42 2013 -0700 2.2 +++ b/agent/src/os/linux/ps_core.c Sat Mar 16 21:44:52 2013 -0700 2.3 @@ -132,12 +132,12 @@ 2.4 } 2.5 2.6 // Part of the class sharing workaround 2.7 -static map_info* add_class_share_map_info(struct ps_prochandle* ph, off_t offset, 2.8 +static void add_class_share_map_info(struct ps_prochandle* ph, off_t offset, 2.9 uintptr_t vaddr, size_t memsz) { 2.10 map_info* map; 2.11 if ((map = allocate_init_map(ph->core->classes_jsa_fd, 2.12 offset, vaddr, memsz)) == NULL) { 2.13 - return NULL; 2.14 + return; 2.15 } 2.16 2.17 map->next = ph->core->class_share_maps;
3.1 --- a/make/bsd/makefiles/gcc.make Fri Mar 15 22:07:42 2013 -0700 3.2 +++ b/make/bsd/makefiles/gcc.make Sat Mar 16 21:44:52 2013 -0700 3.3 @@ -168,12 +168,12 @@ 3.4 # conversions which might affect the values. To avoid that, we need to turn 3.5 # it off explicitly. 3.6 ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0" 3.7 -ACCEPTABLE_WARNINGS = -Wpointer-arith -Wsign-compare 3.8 +WARNING_FLAGS = -Wpointer-arith -Wsign-compare -Wundef 3.9 else 3.10 -ACCEPTABLE_WARNINGS = -Wpointer-arith -Wconversion -Wsign-compare 3.11 +WARNING_FLAGS = -Wpointer-arith -Wconversion -Wsign-compare -Wundef 3.12 endif 3.13 3.14 -CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(ACCEPTABLE_WARNINGS) 3.15 +CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(WARNING_FLAGS) 3.16 # Special cases 3.17 CFLAGS_WARN/BYFILE = $(CFLAGS_WARN/$@)$(CFLAGS_WARN/DEFAULT$(CFLAGS_WARN/$@)) 3.18 # XXXDARWIN: for _dyld_bind_fully_image_containing_address
4.1 --- a/make/excludeSrc.make Fri Mar 15 22:07:42 2013 -0700 4.2 +++ b/make/excludeSrc.make Sat Mar 16 21:44:52 2013 -0700 4.3 @@ -69,7 +69,7 @@ 4.4 CXXFLAGS += -DINCLUDE_CDS=0 4.5 CFLAGS += -DINCLUDE_CDS=0 4.6 4.7 - Src_Files_EXCLUDE += metaspaceShared.cpp 4.8 + Src_Files_EXCLUDE += filemap.cpp metaspaceShared.cpp 4.9 endif 4.10 4.11 ifeq ($(INCLUDE_ALL_GCS), false)
5.1 --- a/make/hotspot_version Fri Mar 15 22:07:42 2013 -0700 5.2 +++ b/make/hotspot_version Sat Mar 16 21:44:52 2013 -0700 5.3 @@ -35,7 +35,7 @@ 5.4 5.5 HS_MAJOR_VER=25 5.6 HS_MINOR_VER=0 5.7 -HS_BUILD_NUMBER=23 5.8 +HS_BUILD_NUMBER=24 5.9 5.10 JDK_MAJOR_VER=1 5.11 JDK_MINOR_VER=8
6.1 --- a/make/linux/makefiles/gcc.make Fri Mar 15 22:07:42 2013 -0700 6.2 +++ b/make/linux/makefiles/gcc.make Sat Mar 16 21:44:52 2013 -0700 6.3 @@ -131,12 +131,12 @@ 6.4 # conversions which might affect the values. To avoid that, we need to turn 6.5 # it off explicitly. 6.6 ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0" 6.7 -ACCEPTABLE_WARNINGS = -Wpointer-arith -Wsign-compare 6.8 +WARNING_FLAGS = -Wpointer-arith -Wsign-compare -Wundef 6.9 else 6.10 -ACCEPTABLE_WARNINGS = -Wpointer-arith -Wconversion -Wsign-compare 6.11 +WARNING_FLAGS = -Wpointer-arith -Wconversion -Wsign-compare -Wundef 6.12 endif 6.13 6.14 -CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(ACCEPTABLE_WARNINGS) 6.15 +CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(WARNING_FLAGS) 6.16 # Special cases 6.17 CFLAGS_WARN/BYFILE = $(CFLAGS_WARN/$@)$(CFLAGS_WARN/DEFAULT$(CFLAGS_WARN/$@)) 6.18
7.1 --- a/make/solaris/makefiles/gcc.make Fri Mar 15 22:07:42 2013 -0700 7.2 +++ b/make/solaris/makefiles/gcc.make Sat Mar 16 21:44:52 2013 -0700 7.3 @@ -118,8 +118,8 @@ 7.4 # Compiler warnings are treated as errors 7.5 WARNINGS_ARE_ERRORS = -Werror 7.6 # Enable these warnings. See 'info gcc' about details on these options 7.7 -ADDITIONAL_WARNINGS = -Wpointer-arith -Wconversion -Wsign-compare 7.8 -CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(ADDITIONAL_WARNINGS) 7.9 +WARNING_FLAGS = -Wpointer-arith -Wconversion -Wsign-compare -Wundef 7.10 +CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(WARNING_FLAGS) 7.11 # Special cases 7.12 CFLAGS_WARN/BYFILE = $(CFLAGS_WARN/$@)$(CFLAGS_WARN/DEFAULT$(CFLAGS_WARN/$@)) 7.13
8.1 --- a/src/cpu/x86/vm/frame_x86.cpp Fri Mar 15 22:07:42 2013 -0700 8.2 +++ b/src/cpu/x86/vm/frame_x86.cpp Sat Mar 16 21:44:52 2013 -0700 8.3 @@ -356,7 +356,7 @@ 8.4 // Verifies the calculated original PC of a deoptimization PC for the 8.5 // given unextended SP. The unextended SP might also be the saved SP 8.6 // for MethodHandle call sites. 8.7 -#if ASSERT 8.8 +#ifdef ASSERT 8.9 void frame::verify_deopt_original_pc(nmethod* nm, intptr_t* unextended_sp, bool is_method_handle_return) { 8.10 frame fr; 8.11
9.1 --- a/src/cpu/x86/vm/frame_x86.hpp Fri Mar 15 22:07:42 2013 -0700 9.2 +++ b/src/cpu/x86/vm/frame_x86.hpp Sat Mar 16 21:44:52 2013 -0700 9.3 @@ -170,7 +170,7 @@ 9.4 return (intptr_t*) addr_at(offset); 9.5 } 9.6 9.7 -#if ASSERT 9.8 +#ifdef ASSERT 9.9 // Used in frame::sender_for_{interpreter,compiled}_frame 9.10 static void verify_deopt_original_pc( nmethod* nm, intptr_t* unextended_sp, bool is_method_handle_return = false); 9.11 static void verify_deopt_mh_original_pc(nmethod* nm, intptr_t* unextended_sp) {
10.1 --- a/src/cpu/x86/vm/frame_x86.inline.hpp Fri Mar 15 22:07:42 2013 -0700 10.2 +++ b/src/cpu/x86/vm/frame_x86.inline.hpp Sat Mar 16 21:44:52 2013 -0700 10.3 @@ -295,14 +295,18 @@ 10.4 return true; 10.5 } 10.6 10.7 +inline oop frame::saved_oop_result(RegisterMap* map) const { 10.8 + oop* result_adr = (oop *)map->location(rax->as_VMReg()); 10.9 + guarantee(result_adr != NULL, "bad register save location"); 10.10 10.11 - 10.12 -inline oop frame::saved_oop_result(RegisterMap* map) const { 10.13 - return *((oop*) map->location(rax->as_VMReg())); 10.14 + return (*result_adr); 10.15 } 10.16 10.17 inline void frame::set_saved_oop_result(RegisterMap* map, oop obj) { 10.18 - *((oop*) map->location(rax->as_VMReg())) = obj; 10.19 + oop* result_adr = (oop *)map->location(rax->as_VMReg()); 10.20 + guarantee(result_adr != NULL, "bad register save location"); 10.21 + 10.22 + *result_adr = obj; 10.23 } 10.24 10.25 #endif // CPU_X86_VM_FRAME_X86_INLINE_HPP
11.1 --- a/src/os/bsd/vm/os_bsd.cpp Fri Mar 15 22:07:42 2013 -0700 11.2 +++ b/src/os/bsd/vm/os_bsd.cpp Sat Mar 16 21:44:52 2013 -0700 11.3 @@ -57,6 +57,7 @@ 11.4 #include "runtime/threadCritical.hpp" 11.5 #include "runtime/timer.hpp" 11.6 #include "services/attachListener.hpp" 11.7 +#include "services/memTracker.hpp" 11.8 #include "services/runtimeService.hpp" 11.9 #include "utilities/decoder.hpp" 11.10 #include "utilities/defaultStream.hpp" 11.11 @@ -2275,13 +2276,25 @@ 11.12 return NULL; 11.13 } 11.14 11.15 + // The memory is committed 11.16 + address pc = CALLER_PC; 11.17 + MemTracker::record_virtual_memory_reserve((address)addr, bytes, pc); 11.18 + MemTracker::record_virtual_memory_commit((address)addr, bytes, pc); 11.19 + 11.20 return addr; 11.21 } 11.22 11.23 bool os::release_memory_special(char* base, size_t bytes) { 11.24 // detaching the SHM segment will also delete it, see reserve_memory_special() 11.25 int rslt = shmdt(base); 11.26 - return rslt == 0; 11.27 + if (rslt == 0) { 11.28 + MemTracker::record_virtual_memory_uncommit((address)base, bytes); 11.29 + MemTracker::record_virtual_memory_release((address)base, bytes); 11.30 + return true; 11.31 + } else { 11.32 + return false; 11.33 + } 11.34 + 11.35 } 11.36 11.37 size_t os::large_page_size() {
12.1 --- a/src/os/linux/vm/globals_linux.hpp Fri Mar 15 22:07:42 2013 -0700 12.2 +++ b/src/os/linux/vm/globals_linux.hpp Sat Mar 16 21:44:52 2013 -0700 12.3 @@ -1,5 +1,5 @@ 12.4 /* 12.5 - * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. 12.6 + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. 12.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 12.8 * 12.9 * This code is free software; you can redistribute it and/or modify it 12.10 @@ -40,6 +40,9 @@ 12.11 product(bool, UseHugeTLBFS, false, \ 12.12 "Use MAP_HUGETLB for large pages") \ 12.13 \ 12.14 + product(bool, LoadExecStackDllInVMThread, true, \ 12.15 + "Load DLLs with executable-stack attribute in the VM Thread") \ 12.16 + \ 12.17 product(bool, UseSHM, false, \ 12.18 "Use SYSV shared memory for large pages") 12.19
13.1 --- a/src/os/linux/vm/os_linux.cpp Fri Mar 15 22:07:42 2013 -0700 13.2 +++ b/src/os/linux/vm/os_linux.cpp Sat Mar 16 21:44:52 2013 -0700 13.3 @@ -44,6 +44,7 @@ 13.4 #include "runtime/extendedPC.hpp" 13.5 #include "runtime/globals.hpp" 13.6 #include "runtime/interfaceSupport.hpp" 13.7 +#include "runtime/init.hpp" 13.8 #include "runtime/java.hpp" 13.9 #include "runtime/javaCalls.hpp" 13.10 #include "runtime/mutexLocker.hpp" 13.11 @@ -57,10 +58,12 @@ 13.12 #include "runtime/threadCritical.hpp" 13.13 #include "runtime/timer.hpp" 13.14 #include "services/attachListener.hpp" 13.15 +#include "services/memTracker.hpp" 13.16 #include "services/runtimeService.hpp" 13.17 #include "utilities/decoder.hpp" 13.18 #include "utilities/defaultStream.hpp" 13.19 #include "utilities/events.hpp" 13.20 +#include "utilities/elfFile.hpp" 13.21 #include "utilities/growableArray.hpp" 13.22 #include "utilities/vmError.hpp" 13.23 13.24 @@ -1796,9 +1799,93 @@ 13.25 // in case of error it checks if .dll/.so was built for the 13.26 // same architecture as Hotspot is running on 13.27 13.28 + 13.29 +// Remember the stack's state. The Linux dynamic linker will change 13.30 +// the stack to 'executable' at most once, so we must safepoint only once. 13.31 +bool os::Linux::_stack_is_executable = false; 13.32 + 13.33 +// VM operation that loads a library. This is necessary if stack protection 13.34 +// of the Java stacks can be lost during loading the library. If we 13.35 +// do not stop the Java threads, they can stack overflow before the stacks 13.36 +// are protected again. 13.37 +class VM_LinuxDllLoad: public VM_Operation { 13.38 + private: 13.39 + const char *_filename; 13.40 + void *_lib; 13.41 + public: 13.42 + VM_LinuxDllLoad(const char *fn) : 13.43 + _filename(fn), _lib(NULL) {} 13.44 + VMOp_Type type() const { return VMOp_LinuxDllLoad; } 13.45 + void doit() { 13.46 + _lib = os::Linux::dll_load_inner(_filename); 13.47 + os::Linux::_stack_is_executable = true; 13.48 + } 13.49 + void* loaded_library() { return _lib; } 13.50 +}; 13.51 + 13.52 void * os::dll_load(const char *filename, char *ebuf, int ebuflen) 13.53 { 13.54 - void * result= ::dlopen(filename, RTLD_LAZY); 13.55 + void * result = NULL; 13.56 + bool load_attempted = false; 13.57 + 13.58 + // Check whether the library to load might change execution rights 13.59 + // of the stack. If they are changed, the protection of the stack 13.60 + // guard pages will be lost. We need a safepoint to fix this. 13.61 + // 13.62 + // See Linux man page execstack(8) for more info. 13.63 + if (os::uses_stack_guard_pages() && !os::Linux::_stack_is_executable) { 13.64 + ElfFile ef(filename); 13.65 + if (!ef.specifies_noexecstack()) { 13.66 + if (!is_init_completed()) { 13.67 + os::Linux::_stack_is_executable = true; 13.68 + // This is OK - No Java threads have been created yet, and hence no 13.69 + // stack guard pages to fix. 13.70 + // 13.71 + // This should happen only when you are building JDK7 using a very 13.72 + // old version of JDK6 (e.g., with JPRT) and running test_gamma. 13.73 + // 13.74 + // Dynamic loader will make all stacks executable after 13.75 + // this function returns, and will not do that again. 13.76 + assert(Threads::first() == NULL, "no Java threads should exist yet."); 13.77 + } else { 13.78 + warning("You have loaded library %s which might have disabled stack guard. " 13.79 + "The VM will try to fix the stack guard now.\n" 13.80 + "It's highly recommended that you fix the library with " 13.81 + "'execstack -c <libfile>', or link it with '-z noexecstack'.", 13.82 + filename); 13.83 + 13.84 + assert(Thread::current()->is_Java_thread(), "must be Java thread"); 13.85 + JavaThread *jt = JavaThread::current(); 13.86 + if (jt->thread_state() != _thread_in_native) { 13.87 + // This happens when a compiler thread tries to load a hsdis-<arch>.so file 13.88 + // that requires ExecStack. Cannot enter safe point. Let's give up. 13.89 + warning("Unable to fix stack guard. Giving up."); 13.90 + } else { 13.91 + if (!LoadExecStackDllInVMThread) { 13.92 + // This is for the case where the DLL has an static 13.93 + // constructor function that executes JNI code. We cannot 13.94 + // load such DLLs in the VMThread. 13.95 + result = ::dlopen(filename, RTLD_LAZY); 13.96 + } 13.97 + 13.98 + ThreadInVMfromNative tiv(jt); 13.99 + debug_only(VMNativeEntryWrapper vew;) 13.100 + 13.101 + VM_LinuxDllLoad op(filename); 13.102 + VMThread::execute(&op); 13.103 + if (LoadExecStackDllInVMThread) { 13.104 + result = op.loaded_library(); 13.105 + } 13.106 + load_attempted = true; 13.107 + } 13.108 + } 13.109 + } 13.110 + } 13.111 + 13.112 + if (!load_attempted) { 13.113 + result = ::dlopen(filename, RTLD_LAZY); 13.114 + } 13.115 + 13.116 if (result != NULL) { 13.117 // Successful loading 13.118 return result; 13.119 @@ -1952,6 +2039,38 @@ 13.120 return NULL; 13.121 } 13.122 13.123 +void * os::Linux::dll_load_inner(const char *filename) { 13.124 + void * result = NULL; 13.125 + if (LoadExecStackDllInVMThread) { 13.126 + result = ::dlopen(filename, RTLD_LAZY); 13.127 + } 13.128 + 13.129 + // Since 7019808, libjvm.so is linked with -noexecstack. If the VM loads a 13.130 + // library that requires an executable stack, or which does not have this 13.131 + // stack attribute set, dlopen changes the stack attribute to executable. The 13.132 + // read protection of the guard pages gets lost. 13.133 + // 13.134 + // Need to check _stack_is_executable again as multiple VM_LinuxDllLoad 13.135 + // may have been queued at the same time. 13.136 + 13.137 + if (!_stack_is_executable) { 13.138 + JavaThread *jt = Threads::first(); 13.139 + 13.140 + while (jt) { 13.141 + if (!jt->stack_guard_zone_unused() && // Stack not yet fully initialized 13.142 + jt->stack_yellow_zone_enabled()) { // No pending stack overflow exceptions 13.143 + if (!os::guard_memory((char *) jt->stack_red_zone_base() - jt->stack_red_zone_size(), 13.144 + jt->stack_yellow_zone_size() + jt->stack_red_zone_size())) { 13.145 + warning("Attempt to reguard stack yellow zone failed."); 13.146 + } 13.147 + } 13.148 + jt = jt->next(); 13.149 + } 13.150 + } 13.151 + 13.152 + return result; 13.153 +} 13.154 + 13.155 /* 13.156 * glibc-2.0 libdl is not MT safe. If you are building with any glibc, 13.157 * chances are you might want to run the generated bits against glibc-2.0 13.158 @@ -3094,13 +3213,24 @@ 13.159 numa_make_global(addr, bytes); 13.160 } 13.161 13.162 + // The memory is committed 13.163 + address pc = CALLER_PC; 13.164 + MemTracker::record_virtual_memory_reserve((address)addr, bytes, pc); 13.165 + MemTracker::record_virtual_memory_commit((address)addr, bytes, pc); 13.166 + 13.167 return addr; 13.168 } 13.169 13.170 bool os::release_memory_special(char* base, size_t bytes) { 13.171 // detaching the SHM segment will also delete it, see reserve_memory_special() 13.172 int rslt = shmdt(base); 13.173 - return rslt == 0; 13.174 + if (rslt == 0) { 13.175 + MemTracker::record_virtual_memory_uncommit((address)base, bytes); 13.176 + MemTracker::record_virtual_memory_release((address)base, bytes); 13.177 + return true; 13.178 + } else { 13.179 + return false; 13.180 + } 13.181 } 13.182 13.183 size_t os::large_page_size() {
14.1 --- a/src/os/linux/vm/os_linux.hpp Fri Mar 15 22:07:42 2013 -0700 14.2 +++ b/src/os/linux/vm/os_linux.hpp Sat Mar 16 21:44:52 2013 -0700 14.3 @@ -94,6 +94,9 @@ 14.4 static void print_libversion_info(outputStream* st); 14.5 14.6 public: 14.7 + static bool _stack_is_executable; 14.8 + static void *dll_load_inner(const char *name); 14.9 + 14.10 static void init_thread_fpu_state(); 14.11 static int get_fpu_control_word(); 14.12 static void set_fpu_control_word(int fpu_control);
15.1 --- a/src/os/solaris/vm/os_solaris.cpp Fri Mar 15 22:07:42 2013 -0700 15.2 +++ b/src/os/solaris/vm/os_solaris.cpp Sat Mar 16 21:44:52 2013 -0700 15.3 @@ -2945,7 +2945,7 @@ 15.4 while (p < (uint64_t)end) { 15.5 addrs[0] = p; 15.6 size_t addrs_count = 1; 15.7 - while (addrs_count < MAX_MEMINFO_CNT && addrs[addrs_count - 1] < (uint64_t)end) { 15.8 + while (addrs_count < MAX_MEMINFO_CNT && addrs[addrs_count - 1] + page_size < (uint64_t)end) { 15.9 addrs[addrs_count] = addrs[addrs_count - 1] + page_size; 15.10 addrs_count++; 15.11 } 15.12 @@ -3420,13 +3420,25 @@ 15.13 if ((retAddr != NULL) && UseNUMAInterleaving) { 15.14 numa_make_global(retAddr, size); 15.15 } 15.16 + 15.17 + // The memory is committed 15.18 + address pc = CALLER_PC; 15.19 + MemTracker::record_virtual_memory_reserve((address)retAddr, size, pc); 15.20 + MemTracker::record_virtual_memory_commit((address)retAddr, size, pc); 15.21 + 15.22 return retAddr; 15.23 } 15.24 15.25 bool os::release_memory_special(char* base, size_t bytes) { 15.26 // detaching the SHM segment will also delete it, see reserve_memory_special() 15.27 int rslt = shmdt(base); 15.28 - return rslt == 0; 15.29 + if (rslt == 0) { 15.30 + MemTracker::record_virtual_memory_uncommit((address)base, bytes); 15.31 + MemTracker::record_virtual_memory_release((address)base, bytes); 15.32 + return true; 15.33 + } else { 15.34 + return false; 15.35 + } 15.36 } 15.37 15.38 size_t os::large_page_size() {
16.1 --- a/src/os/windows/vm/os_windows.cpp Fri Mar 15 22:07:42 2013 -0700 16.2 +++ b/src/os/windows/vm/os_windows.cpp Sat Mar 16 21:44:52 2013 -0700 16.3 @@ -60,6 +60,7 @@ 16.4 #include "runtime/threadCritical.hpp" 16.5 #include "runtime/timer.hpp" 16.6 #include "services/attachListener.hpp" 16.7 +#include "services/memTracker.hpp" 16.8 #include "services/runtimeService.hpp" 16.9 #include "utilities/decoder.hpp" 16.10 #include "utilities/defaultStream.hpp" 16.11 @@ -2836,7 +2837,7 @@ 16.12 PAGE_READWRITE); 16.13 // If reservation failed, return NULL 16.14 if (p_buf == NULL) return NULL; 16.15 - 16.16 + MemTracker::record_virtual_memory_reserve((address)p_buf, size_of_reserve, CALLER_PC); 16.17 os::release_memory(p_buf, bytes + chunk_size); 16.18 16.19 // we still need to round up to a page boundary (in case we are using large pages) 16.20 @@ -2898,6 +2899,11 @@ 16.21 if (next_alloc_addr > p_buf) { 16.22 // Some memory was committed so release it. 16.23 size_t bytes_to_release = bytes - bytes_remaining; 16.24 + // NMT has yet to record any individual blocks, so it 16.25 + // need to create a dummy 'reserve' record to match 16.26 + // the release. 16.27 + MemTracker::record_virtual_memory_reserve((address)p_buf, 16.28 + bytes_to_release, CALLER_PC); 16.29 os::release_memory(p_buf, bytes_to_release); 16.30 } 16.31 #ifdef ASSERT 16.32 @@ -2909,10 +2915,19 @@ 16.33 #endif 16.34 return NULL; 16.35 } 16.36 + 16.37 bytes_remaining -= bytes_to_rq; 16.38 next_alloc_addr += bytes_to_rq; 16.39 count++; 16.40 } 16.41 + // Although the memory is allocated individually, it is returned as one. 16.42 + // NMT records it as one block. 16.43 + address pc = CALLER_PC; 16.44 + MemTracker::record_virtual_memory_reserve((address)p_buf, bytes, pc); 16.45 + if ((flags & MEM_COMMIT) != 0) { 16.46 + MemTracker::record_virtual_memory_commit((address)p_buf, bytes, pc); 16.47 + } 16.48 + 16.49 // made it this far, success 16.50 return p_buf; 16.51 } 16.52 @@ -3099,11 +3114,20 @@ 16.53 // normal policy just allocate it all at once 16.54 DWORD flag = MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES; 16.55 char * res = (char *)VirtualAlloc(NULL, bytes, flag, prot); 16.56 + if (res != NULL) { 16.57 + address pc = CALLER_PC; 16.58 + MemTracker::record_virtual_memory_reserve((address)res, bytes, pc); 16.59 + MemTracker::record_virtual_memory_commit((address)res, bytes, pc); 16.60 + } 16.61 + 16.62 return res; 16.63 } 16.64 } 16.65 16.66 bool os::release_memory_special(char* base, size_t bytes) { 16.67 + assert(base != NULL, "Sanity check"); 16.68 + // Memory allocated via reserve_memory_special() is committed 16.69 + MemTracker::record_virtual_memory_uncommit((address)base, bytes); 16.70 return release_memory(base, bytes); 16.71 } 16.72
17.1 --- a/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp Fri Mar 15 22:07:42 2013 -0700 17.2 +++ b/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp Sat Mar 16 21:44:52 2013 -0700 17.3 @@ -410,6 +410,11 @@ 17.4 // to handle_unexpected_exception way down below. 17.5 thread->disable_stack_red_zone(); 17.6 tty->print_raw_cr("An irrecoverable stack overflow has occurred."); 17.7 + 17.8 + // This is a likely cause, but hard to verify. Let's just print 17.9 + // it as a hint. 17.10 + tty->print_raw_cr("Please check if any of your loaded .so files has " 17.11 + "enabled executable stack (see man page execstack(8))"); 17.12 } else { 17.13 // Accessing stack address below sp may cause SEGV if current 17.14 // thread has MAP_GROWSDOWN stack. This should only happen when
18.1 --- a/src/os_cpu/linux_x86/vm/os_linux_x86.cpp Fri Mar 15 22:07:42 2013 -0700 18.2 +++ b/src/os_cpu/linux_x86/vm/os_linux_x86.cpp Sat Mar 16 21:44:52 2013 -0700 18.3 @@ -305,6 +305,11 @@ 18.4 // to handle_unexpected_exception way down below. 18.5 thread->disable_stack_red_zone(); 18.6 tty->print_raw_cr("An irrecoverable stack overflow has occurred."); 18.7 + 18.8 + // This is a likely cause, but hard to verify. Let's just print 18.9 + // it as a hint. 18.10 + tty->print_raw_cr("Please check if any of your loaded .so files has " 18.11 + "enabled executable stack (see man page execstack(8))"); 18.12 } else { 18.13 // Accessing stack address below sp may cause SEGV if current 18.14 // thread has MAP_GROWSDOWN stack. This should only happen when 18.15 @@ -335,7 +340,7 @@ 18.16 // here if the underlying file has been truncated. 18.17 // Do not crash the VM in such a case. 18.18 CodeBlob* cb = CodeCache::find_blob_unsafe(pc); 18.19 - nmethod* nm = cb->is_nmethod() ? (nmethod*)cb : NULL; 18.20 + nmethod* nm = (cb != NULL && cb->is_nmethod()) ? (nmethod*)cb : NULL; 18.21 if (nm != NULL && nm->has_unsafe_access()) { 18.22 stub = StubRoutines::handler_for_unsafe_access(); 18.23 }
19.1 --- a/src/share/vm/c1/c1_LIR.hpp Fri Mar 15 22:07:42 2013 -0700 19.2 +++ b/src/share/vm/c1/c1_LIR.hpp Sat Mar 16 21:44:52 2013 -0700 19.3 @@ -2375,7 +2375,7 @@ 19.4 // collects all register operands of the instruction 19.5 void visit(LIR_Op* op); 19.6 19.7 -#if ASSERT 19.8 +#ifdef ASSERT 19.9 // check that an operation has no operands 19.10 bool no_operands(LIR_Op* op); 19.11 #endif
20.1 --- a/src/share/vm/ci/ciTypeFlow.cpp Fri Mar 15 22:07:42 2013 -0700 20.2 +++ b/src/share/vm/ci/ciTypeFlow.cpp Sat Mar 16 21:44:52 2013 -0700 20.3 @@ -2540,7 +2540,7 @@ 20.4 } else if (innermost->head() == blk) { 20.5 // If loop header, complete the tree pointers 20.6 if (blk->loop() != innermost) { 20.7 -#if ASSERT 20.8 +#ifdef ASSERT 20.9 assert(blk->loop()->head() == innermost->head(), "same head"); 20.10 Loop* dl; 20.11 for (dl = innermost; dl != NULL && dl != blk->loop(); dl = dl->parent());
21.1 --- a/src/share/vm/classfile/classFileParser.cpp Fri Mar 15 22:07:42 2013 -0700 21.2 +++ b/src/share/vm/classfile/classFileParser.cpp Sat Mar 16 21:44:52 2013 -0700 21.3 @@ -90,8 +90,7 @@ 21.4 // Extension method support. 21.5 #define JAVA_8_VERSION 52 21.6 21.7 - 21.8 -void ClassFileParser::parse_constant_pool_entries(ClassLoaderData* loader_data, constantPoolHandle cp, int length, TRAPS) { 21.9 +void ClassFileParser::parse_constant_pool_entries(int length, TRAPS) { 21.10 // Use a local copy of ClassFileStream. It helps the C++ compiler to optimize 21.11 // this function (_current can be allocated in a register, with scalar 21.12 // replacement of aggregates). The _current pointer is copied back to 21.13 @@ -104,7 +103,7 @@ 21.14 assert(cfs->allocated_on_stack(),"should be local"); 21.15 u1* old_current = cfs0->current(); 21.16 #endif 21.17 - Handle class_loader(THREAD, loader_data->class_loader()); 21.18 + Handle class_loader(THREAD, _loader_data->class_loader()); 21.19 21.20 // Used for batching symbol allocations. 21.21 const char* names[SymbolTable::symbol_alloc_batch_size]; 21.22 @@ -124,7 +123,7 @@ 21.23 { 21.24 cfs->guarantee_more(3, CHECK); // name_index, tag/access_flags 21.25 u2 name_index = cfs->get_u2_fast(); 21.26 - cp->klass_index_at_put(index, name_index); 21.27 + _cp->klass_index_at_put(index, name_index); 21.28 } 21.29 break; 21.30 case JVM_CONSTANT_Fieldref : 21.31 @@ -132,7 +131,7 @@ 21.32 cfs->guarantee_more(5, CHECK); // class_index, name_and_type_index, tag/access_flags 21.33 u2 class_index = cfs->get_u2_fast(); 21.34 u2 name_and_type_index = cfs->get_u2_fast(); 21.35 - cp->field_at_put(index, class_index, name_and_type_index); 21.36 + _cp->field_at_put(index, class_index, name_and_type_index); 21.37 } 21.38 break; 21.39 case JVM_CONSTANT_Methodref : 21.40 @@ -140,7 +139,7 @@ 21.41 cfs->guarantee_more(5, CHECK); // class_index, name_and_type_index, tag/access_flags 21.42 u2 class_index = cfs->get_u2_fast(); 21.43 u2 name_and_type_index = cfs->get_u2_fast(); 21.44 - cp->method_at_put(index, class_index, name_and_type_index); 21.45 + _cp->method_at_put(index, class_index, name_and_type_index); 21.46 } 21.47 break; 21.48 case JVM_CONSTANT_InterfaceMethodref : 21.49 @@ -148,14 +147,14 @@ 21.50 cfs->guarantee_more(5, CHECK); // class_index, name_and_type_index, tag/access_flags 21.51 u2 class_index = cfs->get_u2_fast(); 21.52 u2 name_and_type_index = cfs->get_u2_fast(); 21.53 - cp->interface_method_at_put(index, class_index, name_and_type_index); 21.54 + _cp->interface_method_at_put(index, class_index, name_and_type_index); 21.55 } 21.56 break; 21.57 case JVM_CONSTANT_String : 21.58 { 21.59 cfs->guarantee_more(3, CHECK); // string_index, tag/access_flags 21.60 u2 string_index = cfs->get_u2_fast(); 21.61 - cp->string_index_at_put(index, string_index); 21.62 + _cp->string_index_at_put(index, string_index); 21.63 } 21.64 break; 21.65 case JVM_CONSTANT_MethodHandle : 21.66 @@ -174,11 +173,11 @@ 21.67 cfs->guarantee_more(4, CHECK); // ref_kind, method_index, tag/access_flags 21.68 u1 ref_kind = cfs->get_u1_fast(); 21.69 u2 method_index = cfs->get_u2_fast(); 21.70 - cp->method_handle_index_at_put(index, ref_kind, method_index); 21.71 + _cp->method_handle_index_at_put(index, ref_kind, method_index); 21.72 } else if (tag == JVM_CONSTANT_MethodType) { 21.73 cfs->guarantee_more(3, CHECK); // signature_index, tag/access_flags 21.74 u2 signature_index = cfs->get_u2_fast(); 21.75 - cp->method_type_index_at_put(index, signature_index); 21.76 + _cp->method_type_index_at_put(index, signature_index); 21.77 } else { 21.78 ShouldNotReachHere(); 21.79 } 21.80 @@ -200,21 +199,21 @@ 21.81 u2 name_and_type_index = cfs->get_u2_fast(); 21.82 if (_max_bootstrap_specifier_index < (int) bootstrap_specifier_index) 21.83 _max_bootstrap_specifier_index = (int) bootstrap_specifier_index; // collect for later 21.84 - cp->invoke_dynamic_at_put(index, bootstrap_specifier_index, name_and_type_index); 21.85 + _cp->invoke_dynamic_at_put(index, bootstrap_specifier_index, name_and_type_index); 21.86 } 21.87 break; 21.88 case JVM_CONSTANT_Integer : 21.89 { 21.90 cfs->guarantee_more(5, CHECK); // bytes, tag/access_flags 21.91 u4 bytes = cfs->get_u4_fast(); 21.92 - cp->int_at_put(index, (jint) bytes); 21.93 + _cp->int_at_put(index, (jint) bytes); 21.94 } 21.95 break; 21.96 case JVM_CONSTANT_Float : 21.97 { 21.98 cfs->guarantee_more(5, CHECK); // bytes, tag/access_flags 21.99 u4 bytes = cfs->get_u4_fast(); 21.100 - cp->float_at_put(index, *(jfloat*)&bytes); 21.101 + _cp->float_at_put(index, *(jfloat*)&bytes); 21.102 } 21.103 break; 21.104 case JVM_CONSTANT_Long : 21.105 @@ -225,7 +224,7 @@ 21.106 { 21.107 cfs->guarantee_more(9, CHECK); // bytes, tag/access_flags 21.108 u8 bytes = cfs->get_u8_fast(); 21.109 - cp->long_at_put(index, bytes); 21.110 + _cp->long_at_put(index, bytes); 21.111 } 21.112 index++; // Skip entry following eigth-byte constant, see JVM book p. 98 21.113 break; 21.114 @@ -237,7 +236,7 @@ 21.115 { 21.116 cfs->guarantee_more(9, CHECK); // bytes, tag/access_flags 21.117 u8 bytes = cfs->get_u8_fast(); 21.118 - cp->double_at_put(index, *(jdouble*)&bytes); 21.119 + _cp->double_at_put(index, *(jdouble*)&bytes); 21.120 } 21.121 index++; // Skip entry following eigth-byte constant, see JVM book p. 98 21.122 break; 21.123 @@ -246,7 +245,7 @@ 21.124 cfs->guarantee_more(5, CHECK); // name_index, signature_index, tag/access_flags 21.125 u2 name_index = cfs->get_u2_fast(); 21.126 u2 signature_index = cfs->get_u2_fast(); 21.127 - cp->name_and_type_at_put(index, name_index, signature_index); 21.128 + _cp->name_and_type_at_put(index, name_index, signature_index); 21.129 } 21.130 break; 21.131 case JVM_CONSTANT_Utf8 : 21.132 @@ -283,11 +282,11 @@ 21.133 indices[names_count] = index; 21.134 hashValues[names_count++] = hash; 21.135 if (names_count == SymbolTable::symbol_alloc_batch_size) { 21.136 - SymbolTable::new_symbols(loader_data, cp, names_count, names, lengths, indices, hashValues, CHECK); 21.137 + SymbolTable::new_symbols(_loader_data, _cp, names_count, names, lengths, indices, hashValues, CHECK); 21.138 names_count = 0; 21.139 } 21.140 } else { 21.141 - cp->symbol_at_put(index, result); 21.142 + _cp->symbol_at_put(index, result); 21.143 } 21.144 } 21.145 break; 21.146 @@ -300,7 +299,7 @@ 21.147 21.148 // Allocate the remaining symbols 21.149 if (names_count > 0) { 21.150 - SymbolTable::new_symbols(loader_data, cp, names_count, names, lengths, indices, hashValues, CHECK); 21.151 + SymbolTable::new_symbols(_loader_data, _cp, names_count, names, lengths, indices, hashValues, CHECK); 21.152 } 21.153 21.154 // Copy _current pointer of local copy back to stream(). 21.155 @@ -310,23 +309,6 @@ 21.156 cfs0->set_current(cfs1.current()); 21.157 } 21.158 21.159 -// This class unreferences constant pool symbols if an error has occurred 21.160 -// while parsing the class before it is assigned into the class. 21.161 -// If it gets an error after that it is unloaded and the constant pool will 21.162 -// be cleaned up then. 21.163 -class ConstantPoolCleaner : public StackObj { 21.164 - constantPoolHandle _cphandle; 21.165 - bool _in_error; 21.166 - public: 21.167 - ConstantPoolCleaner(constantPoolHandle cp) : _cphandle(cp), _in_error(true) {} 21.168 - ~ConstantPoolCleaner() { 21.169 - if (_in_error && _cphandle.not_null()) { 21.170 - _cphandle->unreference_symbols(); 21.171 - } 21.172 - } 21.173 - void set_in_error(bool clean) { _in_error = clean; } 21.174 -}; 21.175 - 21.176 bool inline valid_cp_range(int index, int length) { return (index > 0 && index < length); } 21.177 21.178 inline Symbol* check_symbol_at(constantPoolHandle cp, int index) { 21.179 @@ -336,7 +318,7 @@ 21.180 return NULL; 21.181 } 21.182 21.183 -constantPoolHandle ClassFileParser::parse_constant_pool(ClassLoaderData* loader_data, TRAPS) { 21.184 +constantPoolHandle ClassFileParser::parse_constant_pool(TRAPS) { 21.185 ClassFileStream* cfs = stream(); 21.186 constantPoolHandle nullHandle; 21.187 21.188 @@ -345,16 +327,13 @@ 21.189 guarantee_property( 21.190 length >= 1, "Illegal constant pool size %u in class file %s", 21.191 length, CHECK_(nullHandle)); 21.192 - ConstantPool* constant_pool = 21.193 - ConstantPool::allocate(loader_data, 21.194 - length, 21.195 - CHECK_(nullHandle)); 21.196 + ConstantPool* constant_pool = ConstantPool::allocate(_loader_data, length, 21.197 + CHECK_(nullHandle)); 21.198 + _cp = constant_pool; // save in case of errors 21.199 constantPoolHandle cp (THREAD, constant_pool); 21.200 21.201 - ConstantPoolCleaner cp_in_error(cp); // set constant pool to be cleaned up. 21.202 - 21.203 // parsing constant pool entries 21.204 - parse_constant_pool_entries(loader_data, cp, length, CHECK_(nullHandle)); 21.205 + parse_constant_pool_entries(length, CHECK_(nullHandle)); 21.206 21.207 int index = 1; // declared outside of loops for portability 21.208 21.209 @@ -373,8 +352,7 @@ 21.210 if (!_need_verify) break; 21.211 int klass_ref_index = cp->klass_ref_index_at(index); 21.212 int name_and_type_ref_index = cp->name_and_type_ref_index_at(index); 21.213 - check_property(valid_cp_range(klass_ref_index, length) && 21.214 - is_klass_reference(cp, klass_ref_index), 21.215 + check_property(valid_klass_reference_at(klass_ref_index), 21.216 "Invalid constant pool index %u in class file %s", 21.217 klass_ref_index, 21.218 CHECK_(nullHandle)); 21.219 @@ -404,16 +382,12 @@ 21.220 if (!_need_verify) break; 21.221 int name_ref_index = cp->name_ref_index_at(index); 21.222 int signature_ref_index = cp->signature_ref_index_at(index); 21.223 - check_property( 21.224 - valid_cp_range(name_ref_index, length) && 21.225 - cp->tag_at(name_ref_index).is_utf8(), 21.226 - "Invalid constant pool index %u in class file %s", 21.227 - name_ref_index, CHECK_(nullHandle)); 21.228 - check_property( 21.229 - valid_cp_range(signature_ref_index, length) && 21.230 - cp->tag_at(signature_ref_index).is_utf8(), 21.231 - "Invalid constant pool index %u in class file %s", 21.232 - signature_ref_index, CHECK_(nullHandle)); 21.233 + check_property(valid_symbol_at(name_ref_index), 21.234 + "Invalid constant pool index %u in class file %s", 21.235 + name_ref_index, CHECK_(nullHandle)); 21.236 + check_property(valid_symbol_at(signature_ref_index), 21.237 + "Invalid constant pool index %u in class file %s", 21.238 + signature_ref_index, CHECK_(nullHandle)); 21.239 break; 21.240 } 21.241 case JVM_CONSTANT_Utf8 : 21.242 @@ -425,22 +399,18 @@ 21.243 case JVM_CONSTANT_ClassIndex : 21.244 { 21.245 int class_index = cp->klass_index_at(index); 21.246 - check_property( 21.247 - valid_cp_range(class_index, length) && 21.248 - cp->tag_at(class_index).is_utf8(), 21.249 - "Invalid constant pool index %u in class file %s", 21.250 - class_index, CHECK_(nullHandle)); 21.251 + check_property(valid_symbol_at(class_index), 21.252 + "Invalid constant pool index %u in class file %s", 21.253 + class_index, CHECK_(nullHandle)); 21.254 cp->unresolved_klass_at_put(index, cp->symbol_at(class_index)); 21.255 } 21.256 break; 21.257 case JVM_CONSTANT_StringIndex : 21.258 { 21.259 int string_index = cp->string_index_at(index); 21.260 - check_property( 21.261 - valid_cp_range(string_index, length) && 21.262 - cp->tag_at(string_index).is_utf8(), 21.263 - "Invalid constant pool index %u in class file %s", 21.264 - string_index, CHECK_(nullHandle)); 21.265 + check_property(valid_symbol_at(string_index), 21.266 + "Invalid constant pool index %u in class file %s", 21.267 + string_index, CHECK_(nullHandle)); 21.268 Symbol* sym = cp->symbol_at(string_index); 21.269 cp->unresolved_string_at_put(index, sym); 21.270 } 21.271 @@ -491,12 +461,9 @@ 21.272 case JVM_CONSTANT_MethodType : 21.273 { 21.274 int ref_index = cp->method_type_index_at(index); 21.275 - check_property( 21.276 - valid_cp_range(ref_index, length) && 21.277 - cp->tag_at(ref_index).is_utf8() && 21.278 - EnableInvokeDynamic, 21.279 - "Invalid constant pool index %u in class file %s", 21.280 - ref_index, CHECK_(nullHandle)); 21.281 + check_property(valid_symbol_at(ref_index) && EnableInvokeDynamic, 21.282 + "Invalid constant pool index %u in class file %s", 21.283 + ref_index, CHECK_(nullHandle)); 21.284 } 21.285 break; 21.286 case JVM_CONSTANT_InvokeDynamic : 21.287 @@ -541,7 +508,6 @@ 21.288 } 21.289 21.290 if (!_need_verify) { 21.291 - cp_in_error.set_in_error(false); 21.292 return cp; 21.293 } 21.294 21.295 @@ -664,7 +630,6 @@ 21.296 } // end of switch 21.297 } // end of for 21.298 21.299 - cp_in_error.set_in_error(false); 21.300 return cp; 21.301 } 21.302 21.303 @@ -786,93 +751,92 @@ 21.304 } 21.305 21.306 21.307 -Array<Klass*>* ClassFileParser::parse_interfaces(constantPoolHandle cp, 21.308 - int length, 21.309 - ClassLoaderData* loader_data, 21.310 +Array<Klass*>* ClassFileParser::parse_interfaces(int length, 21.311 Handle protection_domain, 21.312 Symbol* class_name, 21.313 bool* has_default_methods, 21.314 TRAPS) { 21.315 - ClassFileStream* cfs = stream(); 21.316 - assert(length > 0, "only called for length>0"); 21.317 - // FIXME: Leak at later OOM. 21.318 - Array<Klass*>* interfaces = MetadataFactory::new_array<Klass*>(loader_data, length, NULL, CHECK_NULL); 21.319 - 21.320 - int index; 21.321 - for (index = 0; index < length; index++) { 21.322 - u2 interface_index = cfs->get_u2(CHECK_NULL); 21.323 - KlassHandle interf; 21.324 - check_property( 21.325 - valid_cp_range(interface_index, cp->length()) && 21.326 - is_klass_reference(cp, interface_index), 21.327 - "Interface name has bad constant pool index %u in class file %s", 21.328 - interface_index, CHECK_NULL); 21.329 - if (cp->tag_at(interface_index).is_klass()) { 21.330 - interf = KlassHandle(THREAD, cp->resolved_klass_at(interface_index)); 21.331 - } else { 21.332 - Symbol* unresolved_klass = cp->klass_name_at(interface_index); 21.333 - 21.334 - // Don't need to check legal name because it's checked when parsing constant pool. 21.335 - // But need to make sure it's not an array type. 21.336 - guarantee_property(unresolved_klass->byte_at(0) != JVM_SIGNATURE_ARRAY, 21.337 - "Bad interface name in class file %s", CHECK_NULL); 21.338 - Handle class_loader(THREAD, loader_data->class_loader()); 21.339 - 21.340 - // Call resolve_super so classcircularity is checked 21.341 - Klass* k = SystemDictionary::resolve_super_or_fail(class_name, 21.342 - unresolved_klass, class_loader, protection_domain, 21.343 - false, CHECK_NULL); 21.344 - interf = KlassHandle(THREAD, k); 21.345 + if (length == 0) { 21.346 + _local_interfaces = Universe::the_empty_klass_array(); 21.347 + } else { 21.348 + ClassFileStream* cfs = stream(); 21.349 + assert(length > 0, "only called for length>0"); 21.350 + _local_interfaces = MetadataFactory::new_array<Klass*>(_loader_data, length, NULL, CHECK_NULL); 21.351 + 21.352 + int index; 21.353 + for (index = 0; index < length; index++) { 21.354 + u2 interface_index = cfs->get_u2(CHECK_NULL); 21.355 + KlassHandle interf; 21.356 + check_property( 21.357 + valid_klass_reference_at(interface_index), 21.358 + "Interface name has bad constant pool index %u in class file %s", 21.359 + interface_index, CHECK_NULL); 21.360 + if (_cp->tag_at(interface_index).is_klass()) { 21.361 + interf = KlassHandle(THREAD, _cp->resolved_klass_at(interface_index)); 21.362 + } else { 21.363 + Symbol* unresolved_klass = _cp->klass_name_at(interface_index); 21.364 + 21.365 + // Don't need to check legal name because it's checked when parsing constant pool. 21.366 + // But need to make sure it's not an array type. 21.367 + guarantee_property(unresolved_klass->byte_at(0) != JVM_SIGNATURE_ARRAY, 21.368 + "Bad interface name in class file %s", CHECK_NULL); 21.369 + Handle class_loader(THREAD, _loader_data->class_loader()); 21.370 + 21.371 + // Call resolve_super so classcircularity is checked 21.372 + Klass* k = SystemDictionary::resolve_super_or_fail(class_name, 21.373 + unresolved_klass, class_loader, protection_domain, 21.374 + false, CHECK_NULL); 21.375 + interf = KlassHandle(THREAD, k); 21.376 + } 21.377 + 21.378 + if (!interf()->is_interface()) { 21.379 + THROW_MSG_(vmSymbols::java_lang_IncompatibleClassChangeError(), "Implementing class", NULL); 21.380 + } 21.381 + if (InstanceKlass::cast(interf())->has_default_methods()) { 21.382 + *has_default_methods = true; 21.383 + } 21.384 + _local_interfaces->at_put(index, interf()); 21.385 } 21.386 21.387 - if (!interf()->is_interface()) { 21.388 - THROW_MSG_(vmSymbols::java_lang_IncompatibleClassChangeError(), "Implementing class", NULL); 21.389 + if (!_need_verify || length <= 1) { 21.390 + return _local_interfaces; 21.391 } 21.392 - if (InstanceKlass::cast(interf())->has_default_methods()) { 21.393 - *has_default_methods = true; 21.394 - } 21.395 - interfaces->at_put(index, interf()); 21.396 - } 21.397 - 21.398 - if (!_need_verify || length <= 1) { 21.399 - return interfaces; 21.400 - } 21.401 - 21.402 - // Check if there's any duplicates in interfaces 21.403 - ResourceMark rm(THREAD); 21.404 - NameSigHash** interface_names = NEW_RESOURCE_ARRAY_IN_THREAD( 21.405 - THREAD, NameSigHash*, HASH_ROW_SIZE); 21.406 - initialize_hashtable(interface_names); 21.407 - bool dup = false; 21.408 - { 21.409 - debug_only(No_Safepoint_Verifier nsv;) 21.410 - for (index = 0; index < length; index++) { 21.411 - Klass* k = interfaces->at(index); 21.412 - Symbol* name = InstanceKlass::cast(k)->name(); 21.413 - // If no duplicates, add (name, NULL) in hashtable interface_names. 21.414 - if (!put_after_lookup(name, NULL, interface_names)) { 21.415 - dup = true; 21.416 - break; 21.417 + 21.418 + // Check if there's any duplicates in interfaces 21.419 + ResourceMark rm(THREAD); 21.420 + NameSigHash** interface_names = NEW_RESOURCE_ARRAY_IN_THREAD( 21.421 + THREAD, NameSigHash*, HASH_ROW_SIZE); 21.422 + initialize_hashtable(interface_names); 21.423 + bool dup = false; 21.424 + { 21.425 + debug_only(No_Safepoint_Verifier nsv;) 21.426 + for (index = 0; index < length; index++) { 21.427 + Klass* k = _local_interfaces->at(index); 21.428 + Symbol* name = InstanceKlass::cast(k)->name(); 21.429 + // If no duplicates, add (name, NULL) in hashtable interface_names. 21.430 + if (!put_after_lookup(name, NULL, interface_names)) { 21.431 + dup = true; 21.432 + break; 21.433 + } 21.434 } 21.435 } 21.436 + if (dup) { 21.437 + classfile_parse_error("Duplicate interface name in class file %s", CHECK_NULL); 21.438 + } 21.439 } 21.440 - if (dup) { 21.441 - classfile_parse_error("Duplicate interface name in class file %s", CHECK_NULL); 21.442 - } 21.443 - 21.444 - return interfaces; 21.445 + return _local_interfaces; 21.446 } 21.447 21.448 21.449 -void ClassFileParser::verify_constantvalue(int constantvalue_index, int signature_index, constantPoolHandle cp, TRAPS) { 21.450 +void ClassFileParser::verify_constantvalue(int constantvalue_index, int signature_index, TRAPS) { 21.451 // Make sure the constant pool entry is of a type appropriate to this field 21.452 guarantee_property( 21.453 (constantvalue_index > 0 && 21.454 - constantvalue_index < cp->length()), 21.455 + constantvalue_index < _cp->length()), 21.456 "Bad initial value index %u in ConstantValue attribute in class file %s", 21.457 constantvalue_index, CHECK); 21.458 - constantTag value_type = cp->tag_at(constantvalue_index); 21.459 - switch ( cp->basic_type_for_signature_at(signature_index) ) { 21.460 + constantTag value_type = _cp->tag_at(constantvalue_index); 21.461 + switch ( _cp->basic_type_for_signature_at(signature_index) ) { 21.462 case T_LONG: 21.463 guarantee_property(value_type.is_long(), "Inconsistent constant value type in class file %s", CHECK); 21.464 break; 21.465 @@ -886,7 +850,7 @@ 21.466 guarantee_property(value_type.is_int(), "Inconsistent constant value type in class file %s", CHECK); 21.467 break; 21.468 case T_OBJECT: 21.469 - guarantee_property((cp->symbol_at(signature_index)->equals("Ljava/lang/String;") 21.470 + guarantee_property((_cp->symbol_at(signature_index)->equals("Ljava/lang/String;") 21.471 && value_type.is_string()), 21.472 "Bad string initial value in class file %s", CHECK); 21.473 break; 21.474 @@ -899,15 +863,11 @@ 21.475 21.476 21.477 // Parse attributes for a field. 21.478 -void ClassFileParser::parse_field_attributes(ClassLoaderData* loader_data, 21.479 - constantPoolHandle cp, 21.480 - u2 attributes_count, 21.481 +void ClassFileParser::parse_field_attributes(u2 attributes_count, 21.482 bool is_static, u2 signature_index, 21.483 u2* constantvalue_index_addr, 21.484 bool* is_synthetic_addr, 21.485 u2* generic_signature_index_addr, 21.486 - AnnotationArray** field_annotations, 21.487 - AnnotationArray** field_type_annotations, 21.488 ClassFileParser::FieldAnnotationCollector* parsed_annotations, 21.489 TRAPS) { 21.490 ClassFileStream* cfs = stream(); 21.491 @@ -927,12 +887,11 @@ 21.492 cfs->guarantee_more(6, CHECK); // attribute_name_index, attribute_length 21.493 u2 attribute_name_index = cfs->get_u2_fast(); 21.494 u4 attribute_length = cfs->get_u4_fast(); 21.495 - check_property(valid_cp_range(attribute_name_index, cp->length()) && 21.496 - cp->tag_at(attribute_name_index).is_utf8(), 21.497 + check_property(valid_symbol_at(attribute_name_index), 21.498 "Invalid field attribute index %u in class file %s", 21.499 attribute_name_index, 21.500 CHECK); 21.501 - Symbol* attribute_name = cp->symbol_at(attribute_name_index); 21.502 + Symbol* attribute_name = _cp->symbol_at(attribute_name_index); 21.503 if (is_static && attribute_name == vmSymbols::tag_constant_value()) { 21.504 // ignore if non-static 21.505 if (constantvalue_index != 0) { 21.506 @@ -944,7 +903,7 @@ 21.507 attribute_length, CHECK); 21.508 constantvalue_index = cfs->get_u2(CHECK); 21.509 if (_need_verify) { 21.510 - verify_constantvalue(constantvalue_index, signature_index, cp, CHECK); 21.511 + verify_constantvalue(constantvalue_index, signature_index, CHECK); 21.512 } 21.513 } else if (attribute_name == vmSymbols::tag_synthetic()) { 21.514 if (attribute_length != 0) { 21.515 @@ -971,10 +930,8 @@ 21.516 runtime_visible_annotations_length = attribute_length; 21.517 runtime_visible_annotations = cfs->get_u1_buffer(); 21.518 assert(runtime_visible_annotations != NULL, "null visible annotations"); 21.519 - parse_annotations(loader_data, 21.520 - runtime_visible_annotations, 21.521 + parse_annotations(runtime_visible_annotations, 21.522 runtime_visible_annotations_length, 21.523 - cp, 21.524 parsed_annotations, 21.525 CHECK); 21.526 cfs->skip_u1(runtime_visible_annotations_length, CHECK); 21.527 @@ -1004,18 +961,18 @@ 21.528 *constantvalue_index_addr = constantvalue_index; 21.529 *is_synthetic_addr = is_synthetic; 21.530 *generic_signature_index_addr = generic_signature_index; 21.531 - *field_annotations = assemble_annotations(loader_data, 21.532 - runtime_visible_annotations, 21.533 + AnnotationArray* a = assemble_annotations(runtime_visible_annotations, 21.534 runtime_visible_annotations_length, 21.535 runtime_invisible_annotations, 21.536 runtime_invisible_annotations_length, 21.537 CHECK); 21.538 - *field_type_annotations = assemble_annotations(loader_data, 21.539 - runtime_visible_type_annotations, 21.540 - runtime_visible_type_annotations_length, 21.541 - runtime_invisible_type_annotations, 21.542 - runtime_invisible_type_annotations_length, 21.543 - CHECK); 21.544 + parsed_annotations->set_field_annotations(a); 21.545 + a = assemble_annotations(runtime_visible_type_annotations, 21.546 + runtime_visible_type_annotations_length, 21.547 + runtime_invisible_type_annotations, 21.548 + runtime_invisible_type_annotations_length, 21.549 + CHECK); 21.550 + parsed_annotations->set_field_type_annotations(a); 21.551 return; 21.552 } 21.553 21.554 @@ -1106,13 +1063,9 @@ 21.555 } 21.556 }; 21.557 21.558 -Array<u2>* ClassFileParser::parse_fields(ClassLoaderData* loader_data, 21.559 - Symbol* class_name, 21.560 - constantPoolHandle cp, 21.561 +Array<u2>* ClassFileParser::parse_fields(Symbol* class_name, 21.562 bool is_interface, 21.563 FieldAllocationCount *fac, 21.564 - Array<AnnotationArray*>** fields_annotations, 21.565 - Array<AnnotationArray*>** fields_type_annotations, 21.566 u2* java_fields_count_ptr, TRAPS) { 21.567 ClassFileStream* cfs = stream(); 21.568 cfs->guarantee_more(2, CHECK_NULL); // length 21.569 @@ -1147,8 +1100,6 @@ 21.570 u2* fa = NEW_RESOURCE_ARRAY_IN_THREAD( 21.571 THREAD, u2, total_fields * (FieldInfo::field_slots + 1)); 21.572 21.573 - AnnotationArray* field_annotations = NULL; 21.574 - AnnotationArray* field_type_annotations = NULL; 21.575 // The generic signature slots start after all other fields' data. 21.576 int generic_signature_slot = total_fields * FieldInfo::field_slots; 21.577 int num_generic_signature = 0; 21.578 @@ -1161,53 +1112,52 @@ 21.579 access_flags.set_flags(flags); 21.580 21.581 u2 name_index = cfs->get_u2_fast(); 21.582 - int cp_size = cp->length(); 21.583 - check_property( 21.584 - valid_cp_range(name_index, cp_size) && cp->tag_at(name_index).is_utf8(), 21.585 + int cp_size = _cp->length(); 21.586 + check_property(valid_symbol_at(name_index), 21.587 "Invalid constant pool index %u for field name in class file %s", 21.588 - name_index, CHECK_NULL); 21.589 - Symbol* name = cp->symbol_at(name_index); 21.590 + name_index, 21.591 + CHECK_NULL); 21.592 + Symbol* name = _cp->symbol_at(name_index); 21.593 verify_legal_field_name(name, CHECK_NULL); 21.594 21.595 u2 signature_index = cfs->get_u2_fast(); 21.596 - check_property( 21.597 - valid_cp_range(signature_index, cp_size) && 21.598 - cp->tag_at(signature_index).is_utf8(), 21.599 + check_property(valid_symbol_at(signature_index), 21.600 "Invalid constant pool index %u for field signature in class file %s", 21.601 signature_index, CHECK_NULL); 21.602 - Symbol* sig = cp->symbol_at(signature_index); 21.603 + Symbol* sig = _cp->symbol_at(signature_index); 21.604 verify_legal_field_signature(name, sig, CHECK_NULL); 21.605 21.606 u2 constantvalue_index = 0; 21.607 bool is_synthetic = false; 21.608 u2 generic_signature_index = 0; 21.609 bool is_static = access_flags.is_static(); 21.610 - FieldAnnotationCollector parsed_annotations; 21.611 + FieldAnnotationCollector parsed_annotations(_loader_data); 21.612 21.613 u2 attributes_count = cfs->get_u2_fast(); 21.614 if (attributes_count > 0) { 21.615 - parse_field_attributes(loader_data, 21.616 - cp, attributes_count, is_static, signature_index, 21.617 + parse_field_attributes(attributes_count, is_static, signature_index, 21.618 &constantvalue_index, &is_synthetic, 21.619 - &generic_signature_index, &field_annotations, 21.620 - &field_type_annotations, &parsed_annotations, 21.621 + &generic_signature_index, &parsed_annotations, 21.622 CHECK_NULL); 21.623 - if (field_annotations != NULL) { 21.624 - if (*fields_annotations == NULL) { 21.625 - *fields_annotations = MetadataFactory::new_array<AnnotationArray*>( 21.626 - loader_data, length, NULL, 21.627 + if (parsed_annotations.field_annotations() != NULL) { 21.628 + if (_fields_annotations == NULL) { 21.629 + _fields_annotations = MetadataFactory::new_array<AnnotationArray*>( 21.630 + _loader_data, length, NULL, 21.631 CHECK_NULL); 21.632 } 21.633 - (*fields_annotations)->at_put(n, field_annotations); 21.634 + _fields_annotations->at_put(n, parsed_annotations.field_annotations()); 21.635 + parsed_annotations.set_field_annotations(NULL); 21.636 } 21.637 - if (field_type_annotations != NULL) { 21.638 - if (*fields_type_annotations == NULL) { 21.639 - *fields_type_annotations = MetadataFactory::new_array<AnnotationArray*>( 21.640 - loader_data, length, NULL, 21.641 + if (parsed_annotations.field_type_annotations() != NULL) { 21.642 + if (_fields_type_annotations == NULL) { 21.643 + _fields_type_annotations = MetadataFactory::new_array<AnnotationArray*>( 21.644 + _loader_data, length, NULL, 21.645 CHECK_NULL); 21.646 } 21.647 - (*fields_type_annotations)->at_put(n, field_type_annotations); 21.648 + _fields_type_annotations->at_put(n, parsed_annotations.field_type_annotations()); 21.649 + parsed_annotations.set_field_type_annotations(NULL); 21.650 } 21.651 + 21.652 if (is_synthetic) { 21.653 access_flags.set_is_synthetic(); 21.654 } 21.655 @@ -1224,7 +1174,7 @@ 21.656 name_index, 21.657 signature_index, 21.658 constantvalue_index); 21.659 - BasicType type = cp->basic_type_for_signature_at(signature_index); 21.660 + BasicType type = _cp->basic_type_for_signature_at(signature_index); 21.661 21.662 // Remember how many oops we encountered and compute allocation type 21.663 FieldAllocationType atype = fac->update(is_static, type); 21.664 @@ -1245,8 +1195,8 @@ 21.665 bool duplicate = false; 21.666 for (int i = 0; i < length; i++) { 21.667 FieldInfo* f = FieldInfo::from_field_array(fa, i); 21.668 - if (name == cp->symbol_at(f->name_index()) && 21.669 - signature == cp->symbol_at(f->signature_index())) { 21.670 + if (name == _cp->symbol_at(f->name_index()) && 21.671 + signature == _cp->symbol_at(f->signature_index())) { 21.672 // Symbol is desclared in Java so skip this one 21.673 duplicate = true; 21.674 break; 21.675 @@ -1280,8 +1230,9 @@ 21.676 // fields array is trimed. Also unused slots that were reserved 21.677 // for generic signature indexes are discarded. 21.678 Array<u2>* fields = MetadataFactory::new_array<u2>( 21.679 - loader_data, index * FieldInfo::field_slots + num_generic_signature, 21.680 + _loader_data, index * FieldInfo::field_slots + num_generic_signature, 21.681 CHECK_NULL); 21.682 + _fields = fields; // save in case of error 21.683 { 21.684 int i = 0; 21.685 for (; i < index * FieldInfo::field_slots; i++) { 21.686 @@ -1303,7 +1254,7 @@ 21.687 bool dup = false; 21.688 { 21.689 debug_only(No_Safepoint_Verifier nsv;) 21.690 - for (AllFieldStream fs(fields, cp); !fs.done(); fs.next()) { 21.691 + for (AllFieldStream fs(fields, _cp); !fs.done(); fs.next()) { 21.692 Symbol* name = fs.name(); 21.693 Symbol* sig = fs.signature(); 21.694 // If no duplicates, add name/signature in hashtable names_and_sigs. 21.695 @@ -1330,10 +1281,8 @@ 21.696 } 21.697 21.698 21.699 -u2* ClassFileParser::parse_exception_table(ClassLoaderData* loader_data, 21.700 - u4 code_length, 21.701 +u2* ClassFileParser::parse_exception_table(u4 code_length, 21.702 u4 exception_table_length, 21.703 - constantPoolHandle cp, 21.704 TRAPS) { 21.705 ClassFileStream* cfs = stream(); 21.706 21.707 @@ -1354,8 +1303,7 @@ 21.708 "Illegal exception table handler in class file %s", 21.709 CHECK_NULL); 21.710 if (catch_type_index != 0) { 21.711 - guarantee_property(valid_cp_range(catch_type_index, cp->length()) && 21.712 - is_klass_reference(cp, catch_type_index), 21.713 + guarantee_property(valid_klass_reference_at(catch_type_index), 21.714 "Catch type in exception table has bad constant type in class file %s", CHECK_NULL); 21.715 } 21.716 } 21.717 @@ -1506,7 +1454,6 @@ 21.718 u2* ClassFileParser::parse_localvariable_table(u4 code_length, 21.719 u2 max_locals, 21.720 u4 code_attribute_length, 21.721 - constantPoolHandle cp, 21.722 u2* localvariable_table_length, 21.723 bool isLVTT, 21.724 TRAPS) { 21.725 @@ -1544,20 +1491,16 @@ 21.726 "Invalid length %u in %s in class file %s", 21.727 length, tbl_name, CHECK_NULL); 21.728 } 21.729 - int cp_size = cp->length(); 21.730 - guarantee_property( 21.731 - valid_cp_range(name_index, cp_size) && 21.732 - cp->tag_at(name_index).is_utf8(), 21.733 + int cp_size = _cp->length(); 21.734 + guarantee_property(valid_symbol_at(name_index), 21.735 "Name index %u in %s has bad constant type in class file %s", 21.736 name_index, tbl_name, CHECK_NULL); 21.737 - guarantee_property( 21.738 - valid_cp_range(descriptor_index, cp_size) && 21.739 - cp->tag_at(descriptor_index).is_utf8(), 21.740 + guarantee_property(valid_symbol_at(descriptor_index), 21.741 "Signature index %u in %s has bad constant type in class file %s", 21.742 descriptor_index, tbl_name, CHECK_NULL); 21.743 21.744 - Symbol* name = cp->symbol_at(name_index); 21.745 - Symbol* sig = cp->symbol_at(descriptor_index); 21.746 + Symbol* name = _cp->symbol_at(name_index); 21.747 + Symbol* sig = _cp->symbol_at(descriptor_index); 21.748 verify_legal_field_name(name, CHECK_NULL); 21.749 u2 extra_slot = 0; 21.750 if (!isLVTT) { 21.751 @@ -1579,7 +1522,7 @@ 21.752 21.753 21.754 void ClassFileParser::parse_type_array(u2 array_length, u4 code_length, u4* u1_index, u4* u2_index, 21.755 - u1* u1_array, u2* u2_array, constantPoolHandle cp, TRAPS) { 21.756 + u1* u1_array, u2* u2_array, TRAPS) { 21.757 ClassFileStream* cfs = stream(); 21.758 u2 index = 0; // index in the array with long/double occupying two slots 21.759 u4 i1 = *u1_index; 21.760 @@ -1591,8 +1534,7 @@ 21.761 index++; 21.762 } else if (tag == ITEM_Object) { 21.763 u2 class_index = u2_array[i2++] = cfs->get_u2(CHECK); 21.764 - guarantee_property(valid_cp_range(class_index, cp->length()) && 21.765 - is_klass_reference(cp, class_index), 21.766 + guarantee_property(valid_klass_reference_at(class_index), 21.767 "Bad class index %u in StackMap in class file %s", 21.768 class_index, CHECK); 21.769 } else if (tag == ITEM_Uninitialized) { 21.770 @@ -1613,8 +1555,7 @@ 21.771 *u2_index = i2; 21.772 } 21.773 21.774 -Array<u1>* ClassFileParser::parse_stackmap_table( 21.775 - ClassLoaderData* loader_data, 21.776 +u1* ClassFileParser::parse_stackmap_table( 21.777 u4 code_attribute_length, TRAPS) { 21.778 if (code_attribute_length == 0) 21.779 return NULL; 21.780 @@ -1629,18 +1570,12 @@ 21.781 if (!_need_verify && !DumpSharedSpaces) { 21.782 return NULL; 21.783 } 21.784 - 21.785 - Array<u1>* stackmap_data = 21.786 - MetadataFactory::new_array<u1>(loader_data, code_attribute_length, 0, CHECK_NULL); 21.787 - 21.788 - memcpy((void*)stackmap_data->adr_at(0), 21.789 - (void*)stackmap_table_start, code_attribute_length); 21.790 - return stackmap_data; 21.791 + return stackmap_table_start; 21.792 } 21.793 21.794 u2* ClassFileParser::parse_checked_exceptions(u2* checked_exceptions_length, 21.795 u4 method_attribute_length, 21.796 - constantPoolHandle cp, TRAPS) { 21.797 + TRAPS) { 21.798 ClassFileStream* cfs = stream(); 21.799 cfs->guarantee_more(2, CHECK_NULL); // checked_exceptions_length 21.800 *checked_exceptions_length = cfs->get_u2_fast(); 21.801 @@ -1657,8 +1592,7 @@ 21.802 for (int i = 0; i < len; i++) { 21.803 checked_exception = cfs->get_u2_fast(); 21.804 check_property( 21.805 - valid_cp_range(checked_exception, cp->length()) && 21.806 - is_klass_reference(cp, checked_exception), 21.807 + valid_klass_reference_at(checked_exception), 21.808 "Exception name has bad type at constant pool %u in class file %s", 21.809 checked_exception, CHECK_NULL); 21.810 } 21.811 @@ -1735,9 +1669,7 @@ 21.812 } 21.813 21.814 // Sift through annotations, looking for those significant to the VM: 21.815 -void ClassFileParser::parse_annotations(ClassLoaderData* loader_data, 21.816 - u1* buffer, int limit, 21.817 - constantPoolHandle cp, 21.818 +void ClassFileParser::parse_annotations(u1* buffer, int limit, 21.819 ClassFileParser::AnnotationCollector* coll, 21.820 TRAPS) { 21.821 // annotations := do(nann:u2) {annotation} 21.822 @@ -1767,17 +1699,17 @@ 21.823 u1* abase = buffer + index0; 21.824 int atype = Bytes::get_Java_u2(abase + atype_off); 21.825 int count = Bytes::get_Java_u2(abase + count_off); 21.826 - Symbol* aname = check_symbol_at(cp, atype); 21.827 + Symbol* aname = check_symbol_at(_cp, atype); 21.828 if (aname == NULL) break; // invalid annotation name 21.829 Symbol* member = NULL; 21.830 if (count >= 1) { 21.831 int member_index = Bytes::get_Java_u2(abase + member_off); 21.832 - member = check_symbol_at(cp, member_index); 21.833 + member = check_symbol_at(_cp, member_index); 21.834 if (member == NULL) break; // invalid member name 21.835 } 21.836 21.837 // Here is where parsing particular annotations will take place. 21.838 - AnnotationCollector::ID id = coll->annotation_index(loader_data, aname); 21.839 + AnnotationCollector::ID id = coll->annotation_index(_loader_data, aname); 21.840 if (id == AnnotationCollector::_unknown) continue; 21.841 coll->set_annotation(id); 21.842 21.843 @@ -1836,6 +1768,12 @@ 21.844 f->set_contended_group(contended_group()); 21.845 } 21.846 21.847 +ClassFileParser::FieldAnnotationCollector::~FieldAnnotationCollector() { 21.848 + // If there's an error deallocate metadata for field annotations 21.849 + MetadataFactory::free_array<u1>(_loader_data, _field_annotations); 21.850 + MetadataFactory::free_array<u1>(_loader_data, _field_type_annotations); 21.851 +} 21.852 + 21.853 void ClassFileParser::MethodAnnotationCollector::apply_to(methodHandle m) { 21.854 if (has_annotation(_method_ForceInline)) 21.855 m->set_force_inline(true); 21.856 @@ -1894,10 +1832,9 @@ 21.857 && _need_verify 21.858 && _major_version >= JAVA_1_5_VERSION) { 21.859 clear_hashtable(lvt_Hash); 21.860 - ConstantPool* cp = cm->constants(); 21.861 classfile_parse_error("Duplicated LocalVariableTable attribute " 21.862 "entry for '%s' in class file %s", 21.863 - cp->symbol_at(lvt->name_cp_index)->as_utf8(), 21.864 + _cp->symbol_at(lvt->name_cp_index)->as_utf8(), 21.865 CHECK); 21.866 } 21.867 } 21.868 @@ -1916,18 +1853,16 @@ 21.869 if (entry == NULL) { 21.870 if (_need_verify) { 21.871 clear_hashtable(lvt_Hash); 21.872 - ConstantPool* cp = cm->constants(); 21.873 classfile_parse_error("LVTT entry for '%s' in class file %s " 21.874 "does not match any LVT entry", 21.875 - cp->symbol_at(lvtt_elem.name_cp_index)->as_utf8(), 21.876 + _cp->symbol_at(lvtt_elem.name_cp_index)->as_utf8(), 21.877 CHECK); 21.878 } 21.879 } else if (entry->_elem->signature_cp_index != 0 && _need_verify) { 21.880 clear_hashtable(lvt_Hash); 21.881 - ConstantPool* cp = cm->constants(); 21.882 classfile_parse_error("Duplicated LocalVariableTypeTable attribute " 21.883 "entry for '%s' in class file %s", 21.884 - cp->symbol_at(lvtt_elem.name_cp_index)->as_utf8(), 21.885 + _cp->symbol_at(lvtt_elem.name_cp_index)->as_utf8(), 21.886 CHECK); 21.887 } else { 21.888 // to add generic signatures into LocalVariableTable 21.889 @@ -1939,8 +1874,7 @@ 21.890 } 21.891 21.892 21.893 -void ClassFileParser::copy_method_annotations(ClassLoaderData* loader_data, 21.894 - ConstMethod* cm, 21.895 +void ClassFileParser::copy_method_annotations(ConstMethod* cm, 21.896 u1* runtime_visible_annotations, 21.897 int runtime_visible_annotations_length, 21.898 u1* runtime_invisible_annotations, 21.899 @@ -1961,8 +1895,7 @@ 21.900 21.901 if (runtime_visible_annotations_length + 21.902 runtime_invisible_annotations_length > 0) { 21.903 - a = assemble_annotations(loader_data, 21.904 - runtime_visible_annotations, 21.905 + a = assemble_annotations(runtime_visible_annotations, 21.906 runtime_visible_annotations_length, 21.907 runtime_invisible_annotations, 21.908 runtime_invisible_annotations_length, 21.909 @@ -1972,8 +1905,7 @@ 21.910 21.911 if (runtime_visible_parameter_annotations_length + 21.912 runtime_invisible_parameter_annotations_length > 0) { 21.913 - a = assemble_annotations(loader_data, 21.914 - runtime_visible_parameter_annotations, 21.915 + a = assemble_annotations(runtime_visible_parameter_annotations, 21.916 runtime_visible_parameter_annotations_length, 21.917 runtime_invisible_parameter_annotations, 21.918 runtime_invisible_parameter_annotations_length, 21.919 @@ -1982,8 +1914,7 @@ 21.920 } 21.921 21.922 if (annotation_default_length > 0) { 21.923 - a = assemble_annotations(loader_data, 21.924 - annotation_default, 21.925 + a = assemble_annotations(annotation_default, 21.926 annotation_default_length, 21.927 NULL, 21.928 0, 21.929 @@ -1993,8 +1924,7 @@ 21.930 21.931 if (runtime_visible_type_annotations_length + 21.932 runtime_invisible_type_annotations_length > 0) { 21.933 - a = assemble_annotations(loader_data, 21.934 - runtime_visible_type_annotations, 21.935 + a = assemble_annotations(runtime_visible_type_annotations, 21.936 runtime_visible_type_annotations_length, 21.937 runtime_invisible_type_annotations, 21.938 runtime_invisible_type_annotations_length, 21.939 @@ -2013,9 +1943,7 @@ 21.940 // from the method back up to the containing klass. These flag values 21.941 // are added to klass's access_flags. 21.942 21.943 -methodHandle ClassFileParser::parse_method(ClassLoaderData* loader_data, 21.944 - constantPoolHandle cp, 21.945 - bool is_interface, 21.946 +methodHandle ClassFileParser::parse_method(bool is_interface, 21.947 AccessFlags *promoted_flags, 21.948 TRAPS) { 21.949 ClassFileStream* cfs = stream(); 21.950 @@ -2026,22 +1954,20 @@ 21.951 21.952 int flags = cfs->get_u2_fast(); 21.953 u2 name_index = cfs->get_u2_fast(); 21.954 - int cp_size = cp->length(); 21.955 + int cp_size = _cp->length(); 21.956 check_property( 21.957 - valid_cp_range(name_index, cp_size) && 21.958 - cp->tag_at(name_index).is_utf8(), 21.959 + valid_symbol_at(name_index), 21.960 "Illegal constant pool index %u for method name in class file %s", 21.961 name_index, CHECK_(nullHandle)); 21.962 - Symbol* name = cp->symbol_at(name_index); 21.963 + Symbol* name = _cp->symbol_at(name_index); 21.964 verify_legal_method_name(name, CHECK_(nullHandle)); 21.965 21.966 u2 signature_index = cfs->get_u2_fast(); 21.967 guarantee_property( 21.968 - valid_cp_range(signature_index, cp_size) && 21.969 - cp->tag_at(signature_index).is_utf8(), 21.970 + valid_symbol_at(signature_index), 21.971 "Illegal constant pool index %u for method signature in class file %s", 21.972 signature_index, CHECK_(nullHandle)); 21.973 - Symbol* signature = cp->symbol_at(signature_index); 21.974 + Symbol* signature = _cp->symbol_at(signature_index); 21.975 21.976 AccessFlags access_flags; 21.977 if (name == vmSymbols::class_initializer_name()) { 21.978 @@ -2097,7 +2023,8 @@ 21.979 bool parsed_checked_exceptions_attribute = false; 21.980 bool parsed_stackmap_attribute = false; 21.981 // stackmap attribute - JDK1.5 21.982 - Array<u1>* stackmap_data = NULL; 21.983 + u1* stackmap_data = NULL; 21.984 + int stackmap_data_length = 0; 21.985 u2 generic_signature_index = 0; 21.986 MethodAnnotationCollector parsed_annotations; 21.987 u1* runtime_visible_annotations = NULL; 21.988 @@ -2122,12 +2049,11 @@ 21.989 u2 method_attribute_name_index = cfs->get_u2_fast(); 21.990 u4 method_attribute_length = cfs->get_u4_fast(); 21.991 check_property( 21.992 - valid_cp_range(method_attribute_name_index, cp_size) && 21.993 - cp->tag_at(method_attribute_name_index).is_utf8(), 21.994 + valid_symbol_at(method_attribute_name_index), 21.995 "Invalid method attribute name index %u in class file %s", 21.996 method_attribute_name_index, CHECK_(nullHandle)); 21.997 21.998 - Symbol* method_attribute_name = cp->symbol_at(method_attribute_name_index); 21.999 + Symbol* method_attribute_name = _cp->symbol_at(method_attribute_name_index); 21.1000 if (method_attribute_name == vmSymbols::tag_code()) { 21.1001 // Parse Code attribute 21.1002 if (_need_verify) { 21.1003 @@ -2171,7 +2097,7 @@ 21.1004 exception_table_length = cfs->get_u2_fast(); 21.1005 if (exception_table_length > 0) { 21.1006 exception_table_start = 21.1007 - parse_exception_table(loader_data, code_length, exception_table_length, cp, CHECK_(nullHandle)); 21.1008 + parse_exception_table(code_length, exception_table_length, CHECK_(nullHandle)); 21.1009 } 21.1010 21.1011 // Parse additional attributes in code attribute 21.1012 @@ -2204,19 +2130,18 @@ 21.1013 calculated_attribute_length += code_attribute_length + 21.1014 sizeof(code_attribute_name_index) + 21.1015 sizeof(code_attribute_length); 21.1016 - check_property(valid_cp_range(code_attribute_name_index, cp_size) && 21.1017 - cp->tag_at(code_attribute_name_index).is_utf8(), 21.1018 + check_property(valid_symbol_at(code_attribute_name_index), 21.1019 "Invalid code attribute name index %u in class file %s", 21.1020 code_attribute_name_index, 21.1021 CHECK_(nullHandle)); 21.1022 if (LoadLineNumberTables && 21.1023 - cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_line_number_table()) { 21.1024 + _cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_line_number_table()) { 21.1025 // Parse and compress line number table 21.1026 parse_linenumber_table(code_attribute_length, code_length, 21.1027 &linenumber_table, CHECK_(nullHandle)); 21.1028 21.1029 } else if (LoadLocalVariableTables && 21.1030 - cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_table()) { 21.1031 + _cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_table()) { 21.1032 // Parse local variable table 21.1033 if (!lvt_allocated) { 21.1034 localvariable_table_length = NEW_RESOURCE_ARRAY_IN_THREAD( 21.1035 @@ -2238,7 +2163,6 @@ 21.1036 parse_localvariable_table(code_length, 21.1037 max_locals, 21.1038 code_attribute_length, 21.1039 - cp, 21.1040 &localvariable_table_length[lvt_cnt], 21.1041 false, // is not LVTT 21.1042 CHECK_(nullHandle)); 21.1043 @@ -2246,7 +2170,7 @@ 21.1044 lvt_cnt++; 21.1045 } else if (LoadLocalVariableTypeTables && 21.1046 _major_version >= JAVA_1_5_VERSION && 21.1047 - cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_type_table()) { 21.1048 + _cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_type_table()) { 21.1049 if (!lvt_allocated) { 21.1050 localvariable_table_length = NEW_RESOURCE_ARRAY_IN_THREAD( 21.1051 THREAD, u2, INITIAL_MAX_LVT_NUMBER); 21.1052 @@ -2268,19 +2192,19 @@ 21.1053 parse_localvariable_table(code_length, 21.1054 max_locals, 21.1055 code_attribute_length, 21.1056 - cp, 21.1057 &localvariable_type_table_length[lvtt_cnt], 21.1058 true, // is LVTT 21.1059 CHECK_(nullHandle)); 21.1060 lvtt_cnt++; 21.1061 } else if (UseSplitVerifier && 21.1062 _major_version >= Verifier::STACKMAP_ATTRIBUTE_MAJOR_VERSION && 21.1063 - cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_stack_map_table()) { 21.1064 + _cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_stack_map_table()) { 21.1065 // Stack map is only needed by the new verifier in JDK1.5. 21.1066 if (parsed_stackmap_attribute) { 21.1067 classfile_parse_error("Multiple StackMapTable attributes in class file %s", CHECK_(nullHandle)); 21.1068 } 21.1069 - stackmap_data = parse_stackmap_table(loader_data, code_attribute_length, CHECK_(nullHandle)); 21.1070 + stackmap_data = parse_stackmap_table(code_attribute_length, CHECK_(nullHandle)); 21.1071 + stackmap_data_length = code_attribute_length; 21.1072 parsed_stackmap_attribute = true; 21.1073 } else { 21.1074 // Skip unknown attributes 21.1075 @@ -2301,7 +2225,7 @@ 21.1076 checked_exceptions_start = 21.1077 parse_checked_exceptions(&checked_exceptions_length, 21.1078 method_attribute_length, 21.1079 - cp, CHECK_(nullHandle)); 21.1080 + CHECK_(nullHandle)); 21.1081 } else if (method_attribute_name == vmSymbols::tag_method_parameters()) { 21.1082 // reject multiple method parameters 21.1083 if (method_parameters_seen) { 21.1084 @@ -2359,9 +2283,8 @@ 21.1085 runtime_visible_annotations_length = method_attribute_length; 21.1086 runtime_visible_annotations = cfs->get_u1_buffer(); 21.1087 assert(runtime_visible_annotations != NULL, "null visible annotations"); 21.1088 - parse_annotations(loader_data, 21.1089 - runtime_visible_annotations, 21.1090 - runtime_visible_annotations_length, cp, &parsed_annotations, 21.1091 + parse_annotations(runtime_visible_annotations, 21.1092 + runtime_visible_annotations_length, &parsed_annotations, 21.1093 CHECK_(nullHandle)); 21.1094 cfs->skip_u1(runtime_visible_annotations_length, CHECK_(nullHandle)); 21.1095 } else if (PreserveAllAnnotations && method_attribute_name == vmSymbols::tag_runtime_invisible_annotations()) { 21.1096 @@ -2434,18 +2357,18 @@ 21.1097 0); 21.1098 21.1099 Method* m = Method::allocate( 21.1100 - loader_data, code_length, access_flags, &sizes, 21.1101 + _loader_data, code_length, access_flags, &sizes, 21.1102 ConstMethod::NORMAL, CHECK_(nullHandle)); 21.1103 21.1104 ClassLoadingService::add_class_method_size(m->size()*HeapWordSize); 21.1105 21.1106 // Fill in information from fixed part (access_flags already set) 21.1107 - m->set_constants(cp()); 21.1108 + m->set_constants(_cp); 21.1109 m->set_name_index(name_index); 21.1110 m->set_signature_index(signature_index); 21.1111 #ifdef CC_INTERP 21.1112 // hmm is there a gc issue here?? 21.1113 - ResultTypeFinder rtf(cp->symbol_at(signature_index)); 21.1114 + ResultTypeFinder rtf(_cp->symbol_at(signature_index)); 21.1115 m->set_result_index(rtf.type()); 21.1116 #endif 21.1117 21.1118 @@ -2464,7 +2387,10 @@ 21.1119 // Fill in code attribute information 21.1120 m->set_max_stack(max_stack); 21.1121 m->set_max_locals(max_locals); 21.1122 - m->constMethod()->set_stackmap_data(stackmap_data); 21.1123 + if (stackmap_data != NULL) { 21.1124 + m->constMethod()->copy_stackmap_data(_loader_data, stackmap_data, 21.1125 + stackmap_data_length, CHECK_NULL); 21.1126 + } 21.1127 21.1128 // Copy byte codes 21.1129 m->set_code(code_start); 21.1130 @@ -2520,7 +2446,7 @@ 21.1131 parsed_annotations.apply_to(m); 21.1132 21.1133 // Copy annotations 21.1134 - copy_method_annotations(loader_data, m->constMethod(), 21.1135 + copy_method_annotations(m->constMethod(), 21.1136 runtime_visible_annotations, 21.1137 runtime_visible_annotations_length, 21.1138 runtime_invisible_annotations, 21.1139 @@ -2560,9 +2486,7 @@ 21.1140 // from the methods back up to the containing klass. These flag values 21.1141 // are added to klass's access_flags. 21.1142 21.1143 -Array<Method*>* ClassFileParser::parse_methods(ClassLoaderData* loader_data, 21.1144 - constantPoolHandle cp, 21.1145 - bool is_interface, 21.1146 +Array<Method*>* ClassFileParser::parse_methods(bool is_interface, 21.1147 AccessFlags* promoted_flags, 21.1148 bool* has_final_method, 21.1149 bool* has_default_methods, 21.1150 @@ -2571,15 +2495,13 @@ 21.1151 cfs->guarantee_more(2, CHECK_NULL); // length 21.1152 u2 length = cfs->get_u2_fast(); 21.1153 if (length == 0) { 21.1154 - return Universe::the_empty_method_array(); 21.1155 + _methods = Universe::the_empty_method_array(); 21.1156 } else { 21.1157 - // FIXME: Handle leaks at later failures. 21.1158 - Array<Method*>* methods = MetadataFactory::new_array<Method*>(loader_data, length, NULL, CHECK_NULL); 21.1159 + _methods = MetadataFactory::new_array<Method*>(_loader_data, length, NULL, CHECK_NULL); 21.1160 21.1161 HandleMark hm(THREAD); 21.1162 for (int index = 0; index < length; index++) { 21.1163 - methodHandle method = parse_method(loader_data, 21.1164 - cp, is_interface, 21.1165 + methodHandle method = parse_method(is_interface, 21.1166 promoted_flags, 21.1167 CHECK_NULL); 21.1168 21.1169 @@ -2590,7 +2512,7 @@ 21.1170 // default method 21.1171 *has_default_methods = true; 21.1172 } 21.1173 - methods->at_put(index, method()); 21.1174 + _methods->at_put(index, method()); 21.1175 } 21.1176 21.1177 if (_need_verify && length > 1) { 21.1178 @@ -2603,7 +2525,7 @@ 21.1179 { 21.1180 debug_only(No_Safepoint_Verifier nsv;) 21.1181 for (int i = 0; i < length; i++) { 21.1182 - Method* m = methods->at(i); 21.1183 + Method* m = _methods->at(i); 21.1184 // If no duplicates, add name/signature in hashtable names_and_sigs. 21.1185 if (!put_after_lookup(m->name(), m->signature(), names_and_sigs)) { 21.1186 dup = true; 21.1187 @@ -2616,14 +2538,12 @@ 21.1188 CHECK_NULL); 21.1189 } 21.1190 } 21.1191 - return methods; 21.1192 } 21.1193 + return _methods; 21.1194 } 21.1195 21.1196 21.1197 -Array<int>* ClassFileParser::sort_methods(ClassLoaderData* loader_data, 21.1198 - Array<Method*>* methods, 21.1199 - TRAPS) { 21.1200 +intArray* ClassFileParser::sort_methods(Array<Method*>* methods) { 21.1201 int length = methods->length(); 21.1202 // If JVMTI original method ordering or sharing is enabled we have to 21.1203 // remember the original class file ordering. 21.1204 @@ -2641,10 +2561,11 @@ 21.1205 // Note that the ordering is not alphabetical, see Symbol::fast_compare 21.1206 Method::sort_methods(methods); 21.1207 21.1208 + intArray* method_ordering = NULL; 21.1209 // If JVMTI original method ordering or sharing is enabled construct int 21.1210 // array remembering the original ordering 21.1211 if (JvmtiExport::can_maintain_original_method_order() || DumpSharedSpaces) { 21.1212 - Array<int>* method_ordering = MetadataFactory::new_array<int>(loader_data, length, CHECK_NULL); 21.1213 + method_ordering = new intArray(length); 21.1214 for (int index = 0; index < length; index++) { 21.1215 Method* m = methods->at(index); 21.1216 int old_index = m->vtable_index(); 21.1217 @@ -2652,29 +2573,25 @@ 21.1218 method_ordering->at_put(index, old_index); 21.1219 m->set_vtable_index(Method::invalid_vtable_index); 21.1220 } 21.1221 - return method_ordering; 21.1222 - } else { 21.1223 - return Universe::the_empty_int_array(); 21.1224 } 21.1225 + return method_ordering; 21.1226 } 21.1227 21.1228 21.1229 -void ClassFileParser::parse_classfile_sourcefile_attribute(constantPoolHandle cp, TRAPS) { 21.1230 +void ClassFileParser::parse_classfile_sourcefile_attribute(TRAPS) { 21.1231 ClassFileStream* cfs = stream(); 21.1232 cfs->guarantee_more(2, CHECK); // sourcefile_index 21.1233 u2 sourcefile_index = cfs->get_u2_fast(); 21.1234 check_property( 21.1235 - valid_cp_range(sourcefile_index, cp->length()) && 21.1236 - cp->tag_at(sourcefile_index).is_utf8(), 21.1237 + valid_symbol_at(sourcefile_index), 21.1238 "Invalid SourceFile attribute at constant pool index %u in class file %s", 21.1239 sourcefile_index, CHECK); 21.1240 - set_class_sourcefile(cp->symbol_at(sourcefile_index)); 21.1241 + set_class_sourcefile(_cp->symbol_at(sourcefile_index)); 21.1242 } 21.1243 21.1244 21.1245 21.1246 -void ClassFileParser::parse_classfile_source_debug_extension_attribute(constantPoolHandle cp, 21.1247 - int length, TRAPS) { 21.1248 +void ClassFileParser::parse_classfile_source_debug_extension_attribute(int length, TRAPS) { 21.1249 ClassFileStream* cfs = stream(); 21.1250 u1* sde_buffer = cfs->get_u1_buffer(); 21.1251 assert(sde_buffer != NULL, "null sde buffer"); 21.1252 @@ -2698,12 +2615,10 @@ 21.1253 #define RECOGNIZED_INNER_CLASS_MODIFIERS (JVM_RECOGNIZED_CLASS_MODIFIERS | JVM_ACC_PRIVATE | JVM_ACC_PROTECTED | JVM_ACC_STATIC) 21.1254 21.1255 // Return number of classes in the inner classes attribute table 21.1256 -u2 ClassFileParser::parse_classfile_inner_classes_attribute(ClassLoaderData* loader_data, 21.1257 - u1* inner_classes_attribute_start, 21.1258 +u2 ClassFileParser::parse_classfile_inner_classes_attribute(u1* inner_classes_attribute_start, 21.1259 bool parsed_enclosingmethod_attribute, 21.1260 u2 enclosing_method_class_index, 21.1261 u2 enclosing_method_method_index, 21.1262 - constantPoolHandle cp, 21.1263 TRAPS) { 21.1264 ClassFileStream* cfs = stream(); 21.1265 u1* current_mark = cfs->current(); 21.1266 @@ -2724,33 +2639,31 @@ 21.1267 // enclosing_method_class_index, 21.1268 // enclosing_method_method_index] 21.1269 int size = length * 4 + (parsed_enclosingmethod_attribute ? 2 : 0); 21.1270 - // FIXME: Will leak on exceptions. 21.1271 - Array<u2>* inner_classes = MetadataFactory::new_array<u2>(loader_data, size, CHECK_0); 21.1272 + Array<u2>* inner_classes = MetadataFactory::new_array<u2>(_loader_data, size, CHECK_0); 21.1273 + _inner_classes = inner_classes; 21.1274 + 21.1275 int index = 0; 21.1276 - int cp_size = cp->length(); 21.1277 + int cp_size = _cp->length(); 21.1278 cfs->guarantee_more(8 * length, CHECK_0); // 4-tuples of u2 21.1279 for (int n = 0; n < length; n++) { 21.1280 // Inner class index 21.1281 u2 inner_class_info_index = cfs->get_u2_fast(); 21.1282 check_property( 21.1283 inner_class_info_index == 0 || 21.1284 - (valid_cp_range(inner_class_info_index, cp_size) && 21.1285 - is_klass_reference(cp, inner_class_info_index)), 21.1286 + valid_klass_reference_at(inner_class_info_index), 21.1287 "inner_class_info_index %u has bad constant type in class file %s", 21.1288 inner_class_info_index, CHECK_0); 21.1289 // Outer class index 21.1290 u2 outer_class_info_index = cfs->get_u2_fast(); 21.1291 check_property( 21.1292 outer_class_info_index == 0 || 21.1293 - (valid_cp_range(outer_class_info_index, cp_size) && 21.1294 - is_klass_reference(cp, outer_class_info_index)), 21.1295 + valid_klass_reference_at(outer_class_info_index), 21.1296 "outer_class_info_index %u has bad constant type in class file %s", 21.1297 outer_class_info_index, CHECK_0); 21.1298 // Inner class name 21.1299 u2 inner_name_index = cfs->get_u2_fast(); 21.1300 check_property( 21.1301 - inner_name_index == 0 || (valid_cp_range(inner_name_index, cp_size) && 21.1302 - cp->tag_at(inner_name_index).is_utf8()), 21.1303 + inner_name_index == 0 || valid_symbol_at(inner_name_index), 21.1304 "inner_name_index %u has bad constant type in class file %s", 21.1305 inner_name_index, CHECK_0); 21.1306 if (_need_verify) { 21.1307 @@ -2794,33 +2707,27 @@ 21.1308 } 21.1309 assert(index == size, "wrong size"); 21.1310 21.1311 - // Update InstanceKlass with inner class info. 21.1312 - set_class_inner_classes(inner_classes); 21.1313 - 21.1314 // Restore buffer's current position. 21.1315 cfs->set_current(current_mark); 21.1316 21.1317 return length; 21.1318 } 21.1319 21.1320 -void ClassFileParser::parse_classfile_synthetic_attribute(constantPoolHandle cp, TRAPS) { 21.1321 +void ClassFileParser::parse_classfile_synthetic_attribute(TRAPS) { 21.1322 set_class_synthetic_flag(true); 21.1323 } 21.1324 21.1325 -void ClassFileParser::parse_classfile_signature_attribute(constantPoolHandle cp, TRAPS) { 21.1326 +void ClassFileParser::parse_classfile_signature_attribute(TRAPS) { 21.1327 ClassFileStream* cfs = stream(); 21.1328 u2 signature_index = cfs->get_u2(CHECK); 21.1329 check_property( 21.1330 - valid_cp_range(signature_index, cp->length()) && 21.1331 - cp->tag_at(signature_index).is_utf8(), 21.1332 + valid_symbol_at(signature_index), 21.1333 "Invalid constant pool index %u in Signature attribute in class file %s", 21.1334 signature_index, CHECK); 21.1335 - set_class_generic_signature(cp->symbol_at(signature_index)); 21.1336 + set_class_generic_signature(_cp->symbol_at(signature_index)); 21.1337 } 21.1338 21.1339 -void ClassFileParser::parse_classfile_bootstrap_methods_attribute(ClassLoaderData* loader_data, 21.1340 - constantPoolHandle cp, 21.1341 - u4 attribute_byte_length, TRAPS) { 21.1342 +void ClassFileParser::parse_classfile_bootstrap_methods_attribute(u4 attribute_byte_length, TRAPS) { 21.1343 ClassFileStream* cfs = stream(); 21.1344 u1* current_start = cfs->current(); 21.1345 21.1346 @@ -2841,10 +2748,14 @@ 21.1347 // The array begins with a series of short[2] pairs, one for each tuple. 21.1348 int index_size = (attribute_array_length * 2); 21.1349 21.1350 - Array<u2>* operands = MetadataFactory::new_array<u2>(loader_data, index_size + operand_count, CHECK); 21.1351 + Array<u2>* operands = MetadataFactory::new_array<u2>(_loader_data, index_size + operand_count, CHECK); 21.1352 + 21.1353 + // Eagerly assign operands so they will be deallocated with the constant 21.1354 + // pool if there is an error. 21.1355 + _cp->set_operands(operands); 21.1356 21.1357 int operand_fill_index = index_size; 21.1358 - int cp_size = cp->length(); 21.1359 + int cp_size = _cp->length(); 21.1360 21.1361 for (int n = 0; n < attribute_array_length; n++) { 21.1362 // Store a 32-bit offset into the header of the operand array. 21.1363 @@ -2856,7 +2767,7 @@ 21.1364 u2 argument_count = cfs->get_u2_fast(); 21.1365 check_property( 21.1366 valid_cp_range(bootstrap_method_index, cp_size) && 21.1367 - cp->tag_at(bootstrap_method_index).is_method_handle(), 21.1368 + _cp->tag_at(bootstrap_method_index).is_method_handle(), 21.1369 "bootstrap_method_index %u has bad constant type in class file %s", 21.1370 bootstrap_method_index, 21.1371 CHECK); 21.1372 @@ -2868,7 +2779,7 @@ 21.1373 u2 argument_index = cfs->get_u2_fast(); 21.1374 check_property( 21.1375 valid_cp_range(argument_index, cp_size) && 21.1376 - cp->tag_at(argument_index).is_loadable_constant(), 21.1377 + _cp->tag_at(argument_index).is_loadable_constant(), 21.1378 "argument_index %u has bad constant type in class file %s", 21.1379 argument_index, 21.1380 CHECK); 21.1381 @@ -2883,17 +2794,13 @@ 21.1382 guarantee_property(current_end == current_start + attribute_byte_length, 21.1383 "Bad length on BootstrapMethods in class file %s", 21.1384 CHECK); 21.1385 - 21.1386 - cp->set_operands(operands); 21.1387 } 21.1388 21.1389 -void ClassFileParser::parse_classfile_attributes(ClassLoaderData* loader_data, 21.1390 - constantPoolHandle cp, 21.1391 - ClassFileParser::ClassAnnotationCollector* parsed_annotations, 21.1392 +void ClassFileParser::parse_classfile_attributes(ClassFileParser::ClassAnnotationCollector* parsed_annotations, 21.1393 TRAPS) { 21.1394 ClassFileStream* cfs = stream(); 21.1395 // Set inner classes attribute to default sentinel 21.1396 - set_class_inner_classes(Universe::the_empty_short_array()); 21.1397 + _inner_classes = Universe::the_empty_short_array(); 21.1398 cfs->guarantee_more(2, CHECK); // attributes_count 21.1399 u2 attributes_count = cfs->get_u2_fast(); 21.1400 bool parsed_sourcefile_attribute = false; 21.1401 @@ -2918,11 +2825,10 @@ 21.1402 u2 attribute_name_index = cfs->get_u2_fast(); 21.1403 u4 attribute_length = cfs->get_u4_fast(); 21.1404 check_property( 21.1405 - valid_cp_range(attribute_name_index, cp->length()) && 21.1406 - cp->tag_at(attribute_name_index).is_utf8(), 21.1407 + valid_symbol_at(attribute_name_index), 21.1408 "Attribute name has bad constant pool index %u in class file %s", 21.1409 attribute_name_index, CHECK); 21.1410 - Symbol* tag = cp->symbol_at(attribute_name_index); 21.1411 + Symbol* tag = _cp->symbol_at(attribute_name_index); 21.1412 if (tag == vmSymbols::tag_source_file()) { 21.1413 // Check for SourceFile tag 21.1414 if (_need_verify) { 21.1415 @@ -2933,10 +2839,10 @@ 21.1416 } else { 21.1417 parsed_sourcefile_attribute = true; 21.1418 } 21.1419 - parse_classfile_sourcefile_attribute(cp, CHECK); 21.1420 + parse_classfile_sourcefile_attribute(CHECK); 21.1421 } else if (tag == vmSymbols::tag_source_debug_extension()) { 21.1422 // Check for SourceDebugExtension tag 21.1423 - parse_classfile_source_debug_extension_attribute(cp, (int)attribute_length, CHECK); 21.1424 + parse_classfile_source_debug_extension_attribute((int)attribute_length, CHECK); 21.1425 } else if (tag == vmSymbols::tag_inner_classes()) { 21.1426 // Check for InnerClasses tag 21.1427 if (parsed_innerclasses_attribute) { 21.1428 @@ -2955,7 +2861,7 @@ 21.1429 "Invalid Synthetic classfile attribute length %u in class file %s", 21.1430 attribute_length, CHECK); 21.1431 } 21.1432 - parse_classfile_synthetic_attribute(cp, CHECK); 21.1433 + parse_classfile_synthetic_attribute(CHECK); 21.1434 } else if (tag == vmSymbols::tag_deprecated()) { 21.1435 // Check for Deprecatd tag - 4276120 21.1436 if (attribute_length != 0) { 21.1437 @@ -2970,15 +2876,13 @@ 21.1438 "Wrong Signature attribute length %u in class file %s", 21.1439 attribute_length, CHECK); 21.1440 } 21.1441 - parse_classfile_signature_attribute(cp, CHECK); 21.1442 + parse_classfile_signature_attribute(CHECK); 21.1443 } else if (tag == vmSymbols::tag_runtime_visible_annotations()) { 21.1444 runtime_visible_annotations_length = attribute_length; 21.1445 runtime_visible_annotations = cfs->get_u1_buffer(); 21.1446 assert(runtime_visible_annotations != NULL, "null visible annotations"); 21.1447 - parse_annotations(loader_data, 21.1448 - runtime_visible_annotations, 21.1449 + parse_annotations(runtime_visible_annotations, 21.1450 runtime_visible_annotations_length, 21.1451 - cp, 21.1452 parsed_annotations, 21.1453 CHECK); 21.1454 cfs->skip_u1(runtime_visible_annotations_length, CHECK); 21.1455 @@ -3000,13 +2904,11 @@ 21.1456 classfile_parse_error("Invalid class index in EnclosingMethod attribute in class file %s", CHECK); 21.1457 } 21.1458 // Validate the constant pool indices and types 21.1459 - if (!cp->is_within_bounds(enclosing_method_class_index) || 21.1460 - !is_klass_reference(cp, enclosing_method_class_index)) { 21.1461 - classfile_parse_error("Invalid or out-of-bounds class index in EnclosingMethod attribute in class file %s", CHECK); 21.1462 - } 21.1463 + check_property(valid_klass_reference_at(enclosing_method_class_index), 21.1464 + "Invalid or out-of-bounds class index in EnclosingMethod attribute in class file %s", CHECK); 21.1465 if (enclosing_method_method_index != 0 && 21.1466 - (!cp->is_within_bounds(enclosing_method_method_index) || 21.1467 - !cp->tag_at(enclosing_method_method_index).is_name_and_type())) { 21.1468 + (!_cp->is_within_bounds(enclosing_method_method_index) || 21.1469 + !_cp->tag_at(enclosing_method_method_index).is_name_and_type())) { 21.1470 classfile_parse_error("Invalid or out-of-bounds method index in EnclosingMethod attribute in class file %s", CHECK); 21.1471 } 21.1472 } else if (tag == vmSymbols::tag_bootstrap_methods() && 21.1473 @@ -3014,7 +2916,7 @@ 21.1474 if (parsed_bootstrap_methods_attribute) 21.1475 classfile_parse_error("Multiple BootstrapMethods attributes in class file %s", CHECK); 21.1476 parsed_bootstrap_methods_attribute = true; 21.1477 - parse_classfile_bootstrap_methods_attribute(loader_data, cp, attribute_length, CHECK); 21.1478 + parse_classfile_bootstrap_methods_attribute(attribute_length, CHECK); 21.1479 } else if (tag == vmSymbols::tag_runtime_visible_type_annotations()) { 21.1480 runtime_visible_type_annotations_length = attribute_length; 21.1481 runtime_visible_type_annotations = cfs->get_u1_buffer(); 21.1482 @@ -3035,29 +2937,24 @@ 21.1483 cfs->skip_u1(attribute_length, CHECK); 21.1484 } 21.1485 } 21.1486 - AnnotationArray* annotations = assemble_annotations(loader_data, 21.1487 - runtime_visible_annotations, 21.1488 - runtime_visible_annotations_length, 21.1489 - runtime_invisible_annotations, 21.1490 - runtime_invisible_annotations_length, 21.1491 - CHECK); 21.1492 - set_class_annotations(annotations); 21.1493 - AnnotationArray* type_annotations = assemble_annotations(loader_data, 21.1494 - runtime_visible_type_annotations, 21.1495 - runtime_visible_type_annotations_length, 21.1496 - runtime_invisible_type_annotations, 21.1497 - runtime_invisible_type_annotations_length, 21.1498 - CHECK); 21.1499 - set_class_type_annotations(type_annotations); 21.1500 + _annotations = assemble_annotations(runtime_visible_annotations, 21.1501 + runtime_visible_annotations_length, 21.1502 + runtime_invisible_annotations, 21.1503 + runtime_invisible_annotations_length, 21.1504 + CHECK); 21.1505 + _type_annotations = assemble_annotations(runtime_visible_type_annotations, 21.1506 + runtime_visible_type_annotations_length, 21.1507 + runtime_invisible_type_annotations, 21.1508 + runtime_invisible_type_annotations_length, 21.1509 + CHECK); 21.1510 21.1511 if (parsed_innerclasses_attribute || parsed_enclosingmethod_attribute) { 21.1512 u2 num_of_classes = parse_classfile_inner_classes_attribute( 21.1513 - loader_data, 21.1514 inner_classes_attribute_start, 21.1515 parsed_innerclasses_attribute, 21.1516 enclosing_method_class_index, 21.1517 enclosing_method_method_index, 21.1518 - cp, CHECK); 21.1519 + CHECK); 21.1520 if (parsed_innerclasses_attribute &&_need_verify && _major_version >= JAVA_1_5_VERSION) { 21.1521 guarantee_property( 21.1522 inner_classes_attribute_length == sizeof(num_of_classes) + 4 * sizeof(u2) * num_of_classes, 21.1523 @@ -3085,18 +2982,43 @@ 21.1524 if (_sde_buffer != NULL) { 21.1525 k->set_source_debug_extension(_sde_buffer, _sde_length); 21.1526 } 21.1527 - k->set_inner_classes(_inner_classes); 21.1528 } 21.1529 21.1530 -AnnotationArray* ClassFileParser::assemble_annotations(ClassLoaderData* loader_data, 21.1531 - u1* runtime_visible_annotations, 21.1532 +// Transfer ownership of metadata allocated to the InstanceKlass. 21.1533 +void ClassFileParser::apply_parsed_class_metadata( 21.1534 + instanceKlassHandle this_klass, 21.1535 + int java_fields_count, TRAPS) { 21.1536 + // Assign annotations if needed 21.1537 + if (_annotations != NULL || _type_annotations != NULL || 21.1538 + _fields_annotations != NULL || _fields_type_annotations != NULL) { 21.1539 + Annotations* annotations = Annotations::allocate(_loader_data, CHECK); 21.1540 + annotations->set_class_annotations(_annotations); 21.1541 + annotations->set_class_type_annotations(_type_annotations); 21.1542 + annotations->set_fields_annotations(_fields_annotations); 21.1543 + annotations->set_fields_type_annotations(_fields_type_annotations); 21.1544 + this_klass->set_annotations(annotations); 21.1545 + } 21.1546 + 21.1547 + _cp->set_pool_holder(this_klass()); 21.1548 + this_klass->set_constants(_cp); 21.1549 + this_klass->set_fields(_fields, java_fields_count); 21.1550 + this_klass->set_methods(_methods); 21.1551 + this_klass->set_inner_classes(_inner_classes); 21.1552 + this_klass->set_local_interfaces(_local_interfaces); 21.1553 + this_klass->set_transitive_interfaces(_transitive_interfaces); 21.1554 + 21.1555 + // Clear out these fields so they don't get deallocated by the destructor 21.1556 + clear_class_metadata(); 21.1557 +} 21.1558 + 21.1559 +AnnotationArray* ClassFileParser::assemble_annotations(u1* runtime_visible_annotations, 21.1560 int runtime_visible_annotations_length, 21.1561 u1* runtime_invisible_annotations, 21.1562 int runtime_invisible_annotations_length, TRAPS) { 21.1563 AnnotationArray* annotations = NULL; 21.1564 if (runtime_visible_annotations != NULL || 21.1565 runtime_invisible_annotations != NULL) { 21.1566 - annotations = MetadataFactory::new_array<u1>(loader_data, 21.1567 + annotations = MetadataFactory::new_array<u1>(_loader_data, 21.1568 runtime_visible_annotations_length + 21.1569 runtime_invisible_annotations_length, 21.1570 CHECK_(annotations)); 21.1571 @@ -3144,6 +3066,581 @@ 21.1572 #endif // ndef PRODUCT 21.1573 21.1574 21.1575 +instanceKlassHandle ClassFileParser::parse_super_class(int super_class_index, 21.1576 + TRAPS) { 21.1577 + instanceKlassHandle super_klass; 21.1578 + if (super_class_index == 0) { 21.1579 + check_property(_class_name == vmSymbols::java_lang_Object(), 21.1580 + "Invalid superclass index %u in class file %s", 21.1581 + super_class_index, 21.1582 + CHECK_NULL); 21.1583 + } else { 21.1584 + check_property(valid_klass_reference_at(super_class_index), 21.1585 + "Invalid superclass index %u in class file %s", 21.1586 + super_class_index, 21.1587 + CHECK_NULL); 21.1588 + // The class name should be legal because it is checked when parsing constant pool. 21.1589 + // However, make sure it is not an array type. 21.1590 + bool is_array = false; 21.1591 + if (_cp->tag_at(super_class_index).is_klass()) { 21.1592 + super_klass = instanceKlassHandle(THREAD, _cp->resolved_klass_at(super_class_index)); 21.1593 + if (_need_verify) 21.1594 + is_array = super_klass->oop_is_array(); 21.1595 + } else if (_need_verify) { 21.1596 + is_array = (_cp->unresolved_klass_at(super_class_index)->byte_at(0) == JVM_SIGNATURE_ARRAY); 21.1597 + } 21.1598 + if (_need_verify) { 21.1599 + guarantee_property(!is_array, 21.1600 + "Bad superclass name in class file %s", CHECK_NULL); 21.1601 + } 21.1602 + } 21.1603 + return super_klass; 21.1604 +} 21.1605 + 21.1606 + 21.1607 +// Values needed for oopmap and InstanceKlass creation 21.1608 +class FieldLayoutInfo : public StackObj { 21.1609 + public: 21.1610 + int* nonstatic_oop_offsets; 21.1611 + unsigned int* nonstatic_oop_counts; 21.1612 + unsigned int nonstatic_oop_map_count; 21.1613 + unsigned int total_oop_map_count; 21.1614 + int instance_size; 21.1615 + int nonstatic_field_size; 21.1616 + int static_field_size; 21.1617 + bool has_nonstatic_fields; 21.1618 +}; 21.1619 + 21.1620 +// Layout fields and fill in FieldLayoutInfo. Could use more refactoring! 21.1621 +void ClassFileParser::layout_fields(Handle class_loader, 21.1622 + FieldAllocationCount* fac, 21.1623 + ClassAnnotationCollector* parsed_annotations, 21.1624 + FieldLayoutInfo* info, 21.1625 + TRAPS) { 21.1626 + 21.1627 + // get the padding width from the option 21.1628 + // TODO: Ask VM about specific CPU we are running on 21.1629 + int pad_size = ContendedPaddingWidth; 21.1630 + 21.1631 + // Field size and offset computation 21.1632 + int nonstatic_field_size = _super_klass() == NULL ? 0 : _super_klass()->nonstatic_field_size(); 21.1633 +#ifndef PRODUCT 21.1634 + int orig_nonstatic_field_size = 0; 21.1635 +#endif 21.1636 + int next_static_oop_offset; 21.1637 + int next_static_double_offset; 21.1638 + int next_static_word_offset; 21.1639 + int next_static_short_offset; 21.1640 + int next_static_byte_offset; 21.1641 + int next_nonstatic_oop_offset; 21.1642 + int next_nonstatic_double_offset; 21.1643 + int next_nonstatic_word_offset; 21.1644 + int next_nonstatic_short_offset; 21.1645 + int next_nonstatic_byte_offset; 21.1646 + int next_nonstatic_type_offset; 21.1647 + int first_nonstatic_oop_offset; 21.1648 + int first_nonstatic_field_offset; 21.1649 + int next_nonstatic_field_offset; 21.1650 + int next_nonstatic_padded_offset; 21.1651 + 21.1652 + // Count the contended fields by type. 21.1653 + int nonstatic_contended_count = 0; 21.1654 + FieldAllocationCount fac_contended; 21.1655 + for (AllFieldStream fs(_fields, _cp); !fs.done(); fs.next()) { 21.1656 + FieldAllocationType atype = (FieldAllocationType) fs.allocation_type(); 21.1657 + if (fs.is_contended()) { 21.1658 + fac_contended.count[atype]++; 21.1659 + if (!fs.access_flags().is_static()) { 21.1660 + nonstatic_contended_count++; 21.1661 + } 21.1662 + } 21.1663 + } 21.1664 + int contended_count = nonstatic_contended_count; 21.1665 + 21.1666 + 21.1667 + // Calculate the starting byte offsets 21.1668 + next_static_oop_offset = InstanceMirrorKlass::offset_of_static_fields(); 21.1669 + next_static_double_offset = next_static_oop_offset + 21.1670 + ((fac->count[STATIC_OOP]) * heapOopSize); 21.1671 + if ( fac->count[STATIC_DOUBLE] && 21.1672 + (Universe::field_type_should_be_aligned(T_DOUBLE) || 21.1673 + Universe::field_type_should_be_aligned(T_LONG)) ) { 21.1674 + next_static_double_offset = align_size_up(next_static_double_offset, BytesPerLong); 21.1675 + } 21.1676 + 21.1677 + next_static_word_offset = next_static_double_offset + 21.1678 + ((fac->count[STATIC_DOUBLE]) * BytesPerLong); 21.1679 + next_static_short_offset = next_static_word_offset + 21.1680 + ((fac->count[STATIC_WORD]) * BytesPerInt); 21.1681 + next_static_byte_offset = next_static_short_offset + 21.1682 + ((fac->count[STATIC_SHORT]) * BytesPerShort); 21.1683 + 21.1684 + first_nonstatic_field_offset = instanceOopDesc::base_offset_in_bytes() + 21.1685 + nonstatic_field_size * heapOopSize; 21.1686 + 21.1687 + // class is contended, pad before all the fields 21.1688 + if (parsed_annotations->is_contended()) { 21.1689 + first_nonstatic_field_offset += pad_size; 21.1690 + } 21.1691 + 21.1692 + next_nonstatic_field_offset = first_nonstatic_field_offset; 21.1693 + 21.1694 + unsigned int nonstatic_double_count = fac->count[NONSTATIC_DOUBLE] - fac_contended.count[NONSTATIC_DOUBLE]; 21.1695 + unsigned int nonstatic_word_count = fac->count[NONSTATIC_WORD] - fac_contended.count[NONSTATIC_WORD]; 21.1696 + unsigned int nonstatic_short_count = fac->count[NONSTATIC_SHORT] - fac_contended.count[NONSTATIC_SHORT]; 21.1697 + unsigned int nonstatic_byte_count = fac->count[NONSTATIC_BYTE] - fac_contended.count[NONSTATIC_BYTE]; 21.1698 + unsigned int nonstatic_oop_count = fac->count[NONSTATIC_OOP] - fac_contended.count[NONSTATIC_OOP]; 21.1699 + 21.1700 + bool super_has_nonstatic_fields = 21.1701 + (_super_klass() != NULL && _super_klass->has_nonstatic_fields()); 21.1702 + bool has_nonstatic_fields = super_has_nonstatic_fields || 21.1703 + ((nonstatic_double_count + nonstatic_word_count + 21.1704 + nonstatic_short_count + nonstatic_byte_count + 21.1705 + nonstatic_oop_count) != 0); 21.1706 + 21.1707 + 21.1708 + // Prepare list of oops for oop map generation. 21.1709 + int* nonstatic_oop_offsets; 21.1710 + unsigned int* nonstatic_oop_counts; 21.1711 + unsigned int nonstatic_oop_map_count = 0; 21.1712 + 21.1713 + nonstatic_oop_offsets = NEW_RESOURCE_ARRAY_IN_THREAD( 21.1714 + THREAD, int, nonstatic_oop_count + 1); 21.1715 + nonstatic_oop_counts = NEW_RESOURCE_ARRAY_IN_THREAD( 21.1716 + THREAD, unsigned int, nonstatic_oop_count + 1); 21.1717 + 21.1718 + first_nonstatic_oop_offset = 0; // will be set for first oop field 21.1719 + 21.1720 +#ifndef PRODUCT 21.1721 + if( PrintCompactFieldsSavings ) { 21.1722 + next_nonstatic_double_offset = next_nonstatic_field_offset + 21.1723 + (nonstatic_oop_count * heapOopSize); 21.1724 + if ( nonstatic_double_count > 0 ) { 21.1725 + next_nonstatic_double_offset = align_size_up(next_nonstatic_double_offset, BytesPerLong); 21.1726 + } 21.1727 + next_nonstatic_word_offset = next_nonstatic_double_offset + 21.1728 + (nonstatic_double_count * BytesPerLong); 21.1729 + next_nonstatic_short_offset = next_nonstatic_word_offset + 21.1730 + (nonstatic_word_count * BytesPerInt); 21.1731 + next_nonstatic_byte_offset = next_nonstatic_short_offset + 21.1732 + (nonstatic_short_count * BytesPerShort); 21.1733 + next_nonstatic_type_offset = align_size_up((next_nonstatic_byte_offset + 21.1734 + nonstatic_byte_count ), heapOopSize ); 21.1735 + orig_nonstatic_field_size = nonstatic_field_size + 21.1736 + ((next_nonstatic_type_offset - first_nonstatic_field_offset)/heapOopSize); 21.1737 + } 21.1738 +#endif 21.1739 + bool compact_fields = CompactFields; 21.1740 + int allocation_style = FieldsAllocationStyle; 21.1741 + if( allocation_style < 0 || allocation_style > 2 ) { // Out of range? 21.1742 + assert(false, "0 <= FieldsAllocationStyle <= 2"); 21.1743 + allocation_style = 1; // Optimistic 21.1744 + } 21.1745 + 21.1746 + // The next classes have predefined hard-coded fields offsets 21.1747 + // (see in JavaClasses::compute_hard_coded_offsets()). 21.1748 + // Use default fields allocation order for them. 21.1749 + if( (allocation_style != 0 || compact_fields ) && class_loader.is_null() && 21.1750 + (_class_name == vmSymbols::java_lang_AssertionStatusDirectives() || 21.1751 + _class_name == vmSymbols::java_lang_Class() || 21.1752 + _class_name == vmSymbols::java_lang_ClassLoader() || 21.1753 + _class_name == vmSymbols::java_lang_ref_Reference() || 21.1754 + _class_name == vmSymbols::java_lang_ref_SoftReference() || 21.1755 + _class_name == vmSymbols::java_lang_StackTraceElement() || 21.1756 + _class_name == vmSymbols::java_lang_String() || 21.1757 + _class_name == vmSymbols::java_lang_Throwable() || 21.1758 + _class_name == vmSymbols::java_lang_Boolean() || 21.1759 + _class_name == vmSymbols::java_lang_Character() || 21.1760 + _class_name == vmSymbols::java_lang_Float() || 21.1761 + _class_name == vmSymbols::java_lang_Double() || 21.1762 + _class_name == vmSymbols::java_lang_Byte() || 21.1763 + _class_name == vmSymbols::java_lang_Short() || 21.1764 + _class_name == vmSymbols::java_lang_Integer() || 21.1765 + _class_name == vmSymbols::java_lang_Long())) { 21.1766 + allocation_style = 0; // Allocate oops first 21.1767 + compact_fields = false; // Don't compact fields 21.1768 + } 21.1769 + 21.1770 + if( allocation_style == 0 ) { 21.1771 + // Fields order: oops, longs/doubles, ints, shorts/chars, bytes, padded fields 21.1772 + next_nonstatic_oop_offset = next_nonstatic_field_offset; 21.1773 + next_nonstatic_double_offset = next_nonstatic_oop_offset + 21.1774 + (nonstatic_oop_count * heapOopSize); 21.1775 + } else if( allocation_style == 1 ) { 21.1776 + // Fields order: longs/doubles, ints, shorts/chars, bytes, oops, padded fields 21.1777 + next_nonstatic_double_offset = next_nonstatic_field_offset; 21.1778 + } else if( allocation_style == 2 ) { 21.1779 + // Fields allocation: oops fields in super and sub classes are together. 21.1780 + if( nonstatic_field_size > 0 && _super_klass() != NULL && 21.1781 + _super_klass->nonstatic_oop_map_size() > 0 ) { 21.1782 + unsigned int map_count = _super_klass->nonstatic_oop_map_count(); 21.1783 + OopMapBlock* first_map = _super_klass->start_of_nonstatic_oop_maps(); 21.1784 + OopMapBlock* last_map = first_map + map_count - 1; 21.1785 + int next_offset = last_map->offset() + (last_map->count() * heapOopSize); 21.1786 + if (next_offset == next_nonstatic_field_offset) { 21.1787 + allocation_style = 0; // allocate oops first 21.1788 + next_nonstatic_oop_offset = next_nonstatic_field_offset; 21.1789 + next_nonstatic_double_offset = next_nonstatic_oop_offset + 21.1790 + (nonstatic_oop_count * heapOopSize); 21.1791 + } 21.1792 + } 21.1793 + if( allocation_style == 2 ) { 21.1794 + allocation_style = 1; // allocate oops last 21.1795 + next_nonstatic_double_offset = next_nonstatic_field_offset; 21.1796 + } 21.1797 + } else { 21.1798 + ShouldNotReachHere(); 21.1799 + } 21.1800 + 21.1801 + int nonstatic_oop_space_count = 0; 21.1802 + int nonstatic_word_space_count = 0; 21.1803 + int nonstatic_short_space_count = 0; 21.1804 + int nonstatic_byte_space_count = 0; 21.1805 + int nonstatic_oop_space_offset; 21.1806 + int nonstatic_word_space_offset; 21.1807 + int nonstatic_short_space_offset; 21.1808 + int nonstatic_byte_space_offset; 21.1809 + 21.1810 + if( nonstatic_double_count > 0 ) { 21.1811 + int offset = next_nonstatic_double_offset; 21.1812 + next_nonstatic_double_offset = align_size_up(offset, BytesPerLong); 21.1813 + if( compact_fields && offset != next_nonstatic_double_offset ) { 21.1814 + // Allocate available fields into the gap before double field. 21.1815 + int length = next_nonstatic_double_offset - offset; 21.1816 + assert(length == BytesPerInt, ""); 21.1817 + nonstatic_word_space_offset = offset; 21.1818 + if( nonstatic_word_count > 0 ) { 21.1819 + nonstatic_word_count -= 1; 21.1820 + nonstatic_word_space_count = 1; // Only one will fit 21.1821 + length -= BytesPerInt; 21.1822 + offset += BytesPerInt; 21.1823 + } 21.1824 + nonstatic_short_space_offset = offset; 21.1825 + while( length >= BytesPerShort && nonstatic_short_count > 0 ) { 21.1826 + nonstatic_short_count -= 1; 21.1827 + nonstatic_short_space_count += 1; 21.1828 + length -= BytesPerShort; 21.1829 + offset += BytesPerShort; 21.1830 + } 21.1831 + nonstatic_byte_space_offset = offset; 21.1832 + while( length > 0 && nonstatic_byte_count > 0 ) { 21.1833 + nonstatic_byte_count -= 1; 21.1834 + nonstatic_byte_space_count += 1; 21.1835 + length -= 1; 21.1836 + } 21.1837 + // Allocate oop field in the gap if there are no other fields for that. 21.1838 + nonstatic_oop_space_offset = offset; 21.1839 + if( length >= heapOopSize && nonstatic_oop_count > 0 && 21.1840 + allocation_style != 0 ) { // when oop fields not first 21.1841 + nonstatic_oop_count -= 1; 21.1842 + nonstatic_oop_space_count = 1; // Only one will fit 21.1843 + length -= heapOopSize; 21.1844 + offset += heapOopSize; 21.1845 + } 21.1846 + } 21.1847 + } 21.1848 + 21.1849 + next_nonstatic_word_offset = next_nonstatic_double_offset + 21.1850 + (nonstatic_double_count * BytesPerLong); 21.1851 + next_nonstatic_short_offset = next_nonstatic_word_offset + 21.1852 + (nonstatic_word_count * BytesPerInt); 21.1853 + next_nonstatic_byte_offset = next_nonstatic_short_offset + 21.1854 + (nonstatic_short_count * BytesPerShort); 21.1855 + next_nonstatic_padded_offset = next_nonstatic_byte_offset + 21.1856 + nonstatic_byte_count; 21.1857 + 21.1858 + // let oops jump before padding with this allocation style 21.1859 + if( allocation_style == 1 ) { 21.1860 + next_nonstatic_oop_offset = next_nonstatic_padded_offset; 21.1861 + if( nonstatic_oop_count > 0 ) { 21.1862 + next_nonstatic_oop_offset = align_size_up(next_nonstatic_oop_offset, heapOopSize); 21.1863 + } 21.1864 + next_nonstatic_padded_offset = next_nonstatic_oop_offset + (nonstatic_oop_count * heapOopSize); 21.1865 + } 21.1866 + 21.1867 + // Iterate over fields again and compute correct offsets. 21.1868 + // The field allocation type was temporarily stored in the offset slot. 21.1869 + // oop fields are located before non-oop fields (static and non-static). 21.1870 + for (AllFieldStream fs(_fields, _cp); !fs.done(); fs.next()) { 21.1871 + 21.1872 + // skip already laid out fields 21.1873 + if (fs.is_offset_set()) continue; 21.1874 + 21.1875 + // contended instance fields are handled below 21.1876 + if (fs.is_contended() && !fs.access_flags().is_static()) continue; 21.1877 + 21.1878 + int real_offset; 21.1879 + FieldAllocationType atype = (FieldAllocationType) fs.allocation_type(); 21.1880 + 21.1881 + // pack the rest of the fields 21.1882 + switch (atype) { 21.1883 + case STATIC_OOP: 21.1884 + real_offset = next_static_oop_offset; 21.1885 + next_static_oop_offset += heapOopSize; 21.1886 + break; 21.1887 + case STATIC_BYTE: 21.1888 + real_offset = next_static_byte_offset; 21.1889 + next_static_byte_offset += 1; 21.1890 + break; 21.1891 + case STATIC_SHORT: 21.1892 + real_offset = next_static_short_offset; 21.1893 + next_static_short_offset += BytesPerShort; 21.1894 + break; 21.1895 + case STATIC_WORD: 21.1896 + real_offset = next_static_word_offset; 21.1897 + next_static_word_offset += BytesPerInt; 21.1898 + break; 21.1899 + case STATIC_DOUBLE: 21.1900 + real_offset = next_static_double_offset; 21.1901 + next_static_double_offset += BytesPerLong; 21.1902 + break; 21.1903 + case NONSTATIC_OOP: 21.1904 + if( nonstatic_oop_space_count > 0 ) { 21.1905 + real_offset = nonstatic_oop_space_offset; 21.1906 + nonstatic_oop_space_offset += heapOopSize; 21.1907 + nonstatic_oop_space_count -= 1; 21.1908 + } else { 21.1909 + real_offset = next_nonstatic_oop_offset; 21.1910 + next_nonstatic_oop_offset += heapOopSize; 21.1911 + } 21.1912 + // Update oop maps 21.1913 + if( nonstatic_oop_map_count > 0 && 21.1914 + nonstatic_oop_offsets[nonstatic_oop_map_count - 1] == 21.1915 + real_offset - 21.1916 + int(nonstatic_oop_counts[nonstatic_oop_map_count - 1]) * 21.1917 + heapOopSize ) { 21.1918 + // Extend current oop map 21.1919 + nonstatic_oop_counts[nonstatic_oop_map_count - 1] += 1; 21.1920 + } else { 21.1921 + // Create new oop map 21.1922 + nonstatic_oop_offsets[nonstatic_oop_map_count] = real_offset; 21.1923 + nonstatic_oop_counts [nonstatic_oop_map_count] = 1; 21.1924 + nonstatic_oop_map_count += 1; 21.1925 + if( first_nonstatic_oop_offset == 0 ) { // Undefined 21.1926 + first_nonstatic_oop_offset = real_offset; 21.1927 + } 21.1928 + } 21.1929 + break; 21.1930 + case NONSTATIC_BYTE: 21.1931 + if( nonstatic_byte_space_count > 0 ) { 21.1932 + real_offset = nonstatic_byte_space_offset; 21.1933 + nonstatic_byte_space_offset += 1; 21.1934 + nonstatic_byte_space_count -= 1; 21.1935 + } else { 21.1936 + real_offset = next_nonstatic_byte_offset; 21.1937 + next_nonstatic_byte_offset += 1; 21.1938 + } 21.1939 + break; 21.1940 + case NONSTATIC_SHORT: 21.1941 + if( nonstatic_short_space_count > 0 ) { 21.1942 + real_offset = nonstatic_short_space_offset; 21.1943 + nonstatic_short_space_offset += BytesPerShort; 21.1944 + nonstatic_short_space_count -= 1; 21.1945 + } else { 21.1946 + real_offset = next_nonstatic_short_offset; 21.1947 + next_nonstatic_short_offset += BytesPerShort; 21.1948 + } 21.1949 + break; 21.1950 + case NONSTATIC_WORD: 21.1951 + if( nonstatic_word_space_count > 0 ) { 21.1952 + real_offset = nonstatic_word_space_offset; 21.1953 + nonstatic_word_space_offset += BytesPerInt; 21.1954 + nonstatic_word_space_count -= 1; 21.1955 + } else { 21.1956 + real_offset = next_nonstatic_word_offset; 21.1957 + next_nonstatic_word_offset += BytesPerInt; 21.1958 + } 21.1959 + break; 21.1960 + case NONSTATIC_DOUBLE: 21.1961 + real_offset = next_nonstatic_double_offset; 21.1962 + next_nonstatic_double_offset += BytesPerLong; 21.1963 + break; 21.1964 + default: 21.1965 + ShouldNotReachHere(); 21.1966 + } 21.1967 + fs.set_offset(real_offset); 21.1968 + } 21.1969 + 21.1970 + 21.1971 + // Handle the contended cases. 21.1972 + // 21.1973 + // Each contended field should not intersect the cache line with another contended field. 21.1974 + // In the absence of alignment information, we end up with pessimistically separating 21.1975 + // the fields with full-width padding. 21.1976 + // 21.1977 + // Additionally, this should not break alignment for the fields, so we round the alignment up 21.1978 + // for each field. 21.1979 + if (contended_count > 0) { 21.1980 + 21.1981 + // if there is at least one contended field, we need to have pre-padding for them 21.1982 + if (nonstatic_contended_count > 0) { 21.1983 + next_nonstatic_padded_offset += pad_size; 21.1984 + } 21.1985 + 21.1986 + // collect all contended groups 21.1987 + BitMap bm(_cp->size()); 21.1988 + for (AllFieldStream fs(_fields, _cp); !fs.done(); fs.next()) { 21.1989 + // skip already laid out fields 21.1990 + if (fs.is_offset_set()) continue; 21.1991 + 21.1992 + if (fs.is_contended()) { 21.1993 + bm.set_bit(fs.contended_group()); 21.1994 + } 21.1995 + } 21.1996 + 21.1997 + int current_group = -1; 21.1998 + while ((current_group = (int)bm.get_next_one_offset(current_group + 1)) != (int)bm.size()) { 21.1999 + 21.2000 + for (AllFieldStream fs(_fields, _cp); !fs.done(); fs.next()) { 21.2001 + 21.2002 + // skip already laid out fields 21.2003 + if (fs.is_offset_set()) continue; 21.2004 + 21.2005 + // skip non-contended fields and fields from different group 21.2006 + if (!fs.is_contended() || (fs.contended_group() != current_group)) continue; 21.2007 + 21.2008 + // handle statics below 21.2009 + if (fs.access_flags().is_static()) continue; 21.2010 + 21.2011 + int real_offset; 21.2012 + FieldAllocationType atype = (FieldAllocationType) fs.allocation_type(); 21.2013 + 21.2014 + switch (atype) { 21.2015 + case NONSTATIC_BYTE: 21.2016 + next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, 1); 21.2017 + real_offset = next_nonstatic_padded_offset; 21.2018 + next_nonstatic_padded_offset += 1; 21.2019 + break; 21.2020 + 21.2021 + case NONSTATIC_SHORT: 21.2022 + next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, BytesPerShort); 21.2023 + real_offset = next_nonstatic_padded_offset; 21.2024 + next_nonstatic_padded_offset += BytesPerShort; 21.2025 + break; 21.2026 + 21.2027 + case NONSTATIC_WORD: 21.2028 + next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, BytesPerInt); 21.2029 + real_offset = next_nonstatic_padded_offset; 21.2030 + next_nonstatic_padded_offset += BytesPerInt; 21.2031 + break; 21.2032 + 21.2033 + case NONSTATIC_DOUBLE: 21.2034 + next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, BytesPerLong); 21.2035 + real_offset = next_nonstatic_padded_offset; 21.2036 + next_nonstatic_padded_offset += BytesPerLong; 21.2037 + break; 21.2038 + 21.2039 + case NONSTATIC_OOP: 21.2040 + next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, heapOopSize); 21.2041 + real_offset = next_nonstatic_padded_offset; 21.2042 + next_nonstatic_padded_offset += heapOopSize; 21.2043 + 21.2044 + // Create new oop map 21.2045 + nonstatic_oop_offsets[nonstatic_oop_map_count] = real_offset; 21.2046 + nonstatic_oop_counts [nonstatic_oop_map_count] = 1; 21.2047 + nonstatic_oop_map_count += 1; 21.2048 + if( first_nonstatic_oop_offset == 0 ) { // Undefined 21.2049 + first_nonstatic_oop_offset = real_offset; 21.2050 + } 21.2051 + break; 21.2052 + 21.2053 + default: 21.2054 + ShouldNotReachHere(); 21.2055 + } 21.2056 + 21.2057 + if (fs.contended_group() == 0) { 21.2058 + // Contended group defines the equivalence class over the fields: 21.2059 + // the fields within the same contended group are not inter-padded. 21.2060 + // The only exception is default group, which does not incur the 21.2061 + // equivalence, and so requires intra-padding. 21.2062 + next_nonstatic_padded_offset += pad_size; 21.2063 + } 21.2064 + 21.2065 + fs.set_offset(real_offset); 21.2066 + } // for 21.2067 + 21.2068 + // Start laying out the next group. 21.2069 + // Note that this will effectively pad the last group in the back; 21.2070 + // this is expected to alleviate memory contention effects for 21.2071 + // subclass fields and/or adjacent object. 21.2072 + // If this was the default group, the padding is already in place. 21.2073 + if (current_group != 0) { 21.2074 + next_nonstatic_padded_offset += pad_size; 21.2075 + } 21.2076 + } 21.2077 + 21.2078 + // handle static fields 21.2079 + } 21.2080 + 21.2081 + // Size of instances 21.2082 + int notaligned_offset = next_nonstatic_padded_offset; 21.2083 + 21.2084 + // Entire class is contended, pad in the back. 21.2085 + // This helps to alleviate memory contention effects for subclass fields 21.2086 + // and/or adjacent object. 21.2087 + if (parsed_annotations->is_contended()) { 21.2088 + notaligned_offset += pad_size; 21.2089 + } 21.2090 + 21.2091 + int next_static_type_offset = align_size_up(next_static_byte_offset, wordSize); 21.2092 + int static_field_size = (next_static_type_offset - 21.2093 + InstanceMirrorKlass::offset_of_static_fields()) / wordSize; 21.2094 + 21.2095 + next_nonstatic_type_offset = align_size_up(notaligned_offset, heapOopSize ); 21.2096 + nonstatic_field_size = nonstatic_field_size + ((next_nonstatic_type_offset 21.2097 + - first_nonstatic_field_offset)/heapOopSize); 21.2098 + 21.2099 + next_nonstatic_type_offset = align_size_up(notaligned_offset, wordSize ); 21.2100 + int instance_size = align_object_size(next_nonstatic_type_offset / wordSize); 21.2101 + 21.2102 + assert(instance_size == align_object_size(align_size_up( 21.2103 + (instanceOopDesc::base_offset_in_bytes() + nonstatic_field_size*heapOopSize + ((parsed_annotations->is_contended()) ? pad_size : 0)), 21.2104 + wordSize) / wordSize), "consistent layout helper value"); 21.2105 + 21.2106 + // Number of non-static oop map blocks allocated at end of klass. 21.2107 + const unsigned int total_oop_map_count = 21.2108 + compute_oop_map_count(_super_klass, nonstatic_oop_map_count, 21.2109 + first_nonstatic_oop_offset); 21.2110 + 21.2111 +#ifndef PRODUCT 21.2112 + if( PrintCompactFieldsSavings ) { 21.2113 + ResourceMark rm; 21.2114 + if( nonstatic_field_size < orig_nonstatic_field_size ) { 21.2115 + tty->print("[Saved %d of %d bytes in %s]\n", 21.2116 + (orig_nonstatic_field_size - nonstatic_field_size)*heapOopSize, 21.2117 + orig_nonstatic_field_size*heapOopSize, 21.2118 + _class_name); 21.2119 + } else if( nonstatic_field_size > orig_nonstatic_field_size ) { 21.2120 + tty->print("[Wasted %d over %d bytes in %s]\n", 21.2121 + (nonstatic_field_size - orig_nonstatic_field_size)*heapOopSize, 21.2122 + orig_nonstatic_field_size*heapOopSize, 21.2123 + _class_name); 21.2124 + } 21.2125 + } 21.2126 + 21.2127 + if (PrintFieldLayout) { 21.2128 + print_field_layout(_class_name, 21.2129 + _fields, 21.2130 + _cp, 21.2131 + instance_size, 21.2132 + first_nonstatic_field_offset, 21.2133 + next_nonstatic_field_offset, 21.2134 + next_static_type_offset); 21.2135 + } 21.2136 + 21.2137 +#endif 21.2138 + // Pass back information needed for InstanceKlass creation 21.2139 + info->nonstatic_oop_offsets = nonstatic_oop_offsets; 21.2140 + info->nonstatic_oop_counts = nonstatic_oop_counts; 21.2141 + info->nonstatic_oop_map_count = nonstatic_oop_map_count; 21.2142 + info->total_oop_map_count = total_oop_map_count; 21.2143 + info->instance_size = instance_size; 21.2144 + info->static_field_size = static_field_size; 21.2145 + info->nonstatic_field_size = nonstatic_field_size; 21.2146 + info->has_nonstatic_fields = has_nonstatic_fields; 21.2147 +} 21.2148 + 21.2149 + 21.2150 instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name, 21.2151 ClassLoaderData* loader_data, 21.2152 Handle protection_domain, 21.2153 @@ -3176,7 +3673,7 @@ 21.2154 jt->get_thread_stat()->perf_timers_addr(), 21.2155 PerfClassTraceTime::PARSE_CLASS); 21.2156 21.2157 - init_parsed_class_attributes(); 21.2158 + init_parsed_class_attributes(loader_data); 21.2159 21.2160 if (JvmtiExport::should_post_class_file_load_hook()) { 21.2161 // Get the cached class file bytes (if any) from the class that 21.2162 @@ -3271,8 +3768,7 @@ 21.2163 _relax_verify = Verifier::relax_verify_for(class_loader()); 21.2164 21.2165 // Constant pool 21.2166 - constantPoolHandle cp = parse_constant_pool(loader_data, CHECK_(nullHandle)); 21.2167 - ConstantPoolCleaner error_handler(cp); // set constant pool to be cleaned up. 21.2168 + constantPoolHandle cp = parse_constant_pool(CHECK_(nullHandle)); 21.2169 21.2170 int cp_size = cp->length(); 21.2171 21.2172 @@ -3290,7 +3786,6 @@ 21.2173 access_flags.set_flags(flags); 21.2174 21.2175 // This class and superclass 21.2176 - instanceKlassHandle super_klass; 21.2177 u2 this_class_index = cfs->get_u2_fast(); 21.2178 check_property( 21.2179 valid_cp_range(this_class_index, cp_size) && 21.2180 @@ -3345,59 +3840,27 @@ 21.2181 } 21.2182 21.2183 u2 super_class_index = cfs->get_u2_fast(); 21.2184 - if (super_class_index == 0) { 21.2185 - check_property(class_name == vmSymbols::java_lang_Object(), 21.2186 - "Invalid superclass index %u in class file %s", 21.2187 - super_class_index, 21.2188 - CHECK_(nullHandle)); 21.2189 - } else { 21.2190 - check_property(valid_cp_range(super_class_index, cp_size) && 21.2191 - is_klass_reference(cp, super_class_index), 21.2192 - "Invalid superclass index %u in class file %s", 21.2193 - super_class_index, 21.2194 - CHECK_(nullHandle)); 21.2195 - // The class name should be legal because it is checked when parsing constant pool. 21.2196 - // However, make sure it is not an array type. 21.2197 - bool is_array = false; 21.2198 - if (cp->tag_at(super_class_index).is_klass()) { 21.2199 - super_klass = instanceKlassHandle(THREAD, cp->resolved_klass_at(super_class_index)); 21.2200 - if (_need_verify) 21.2201 - is_array = super_klass->oop_is_array(); 21.2202 - } else if (_need_verify) { 21.2203 - is_array = (cp->unresolved_klass_at(super_class_index)->byte_at(0) == JVM_SIGNATURE_ARRAY); 21.2204 - } 21.2205 - if (_need_verify) { 21.2206 - guarantee_property(!is_array, 21.2207 - "Bad superclass name in class file %s", CHECK_(nullHandle)); 21.2208 - } 21.2209 - } 21.2210 + instanceKlassHandle super_klass = parse_super_class(super_class_index, 21.2211 + CHECK_NULL); 21.2212 21.2213 // Interfaces 21.2214 u2 itfs_len = cfs->get_u2_fast(); 21.2215 - Array<Klass*>* local_interfaces; 21.2216 - if (itfs_len == 0) { 21.2217 - local_interfaces = Universe::the_empty_klass_array(); 21.2218 - } else { 21.2219 - local_interfaces = parse_interfaces( 21.2220 - cp, itfs_len, loader_data, protection_domain, _class_name, 21.2221 - &has_default_methods, CHECK_(nullHandle)); 21.2222 - } 21.2223 + Array<Klass*>* local_interfaces = 21.2224 + parse_interfaces(itfs_len, protection_domain, _class_name, 21.2225 + &has_default_methods, CHECK_(nullHandle)); 21.2226 21.2227 u2 java_fields_count = 0; 21.2228 // Fields (offsets are filled in later) 21.2229 FieldAllocationCount fac; 21.2230 - Array<AnnotationArray*>* fields_annotations = NULL; 21.2231 - Array<AnnotationArray*>* fields_type_annotations = NULL; 21.2232 - Array<u2>* fields = parse_fields(loader_data, class_name, cp, access_flags.is_interface(), &fac, &fields_annotations, 21.2233 - &fields_type_annotations, 21.2234 - &java_fields_count, 21.2235 - CHECK_(nullHandle)); 21.2236 + Array<u2>* fields = parse_fields(class_name, 21.2237 + access_flags.is_interface(), 21.2238 + &fac, &java_fields_count, 21.2239 + CHECK_(nullHandle)); 21.2240 // Methods 21.2241 bool has_final_method = false; 21.2242 AccessFlags promoted_flags; 21.2243 promoted_flags.set_flags(0); 21.2244 - Array<Method*>* methods = parse_methods(loader_data, 21.2245 - cp, access_flags.is_interface(), 21.2246 + Array<Method*>* methods = parse_methods(access_flags.is_interface(), 21.2247 &promoted_flags, 21.2248 &has_final_method, 21.2249 &has_default_methods, 21.2250 @@ -3405,7 +3868,7 @@ 21.2251 21.2252 // Additional attributes 21.2253 ClassAnnotationCollector parsed_annotations; 21.2254 - parse_classfile_attributes(loader_data, cp, &parsed_annotations, CHECK_(nullHandle)); 21.2255 + parse_classfile_attributes(&parsed_annotations, CHECK_(nullHandle)); 21.2256 21.2257 // Make sure this is the end of class file stream 21.2258 guarantee_property(cfs->at_eos(), "Extra bytes at the end of class file %s", CHECK_(nullHandle)); 21.2259 @@ -3452,13 +3915,15 @@ 21.2260 } 21.2261 } 21.2262 21.2263 + // save super klass for error handling. 21.2264 + _super_klass = super_klass; 21.2265 + 21.2266 // Compute the transitive list of all unique interfaces implemented by this class 21.2267 - Array<Klass*>* transitive_interfaces = compute_transitive_interfaces(loader_data, super_klass, local_interfaces, CHECK_(nullHandle)); 21.2268 + _transitive_interfaces = 21.2269 + compute_transitive_interfaces(super_klass, local_interfaces, CHECK_(nullHandle)); 21.2270 21.2271 // sort methods 21.2272 - Array<int>* method_ordering = sort_methods(loader_data, 21.2273 - methods, 21.2274 - CHECK_(nullHandle)); 21.2275 + intArray* method_ordering = sort_methods(methods); 21.2276 21.2277 // promote flags from parse_methods() to the klass' flags 21.2278 access_flags.add_promoted_flags(promoted_flags.as_int()); 21.2279 @@ -3476,587 +3941,14 @@ 21.2280 CHECK_(nullHandle)); 21.2281 21.2282 // Size of Java itable (in words) 21.2283 - itable_size = access_flags.is_interface() ? 0 : klassItable::compute_itable_size(transitive_interfaces); 21.2284 - 21.2285 - // get the padding width from the option 21.2286 - // TODO: Ask VM about specific CPU we are running on 21.2287 - int pad_size = ContendedPaddingWidth; 21.2288 - 21.2289 - // Field size and offset computation 21.2290 - int nonstatic_field_size = super_klass() == NULL ? 0 : super_klass->nonstatic_field_size(); 21.2291 -#ifndef PRODUCT 21.2292 - int orig_nonstatic_field_size = 0; 21.2293 -#endif 21.2294 - int next_static_oop_offset; 21.2295 - int next_static_double_offset; 21.2296 - int next_static_word_offset; 21.2297 - int next_static_short_offset; 21.2298 - int next_static_byte_offset; 21.2299 - int next_static_padded_offset; 21.2300 - int next_nonstatic_oop_offset; 21.2301 - int next_nonstatic_double_offset; 21.2302 - int next_nonstatic_word_offset; 21.2303 - int next_nonstatic_short_offset; 21.2304 - int next_nonstatic_byte_offset; 21.2305 - int next_nonstatic_type_offset; 21.2306 - int first_nonstatic_oop_offset; 21.2307 - int first_nonstatic_field_offset; 21.2308 - int next_nonstatic_field_offset; 21.2309 - int next_nonstatic_padded_offset; 21.2310 - 21.2311 - // Count the contended fields by type. 21.2312 - int static_contended_count = 0; 21.2313 - int nonstatic_contended_count = 0; 21.2314 - FieldAllocationCount fac_contended; 21.2315 - for (AllFieldStream fs(fields, cp); !fs.done(); fs.next()) { 21.2316 - FieldAllocationType atype = (FieldAllocationType) fs.allocation_type(); 21.2317 - if (fs.is_contended()) { 21.2318 - fac_contended.count[atype]++; 21.2319 - if (fs.access_flags().is_static()) { 21.2320 - static_contended_count++; 21.2321 - } else { 21.2322 - nonstatic_contended_count++; 21.2323 - } 21.2324 - } 21.2325 - } 21.2326 - int contended_count = static_contended_count + nonstatic_contended_count; 21.2327 - 21.2328 - 21.2329 - // Calculate the starting byte offsets 21.2330 - next_static_oop_offset = InstanceMirrorKlass::offset_of_static_fields(); 21.2331 - 21.2332 - // class is contended, pad before all the fields 21.2333 - if (parsed_annotations.is_contended()) { 21.2334 - next_static_oop_offset += pad_size; 21.2335 - } 21.2336 - 21.2337 - next_static_double_offset = next_static_oop_offset + 21.2338 - ((fac.count[STATIC_OOP] - fac_contended.count[STATIC_OOP]) * heapOopSize); 21.2339 - if ( fac.count[STATIC_DOUBLE] && 21.2340 - (Universe::field_type_should_be_aligned(T_DOUBLE) || 21.2341 - Universe::field_type_should_be_aligned(T_LONG)) ) { 21.2342 - next_static_double_offset = align_size_up(next_static_double_offset, BytesPerLong); 21.2343 - } 21.2344 - 21.2345 - next_static_word_offset = next_static_double_offset + 21.2346 - ((fac.count[STATIC_DOUBLE] - fac_contended.count[STATIC_DOUBLE]) * BytesPerLong); 21.2347 - next_static_short_offset = next_static_word_offset + 21.2348 - ((fac.count[STATIC_WORD] - fac_contended.count[STATIC_WORD]) * BytesPerInt); 21.2349 - next_static_byte_offset = next_static_short_offset + 21.2350 - ((fac.count[STATIC_SHORT] - fac_contended.count[STATIC_SHORT]) * BytesPerShort); 21.2351 - next_static_padded_offset = next_static_byte_offset + 21.2352 - ((fac.count[STATIC_BYTE] - fac_contended.count[STATIC_BYTE]) * 1); 21.2353 - 21.2354 - first_nonstatic_field_offset = instanceOopDesc::base_offset_in_bytes() + 21.2355 - nonstatic_field_size * heapOopSize; 21.2356 - 21.2357 - // class is contended, pad before all the fields 21.2358 - if (parsed_annotations.is_contended()) { 21.2359 - first_nonstatic_field_offset += pad_size; 21.2360 - } 21.2361 - 21.2362 - next_nonstatic_field_offset = first_nonstatic_field_offset; 21.2363 - 21.2364 - unsigned int nonstatic_double_count = fac.count[NONSTATIC_DOUBLE] - fac_contended.count[NONSTATIC_DOUBLE]; 21.2365 - unsigned int nonstatic_word_count = fac.count[NONSTATIC_WORD] - fac_contended.count[NONSTATIC_WORD]; 21.2366 - unsigned int nonstatic_short_count = fac.count[NONSTATIC_SHORT] - fac_contended.count[NONSTATIC_SHORT]; 21.2367 - unsigned int nonstatic_byte_count = fac.count[NONSTATIC_BYTE] - fac_contended.count[NONSTATIC_BYTE]; 21.2368 - unsigned int nonstatic_oop_count = fac.count[NONSTATIC_OOP] - fac_contended.count[NONSTATIC_OOP]; 21.2369 - 21.2370 - bool super_has_nonstatic_fields = 21.2371 - (super_klass() != NULL && super_klass->has_nonstatic_fields()); 21.2372 - bool has_nonstatic_fields = super_has_nonstatic_fields || 21.2373 - ((nonstatic_double_count + nonstatic_word_count + 21.2374 - nonstatic_short_count + nonstatic_byte_count + 21.2375 - nonstatic_oop_count) != 0); 21.2376 - 21.2377 - 21.2378 - // Prepare list of oops for oop map generation. 21.2379 - int* nonstatic_oop_offsets; 21.2380 - unsigned int* nonstatic_oop_counts; 21.2381 - unsigned int nonstatic_oop_map_count = 0; 21.2382 - 21.2383 - nonstatic_oop_offsets = NEW_RESOURCE_ARRAY_IN_THREAD( 21.2384 - THREAD, int, nonstatic_oop_count + 1); 21.2385 - nonstatic_oop_counts = NEW_RESOURCE_ARRAY_IN_THREAD( 21.2386 - THREAD, unsigned int, nonstatic_oop_count + 1); 21.2387 - 21.2388 - first_nonstatic_oop_offset = 0; // will be set for first oop field 21.2389 - 21.2390 -#ifndef PRODUCT 21.2391 - if( PrintCompactFieldsSavings ) { 21.2392 - next_nonstatic_double_offset = next_nonstatic_field_offset + 21.2393 - (nonstatic_oop_count * heapOopSize); 21.2394 - if ( nonstatic_double_count > 0 ) { 21.2395 - next_nonstatic_double_offset = align_size_up(next_nonstatic_double_offset, BytesPerLong); 21.2396 - } 21.2397 - next_nonstatic_word_offset = next_nonstatic_double_offset + 21.2398 - (nonstatic_double_count * BytesPerLong); 21.2399 - next_nonstatic_short_offset = next_nonstatic_word_offset + 21.2400 - (nonstatic_word_count * BytesPerInt); 21.2401 - next_nonstatic_byte_offset = next_nonstatic_short_offset + 21.2402 - (nonstatic_short_count * BytesPerShort); 21.2403 - next_nonstatic_type_offset = align_size_up((next_nonstatic_byte_offset + 21.2404 - nonstatic_byte_count ), heapOopSize ); 21.2405 - orig_nonstatic_field_size = nonstatic_field_size + 21.2406 - ((next_nonstatic_type_offset - first_nonstatic_field_offset)/heapOopSize); 21.2407 - } 21.2408 -#endif 21.2409 - bool compact_fields = CompactFields; 21.2410 - int allocation_style = FieldsAllocationStyle; 21.2411 - if( allocation_style < 0 || allocation_style > 2 ) { // Out of range? 21.2412 - assert(false, "0 <= FieldsAllocationStyle <= 2"); 21.2413 - allocation_style = 1; // Optimistic 21.2414 - } 21.2415 - 21.2416 - // The next classes have predefined hard-coded fields offsets 21.2417 - // (see in JavaClasses::compute_hard_coded_offsets()). 21.2418 - // Use default fields allocation order for them. 21.2419 - if( (allocation_style != 0 || compact_fields ) && class_loader.is_null() && 21.2420 - (class_name == vmSymbols::java_lang_AssertionStatusDirectives() || 21.2421 - class_name == vmSymbols::java_lang_Class() || 21.2422 - class_name == vmSymbols::java_lang_ClassLoader() || 21.2423 - class_name == vmSymbols::java_lang_ref_Reference() || 21.2424 - class_name == vmSymbols::java_lang_ref_SoftReference() || 21.2425 - class_name == vmSymbols::java_lang_StackTraceElement() || 21.2426 - class_name == vmSymbols::java_lang_String() || 21.2427 - class_name == vmSymbols::java_lang_Throwable() || 21.2428 - class_name == vmSymbols::java_lang_Boolean() || 21.2429 - class_name == vmSymbols::java_lang_Character() || 21.2430 - class_name == vmSymbols::java_lang_Float() || 21.2431 - class_name == vmSymbols::java_lang_Double() || 21.2432 - class_name == vmSymbols::java_lang_Byte() || 21.2433 - class_name == vmSymbols::java_lang_Short() || 21.2434 - class_name == vmSymbols::java_lang_Integer() || 21.2435 - class_name == vmSymbols::java_lang_Long())) { 21.2436 - allocation_style = 0; // Allocate oops first 21.2437 - compact_fields = false; // Don't compact fields 21.2438 - } 21.2439 - 21.2440 - if( allocation_style == 0 ) { 21.2441 - // Fields order: oops, longs/doubles, ints, shorts/chars, bytes, padded fields 21.2442 - next_nonstatic_oop_offset = next_nonstatic_field_offset; 21.2443 - next_nonstatic_double_offset = next_nonstatic_oop_offset + 21.2444 - (nonstatic_oop_count * heapOopSize); 21.2445 - } else if( allocation_style == 1 ) { 21.2446 - // Fields order: longs/doubles, ints, shorts/chars, bytes, oops, padded fields 21.2447 - next_nonstatic_double_offset = next_nonstatic_field_offset; 21.2448 - } else if( allocation_style == 2 ) { 21.2449 - // Fields allocation: oops fields in super and sub classes are together. 21.2450 - if( nonstatic_field_size > 0 && super_klass() != NULL && 21.2451 - super_klass->nonstatic_oop_map_size() > 0 ) { 21.2452 - int map_count = super_klass->nonstatic_oop_map_count(); 21.2453 - OopMapBlock* first_map = super_klass->start_of_nonstatic_oop_maps(); 21.2454 - OopMapBlock* last_map = first_map + map_count - 1; 21.2455 - int next_offset = last_map->offset() + (last_map->count() * heapOopSize); 21.2456 - if (next_offset == next_nonstatic_field_offset) { 21.2457 - allocation_style = 0; // allocate oops first 21.2458 - next_nonstatic_oop_offset = next_nonstatic_field_offset; 21.2459 - next_nonstatic_double_offset = next_nonstatic_oop_offset + 21.2460 - (nonstatic_oop_count * heapOopSize); 21.2461 - } 21.2462 - } 21.2463 - if( allocation_style == 2 ) { 21.2464 - allocation_style = 1; // allocate oops last 21.2465 - next_nonstatic_double_offset = next_nonstatic_field_offset; 21.2466 - } 21.2467 - } else { 21.2468 - ShouldNotReachHere(); 21.2469 - } 21.2470 - 21.2471 - int nonstatic_oop_space_count = 0; 21.2472 - int nonstatic_word_space_count = 0; 21.2473 - int nonstatic_short_space_count = 0; 21.2474 - int nonstatic_byte_space_count = 0; 21.2475 - int nonstatic_oop_space_offset; 21.2476 - int nonstatic_word_space_offset; 21.2477 - int nonstatic_short_space_offset; 21.2478 - int nonstatic_byte_space_offset; 21.2479 - 21.2480 - if( nonstatic_double_count > 0 ) { 21.2481 - int offset = next_nonstatic_double_offset; 21.2482 - next_nonstatic_double_offset = align_size_up(offset, BytesPerLong); 21.2483 - if( compact_fields && offset != next_nonstatic_double_offset ) { 21.2484 - // Allocate available fields into the gap before double field. 21.2485 - int length = next_nonstatic_double_offset - offset; 21.2486 - assert(length == BytesPerInt, ""); 21.2487 - nonstatic_word_space_offset = offset; 21.2488 - if( nonstatic_word_count > 0 ) { 21.2489 - nonstatic_word_count -= 1; 21.2490 - nonstatic_word_space_count = 1; // Only one will fit 21.2491 - length -= BytesPerInt; 21.2492 - offset += BytesPerInt; 21.2493 - } 21.2494 - nonstatic_short_space_offset = offset; 21.2495 - while( length >= BytesPerShort && nonstatic_short_count > 0 ) { 21.2496 - nonstatic_short_count -= 1; 21.2497 - nonstatic_short_space_count += 1; 21.2498 - length -= BytesPerShort; 21.2499 - offset += BytesPerShort; 21.2500 - } 21.2501 - nonstatic_byte_space_offset = offset; 21.2502 - while( length > 0 && nonstatic_byte_count > 0 ) { 21.2503 - nonstatic_byte_count -= 1; 21.2504 - nonstatic_byte_space_count += 1; 21.2505 - length -= 1; 21.2506 - } 21.2507 - // Allocate oop field in the gap if there are no other fields for that. 21.2508 - nonstatic_oop_space_offset = offset; 21.2509 - if( length >= heapOopSize && nonstatic_oop_count > 0 && 21.2510 - allocation_style != 0 ) { // when oop fields not first 21.2511 - nonstatic_oop_count -= 1; 21.2512 - nonstatic_oop_space_count = 1; // Only one will fit 21.2513 - length -= heapOopSize; 21.2514 - offset += heapOopSize; 21.2515 - } 21.2516 - } 21.2517 - } 21.2518 - 21.2519 - next_nonstatic_word_offset = next_nonstatic_double_offset + 21.2520 - (nonstatic_double_count * BytesPerLong); 21.2521 - next_nonstatic_short_offset = next_nonstatic_word_offset + 21.2522 - (nonstatic_word_count * BytesPerInt); 21.2523 - next_nonstatic_byte_offset = next_nonstatic_short_offset + 21.2524 - (nonstatic_short_count * BytesPerShort); 21.2525 - next_nonstatic_padded_offset = next_nonstatic_byte_offset + 21.2526 - nonstatic_byte_count; 21.2527 - 21.2528 - // let oops jump before padding with this allocation style 21.2529 - if( allocation_style == 1 ) { 21.2530 - next_nonstatic_oop_offset = next_nonstatic_padded_offset; 21.2531 - if( nonstatic_oop_count > 0 ) { 21.2532 - next_nonstatic_oop_offset = align_size_up(next_nonstatic_oop_offset, heapOopSize); 21.2533 - } 21.2534 - next_nonstatic_padded_offset = next_nonstatic_oop_offset + (nonstatic_oop_count * heapOopSize); 21.2535 - } 21.2536 - 21.2537 - // Iterate over fields again and compute correct offsets. 21.2538 - // The field allocation type was temporarily stored in the offset slot. 21.2539 - // oop fields are located before non-oop fields (static and non-static). 21.2540 - for (AllFieldStream fs(fields, cp); !fs.done(); fs.next()) { 21.2541 - 21.2542 - // skip already laid out fields 21.2543 - if (fs.is_offset_set()) continue; 21.2544 - 21.2545 - // contended fields are handled below 21.2546 - if (fs.is_contended()) continue; 21.2547 - 21.2548 - int real_offset; 21.2549 - FieldAllocationType atype = (FieldAllocationType) fs.allocation_type(); 21.2550 - 21.2551 - // pack the rest of the fields 21.2552 - switch (atype) { 21.2553 - case STATIC_OOP: 21.2554 - real_offset = next_static_oop_offset; 21.2555 - next_static_oop_offset += heapOopSize; 21.2556 - break; 21.2557 - case STATIC_BYTE: 21.2558 - real_offset = next_static_byte_offset; 21.2559 - next_static_byte_offset += 1; 21.2560 - break; 21.2561 - case STATIC_SHORT: 21.2562 - real_offset = next_static_short_offset; 21.2563 - next_static_short_offset += BytesPerShort; 21.2564 - break; 21.2565 - case STATIC_WORD: 21.2566 - real_offset = next_static_word_offset; 21.2567 - next_static_word_offset += BytesPerInt; 21.2568 - break; 21.2569 - case STATIC_DOUBLE: 21.2570 - real_offset = next_static_double_offset; 21.2571 - next_static_double_offset += BytesPerLong; 21.2572 - break; 21.2573 - case NONSTATIC_OOP: 21.2574 - if( nonstatic_oop_space_count > 0 ) { 21.2575 - real_offset = nonstatic_oop_space_offset; 21.2576 - nonstatic_oop_space_offset += heapOopSize; 21.2577 - nonstatic_oop_space_count -= 1; 21.2578 - } else { 21.2579 - real_offset = next_nonstatic_oop_offset; 21.2580 - next_nonstatic_oop_offset += heapOopSize; 21.2581 - } 21.2582 - // Update oop maps 21.2583 - if( nonstatic_oop_map_count > 0 && 21.2584 - nonstatic_oop_offsets[nonstatic_oop_map_count - 1] == 21.2585 - real_offset - 21.2586 - int(nonstatic_oop_counts[nonstatic_oop_map_count - 1]) * 21.2587 - heapOopSize ) { 21.2588 - // Extend current oop map 21.2589 - nonstatic_oop_counts[nonstatic_oop_map_count - 1] += 1; 21.2590 - } else { 21.2591 - // Create new oop map 21.2592 - nonstatic_oop_offsets[nonstatic_oop_map_count] = real_offset; 21.2593 - nonstatic_oop_counts [nonstatic_oop_map_count] = 1; 21.2594 - nonstatic_oop_map_count += 1; 21.2595 - if( first_nonstatic_oop_offset == 0 ) { // Undefined 21.2596 - first_nonstatic_oop_offset = real_offset; 21.2597 - } 21.2598 - } 21.2599 - break; 21.2600 - case NONSTATIC_BYTE: 21.2601 - if( nonstatic_byte_space_count > 0 ) { 21.2602 - real_offset = nonstatic_byte_space_offset; 21.2603 - nonstatic_byte_space_offset += 1; 21.2604 - nonstatic_byte_space_count -= 1; 21.2605 - } else { 21.2606 - real_offset = next_nonstatic_byte_offset; 21.2607 - next_nonstatic_byte_offset += 1; 21.2608 - } 21.2609 - break; 21.2610 - case NONSTATIC_SHORT: 21.2611 - if( nonstatic_short_space_count > 0 ) { 21.2612 - real_offset = nonstatic_short_space_offset; 21.2613 - nonstatic_short_space_offset += BytesPerShort; 21.2614 - nonstatic_short_space_count -= 1; 21.2615 - } else { 21.2616 - real_offset = next_nonstatic_short_offset; 21.2617 - next_nonstatic_short_offset += BytesPerShort; 21.2618 - } 21.2619 - break; 21.2620 - case NONSTATIC_WORD: 21.2621 - if( nonstatic_word_space_count > 0 ) { 21.2622 - real_offset = nonstatic_word_space_offset; 21.2623 - nonstatic_word_space_offset += BytesPerInt; 21.2624 - nonstatic_word_space_count -= 1; 21.2625 - } else { 21.2626 - real_offset = next_nonstatic_word_offset; 21.2627 - next_nonstatic_word_offset += BytesPerInt; 21.2628 - } 21.2629 - break; 21.2630 - case NONSTATIC_DOUBLE: 21.2631 - real_offset = next_nonstatic_double_offset; 21.2632 - next_nonstatic_double_offset += BytesPerLong; 21.2633 - break; 21.2634 - default: 21.2635 - ShouldNotReachHere(); 21.2636 - } 21.2637 - fs.set_offset(real_offset); 21.2638 - } 21.2639 - 21.2640 - 21.2641 - // Handle the contended cases. 21.2642 - // 21.2643 - // Each contended field should not intersect the cache line with another contended field. 21.2644 - // In the absence of alignment information, we end up with pessimistically separating 21.2645 - // the fields with full-width padding. 21.2646 - // 21.2647 - // Additionally, this should not break alignment for the fields, so we round the alignment up 21.2648 - // for each field. 21.2649 - if (contended_count > 0) { 21.2650 - 21.2651 - // if there is at least one contended field, we need to have pre-padding for them 21.2652 - if (nonstatic_contended_count > 0) { 21.2653 - next_nonstatic_padded_offset += pad_size; 21.2654 - } 21.2655 - 21.2656 - // collect all contended groups 21.2657 - BitMap bm(cp->size()); 21.2658 - for (AllFieldStream fs(fields, cp); !fs.done(); fs.next()) { 21.2659 - // skip already laid out fields 21.2660 - if (fs.is_offset_set()) continue; 21.2661 - 21.2662 - if (fs.is_contended()) { 21.2663 - bm.set_bit(fs.contended_group()); 21.2664 - } 21.2665 - } 21.2666 - 21.2667 - int current_group = -1; 21.2668 - while ((current_group = (int)bm.get_next_one_offset(current_group + 1)) != (int)bm.size()) { 21.2669 - 21.2670 - for (AllFieldStream fs(fields, cp); !fs.done(); fs.next()) { 21.2671 - 21.2672 - // skip already laid out fields 21.2673 - if (fs.is_offset_set()) continue; 21.2674 - 21.2675 - // skip non-contended fields and fields from different group 21.2676 - if (!fs.is_contended() || (fs.contended_group() != current_group)) continue; 21.2677 - 21.2678 - // handle statics below 21.2679 - if (fs.access_flags().is_static()) continue; 21.2680 - 21.2681 - int real_offset; 21.2682 - FieldAllocationType atype = (FieldAllocationType) fs.allocation_type(); 21.2683 - 21.2684 - switch (atype) { 21.2685 - case NONSTATIC_BYTE: 21.2686 - next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, 1); 21.2687 - real_offset = next_nonstatic_padded_offset; 21.2688 - next_nonstatic_padded_offset += 1; 21.2689 - break; 21.2690 - 21.2691 - case NONSTATIC_SHORT: 21.2692 - next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, BytesPerShort); 21.2693 - real_offset = next_nonstatic_padded_offset; 21.2694 - next_nonstatic_padded_offset += BytesPerShort; 21.2695 - break; 21.2696 - 21.2697 - case NONSTATIC_WORD: 21.2698 - next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, BytesPerInt); 21.2699 - real_offset = next_nonstatic_padded_offset; 21.2700 - next_nonstatic_padded_offset += BytesPerInt; 21.2701 - break; 21.2702 - 21.2703 - case NONSTATIC_DOUBLE: 21.2704 - next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, BytesPerLong); 21.2705 - real_offset = next_nonstatic_padded_offset; 21.2706 - next_nonstatic_padded_offset += BytesPerLong; 21.2707 - break; 21.2708 - 21.2709 - case NONSTATIC_OOP: 21.2710 - next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, heapOopSize); 21.2711 - real_offset = next_nonstatic_padded_offset; 21.2712 - next_nonstatic_padded_offset += heapOopSize; 21.2713 - 21.2714 - // Create new oop map 21.2715 - nonstatic_oop_offsets[nonstatic_oop_map_count] = real_offset; 21.2716 - nonstatic_oop_counts [nonstatic_oop_map_count] = 1; 21.2717 - nonstatic_oop_map_count += 1; 21.2718 - if( first_nonstatic_oop_offset == 0 ) { // Undefined 21.2719 - first_nonstatic_oop_offset = real_offset; 21.2720 - } 21.2721 - break; 21.2722 - 21.2723 - default: 21.2724 - ShouldNotReachHere(); 21.2725 - } 21.2726 - 21.2727 - if (fs.contended_group() == 0) { 21.2728 - // Contended group defines the equivalence class over the fields: 21.2729 - // the fields within the same contended group are not inter-padded. 21.2730 - // The only exception is default group, which does not incur the 21.2731 - // equivalence, and so requires intra-padding. 21.2732 - next_nonstatic_padded_offset += pad_size; 21.2733 - } 21.2734 - 21.2735 - fs.set_offset(real_offset); 21.2736 - } // for 21.2737 - 21.2738 - // Start laying out the next group. 21.2739 - // Note that this will effectively pad the last group in the back; 21.2740 - // this is expected to alleviate memory contention effects for 21.2741 - // subclass fields and/or adjacent object. 21.2742 - // If this was the default group, the padding is already in place. 21.2743 - if (current_group != 0) { 21.2744 - next_nonstatic_padded_offset += pad_size; 21.2745 - } 21.2746 - } 21.2747 - 21.2748 - // handle static fields 21.2749 - 21.2750 - // if there is at least one contended field, we need to have pre-padding for them 21.2751 - if (static_contended_count > 0) { 21.2752 - next_static_padded_offset += pad_size; 21.2753 - } 21.2754 - 21.2755 - current_group = -1; 21.2756 - while ((current_group = (int)bm.get_next_one_offset(current_group + 1)) != (int)bm.size()) { 21.2757 - 21.2758 - for (AllFieldStream fs(fields, cp); !fs.done(); fs.next()) { 21.2759 - 21.2760 - // skip already laid out fields 21.2761 - if (fs.is_offset_set()) continue; 21.2762 - 21.2763 - // skip non-contended fields and fields from different group 21.2764 - if (!fs.is_contended() || (fs.contended_group() != current_group)) continue; 21.2765 - 21.2766 - // non-statics already handled above 21.2767 - if (!fs.access_flags().is_static()) continue; 21.2768 - 21.2769 - int real_offset; 21.2770 - FieldAllocationType atype = (FieldAllocationType) fs.allocation_type(); 21.2771 - 21.2772 - switch (atype) { 21.2773 - 21.2774 - case STATIC_BYTE: 21.2775 - next_static_padded_offset = align_size_up(next_static_padded_offset, 1); 21.2776 - real_offset = next_static_padded_offset; 21.2777 - next_static_padded_offset += 1; 21.2778 - break; 21.2779 - 21.2780 - case STATIC_SHORT: 21.2781 - next_static_padded_offset = align_size_up(next_static_padded_offset, BytesPerShort); 21.2782 - real_offset = next_static_padded_offset; 21.2783 - next_static_padded_offset += BytesPerShort; 21.2784 - break; 21.2785 - 21.2786 - case STATIC_WORD: 21.2787 - next_static_padded_offset = align_size_up(next_static_padded_offset, BytesPerInt); 21.2788 - real_offset = next_static_padded_offset; 21.2789 - next_static_padded_offset += BytesPerInt; 21.2790 - break; 21.2791 - 21.2792 - case STATIC_DOUBLE: 21.2793 - next_static_padded_offset = align_size_up(next_static_padded_offset, BytesPerLong); 21.2794 - real_offset = next_static_padded_offset; 21.2795 - next_static_padded_offset += BytesPerLong; 21.2796 - break; 21.2797 - 21.2798 - case STATIC_OOP: 21.2799 - next_static_padded_offset = align_size_up(next_static_padded_offset, heapOopSize); 21.2800 - real_offset = next_static_padded_offset; 21.2801 - next_static_padded_offset += heapOopSize; 21.2802 - break; 21.2803 - 21.2804 - default: 21.2805 - ShouldNotReachHere(); 21.2806 - } 21.2807 - 21.2808 - if (fs.contended_group() == 0) { 21.2809 - // Contended group defines the equivalence class over the fields: 21.2810 - // the fields within the same contended group are not inter-padded. 21.2811 - // The only exception is default group, which does not incur the 21.2812 - // equivalence, and so requires intra-padding. 21.2813 - next_static_padded_offset += pad_size; 21.2814 - } 21.2815 - 21.2816 - fs.set_offset(real_offset); 21.2817 - } // for 21.2818 - 21.2819 - // Start laying out the next group. 21.2820 - // Note that this will effectively pad the last group in the back; 21.2821 - // this is expected to alleviate memory contention effects for 21.2822 - // subclass fields and/or adjacent object. 21.2823 - // If this was the default group, the padding is already in place. 21.2824 - if (current_group != 0) { 21.2825 - next_static_padded_offset += pad_size; 21.2826 - } 21.2827 - 21.2828 - } 21.2829 - 21.2830 - } // handle contended 21.2831 - 21.2832 - // Size of instances 21.2833 - int instance_size; 21.2834 - 21.2835 - int notaligned_offset = next_nonstatic_padded_offset; 21.2836 - 21.2837 - // Entire class is contended, pad in the back. 21.2838 - // This helps to alleviate memory contention effects for subclass fields 21.2839 - // and/or adjacent object. 21.2840 - if (parsed_annotations.is_contended()) { 21.2841 - notaligned_offset += pad_size; 21.2842 - next_static_padded_offset += pad_size; 21.2843 - } 21.2844 - 21.2845 - int next_static_type_offset = align_size_up(next_static_padded_offset, wordSize); 21.2846 - int static_field_size = (next_static_type_offset - 21.2847 - InstanceMirrorKlass::offset_of_static_fields()) / wordSize; 21.2848 - 21.2849 - next_nonstatic_type_offset = align_size_up(notaligned_offset, heapOopSize ); 21.2850 - nonstatic_field_size = nonstatic_field_size + ((next_nonstatic_type_offset 21.2851 - - first_nonstatic_field_offset)/heapOopSize); 21.2852 - 21.2853 - next_nonstatic_type_offset = align_size_up(notaligned_offset, wordSize ); 21.2854 - instance_size = align_object_size(next_nonstatic_type_offset / wordSize); 21.2855 - 21.2856 - assert(instance_size == align_object_size(align_size_up( 21.2857 - (instanceOopDesc::base_offset_in_bytes() + nonstatic_field_size*heapOopSize + ((parsed_annotations.is_contended()) ? pad_size : 0)), 21.2858 - wordSize) / wordSize), "consistent layout helper value"); 21.2859 - 21.2860 - // Number of non-static oop map blocks allocated at end of klass. 21.2861 - const unsigned int total_oop_map_count = 21.2862 - compute_oop_map_count(super_klass, nonstatic_oop_map_count, 21.2863 - first_nonstatic_oop_offset); 21.2864 + itable_size = access_flags.is_interface() ? 0 : klassItable::compute_itable_size(_transitive_interfaces); 21.2865 + 21.2866 + FieldLayoutInfo info; 21.2867 + layout_fields(class_loader, &fac, &parsed_annotations, &info, CHECK_NULL); 21.2868 + 21.2869 + int total_oop_map_size2 = 21.2870 + InstanceKlass::nonstatic_oop_map_size(info.total_oop_map_count); 21.2871 + 21.2872 // Compute reference type 21.2873 ReferenceType rt; 21.2874 if (super_klass() == NULL) { 21.2875 @@ -4066,53 +3958,42 @@ 21.2876 } 21.2877 21.2878 // We can now create the basic Klass* for this klass 21.2879 - int total_oop_map_size2 = 21.2880 - InstanceKlass::nonstatic_oop_map_size(total_oop_map_count); 21.2881 - 21.2882 - Klass* ik = InstanceKlass::allocate_instance_klass(loader_data, 21.2883 - vtable_size, 21.2884 - itable_size, 21.2885 - static_field_size, 21.2886 - total_oop_map_size2, 21.2887 - rt, 21.2888 - access_flags, 21.2889 - name, 21.2890 - super_klass(), 21.2891 - !host_klass.is_null(), 21.2892 - CHECK_(nullHandle)); 21.2893 - 21.2894 - // Add all classes to our internal class loader list here, 21.2895 - // including classes in the bootstrap (NULL) class loader. 21.2896 - loader_data->add_class(ik); 21.2897 - 21.2898 - instanceKlassHandle this_klass (THREAD, ik); 21.2899 - 21.2900 - assert(this_klass->static_field_size() == static_field_size, "sanity"); 21.2901 - assert(this_klass->nonstatic_oop_map_count() == total_oop_map_count, 21.2902 + _klass = InstanceKlass::allocate_instance_klass(loader_data, 21.2903 + vtable_size, 21.2904 + itable_size, 21.2905 + info.static_field_size, 21.2906 + total_oop_map_size2, 21.2907 + rt, 21.2908 + access_flags, 21.2909 + name, 21.2910 + super_klass(), 21.2911 + !host_klass.is_null(), 21.2912 + CHECK_(nullHandle)); 21.2913 + instanceKlassHandle this_klass (THREAD, _klass); 21.2914 + 21.2915 + assert(this_klass->static_field_size() == info.static_field_size, "sanity"); 21.2916 + assert(this_klass->nonstatic_oop_map_count() == info.total_oop_map_count, 21.2917 "sanity"); 21.2918 21.2919 // Fill in information already parsed 21.2920 this_klass->set_should_verify_class(verify); 21.2921 - jint lh = Klass::instance_layout_helper(instance_size, false); 21.2922 + jint lh = Klass::instance_layout_helper(info.instance_size, false); 21.2923 this_klass->set_layout_helper(lh); 21.2924 assert(this_klass->oop_is_instance(), "layout is correct"); 21.2925 - assert(this_klass->size_helper() == instance_size, "correct size_helper"); 21.2926 + assert(this_klass->size_helper() == info.instance_size, "correct size_helper"); 21.2927 // Not yet: supers are done below to support the new subtype-checking fields 21.2928 //this_klass->set_super(super_klass()); 21.2929 this_klass->set_class_loader_data(loader_data); 21.2930 - this_klass->set_nonstatic_field_size(nonstatic_field_size); 21.2931 - this_klass->set_has_nonstatic_fields(has_nonstatic_fields); 21.2932 + this_klass->set_nonstatic_field_size(info.nonstatic_field_size); 21.2933 + this_klass->set_has_nonstatic_fields(info.has_nonstatic_fields); 21.2934 this_klass->set_static_oop_field_count(fac.count[STATIC_OOP]); 21.2935 - cp->set_pool_holder(this_klass()); 21.2936 - error_handler.set_in_error(false); // turn off error handler for cp 21.2937 - this_klass->set_constants(cp()); 21.2938 - this_klass->set_local_interfaces(local_interfaces); 21.2939 - this_klass->set_fields(fields, java_fields_count); 21.2940 - this_klass->set_methods(methods); 21.2941 + 21.2942 + apply_parsed_class_metadata(this_klass, java_fields_count, CHECK_NULL); 21.2943 + 21.2944 if (has_final_method) { 21.2945 this_klass->set_has_final_method(); 21.2946 } 21.2947 - this_klass->set_method_ordering(method_ordering); 21.2948 + this_klass->copy_method_ordering(method_ordering, CHECK_NULL); 21.2949 // The InstanceKlass::_methods_jmethod_ids cache and the 21.2950 // InstanceKlass::_methods_cached_itable_indices cache are 21.2951 // both managed on the assumption that the initial cache 21.2952 @@ -4124,17 +4005,6 @@ 21.2953 if (is_anonymous()) // I am well known to myself 21.2954 cp->klass_at_put(this_class_index, this_klass()); // eagerly resolve 21.2955 21.2956 - // Assign allocations if needed 21.2957 - if (_annotations != NULL || _type_annotations != NULL || 21.2958 - fields_annotations != NULL || fields_type_annotations != NULL) { 21.2959 - Annotations* annotations = Annotations::allocate(loader_data, CHECK_NULL); 21.2960 - annotations->set_class_annotations(_annotations); 21.2961 - annotations->set_class_type_annotations(_type_annotations); 21.2962 - annotations->set_fields_annotations(fields_annotations); 21.2963 - annotations->set_fields_type_annotations(fields_type_annotations); 21.2964 - this_klass->set_annotations(annotations); 21.2965 - } 21.2966 - 21.2967 this_klass->set_minor_version(minor_version); 21.2968 this_klass->set_major_version(major_version); 21.2969 this_klass->set_has_default_methods(has_default_methods); 21.2970 @@ -4169,8 +4039,6 @@ 21.2971 this_klass->set_has_miranda_methods(); // then set a flag 21.2972 } 21.2973 21.2974 - this_klass->set_transitive_interfaces(transitive_interfaces); 21.2975 - 21.2976 // Fill in information needed to compute superclasses. 21.2977 this_klass->initialize_supers(super_klass(), CHECK_(nullHandle)); 21.2978 21.2979 @@ -4179,7 +4047,7 @@ 21.2980 21.2981 // Compute transitive closure of interfaces this class implements 21.2982 // Do final class setup 21.2983 - fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_counts); 21.2984 + fill_oop_maps(this_klass, info.nonstatic_oop_map_count, info.nonstatic_oop_offsets, info.nonstatic_oop_counts); 21.2985 21.2986 // Fill in has_finalizer, has_vanilla_constructor, and layout_helper 21.2987 set_precomputed_flags(this_klass); 21.2988 @@ -4278,35 +4146,6 @@ 21.2989 } 21.2990 } 21.2991 21.2992 -#ifndef PRODUCT 21.2993 - if( PrintCompactFieldsSavings ) { 21.2994 - ResourceMark rm; 21.2995 - if( nonstatic_field_size < orig_nonstatic_field_size ) { 21.2996 - tty->print("[Saved %d of %d bytes in %s]\n", 21.2997 - (orig_nonstatic_field_size - nonstatic_field_size)*heapOopSize, 21.2998 - orig_nonstatic_field_size*heapOopSize, 21.2999 - this_klass->external_name()); 21.3000 - } else if( nonstatic_field_size > orig_nonstatic_field_size ) { 21.3001 - tty->print("[Wasted %d over %d bytes in %s]\n", 21.3002 - (nonstatic_field_size - orig_nonstatic_field_size)*heapOopSize, 21.3003 - orig_nonstatic_field_size*heapOopSize, 21.3004 - this_klass->external_name()); 21.3005 - } 21.3006 - } 21.3007 -#endif 21.3008 - 21.3009 -#ifndef PRODUCT 21.3010 - if (PrintFieldLayout) { 21.3011 - print_field_layout(name, 21.3012 - fields, 21.3013 - cp, 21.3014 - instance_size, 21.3015 - first_nonstatic_field_offset, 21.3016 - next_nonstatic_field_offset, 21.3017 - next_static_type_offset); 21.3018 - } 21.3019 -#endif 21.3020 - 21.3021 // preserve result across HandleMark 21.3022 preserve_this_klass = this_klass(); 21.3023 } 21.3024 @@ -4316,9 +4155,40 @@ 21.3025 instanceKlassHandle this_klass (THREAD, preserve_this_klass); 21.3026 debug_only(this_klass->verify();) 21.3027 21.3028 + // Clear class if no error has occurred so destructor doesn't deallocate it 21.3029 + _klass = NULL; 21.3030 return this_klass; 21.3031 } 21.3032 21.3033 +// Destructor to clean up if there's an error 21.3034 +ClassFileParser::~ClassFileParser() { 21.3035 + MetadataFactory::free_metadata(_loader_data, _cp); 21.3036 + MetadataFactory::free_array<u2>(_loader_data, _fields); 21.3037 + 21.3038 + // Free methods 21.3039 + InstanceKlass::deallocate_methods(_loader_data, _methods); 21.3040 + 21.3041 + // beware of the Universe::empty_blah_array!! 21.3042 + if (_inner_classes != Universe::the_empty_short_array()) { 21.3043 + MetadataFactory::free_array<u2>(_loader_data, _inner_classes); 21.3044 + } 21.3045 + 21.3046 + // Free interfaces 21.3047 + InstanceKlass::deallocate_interfaces(_loader_data, _super_klass(), 21.3048 + _local_interfaces, _transitive_interfaces); 21.3049 + 21.3050 + MetadataFactory::free_array<u1>(_loader_data, _annotations); 21.3051 + MetadataFactory::free_array<u1>(_loader_data, _type_annotations); 21.3052 + Annotations::free_contents(_loader_data, _fields_annotations); 21.3053 + Annotations::free_contents(_loader_data, _fields_type_annotations); 21.3054 + 21.3055 + clear_class_metadata(); 21.3056 + 21.3057 + // deallocate the klass if already created. 21.3058 + MetadataFactory::free_metadata(_loader_data, _klass); 21.3059 + _klass = NULL; 21.3060 +} 21.3061 + 21.3062 void ClassFileParser::print_field_layout(Symbol* name, 21.3063 Array<u2>* fields, 21.3064 constantPoolHandle cp, 21.3065 @@ -4510,7 +4380,7 @@ 21.3066 } 21.3067 } 21.3068 21.3069 -// utility method for appending and array with check for duplicates 21.3070 +// utility methods for appending an array with check for duplicates 21.3071 21.3072 void append_interfaces(GrowableArray<Klass*>* result, Array<Klass*>* ifs) { 21.3073 // iterate over new interfaces 21.3074 @@ -4522,8 +4392,9 @@ 21.3075 } 21.3076 } 21.3077 21.3078 - 21.3079 -Array<Klass*>* ClassFileParser::compute_transitive_interfaces(ClassLoaderData* loader_data, instanceKlassHandle super, Array<Klass*>* local_ifs, TRAPS) { 21.3080 +Array<Klass*>* ClassFileParser::compute_transitive_interfaces( 21.3081 + instanceKlassHandle super, 21.3082 + Array<Klass*>* local_ifs, TRAPS) { 21.3083 // Compute maximum size for transitive interfaces 21.3084 int max_transitive_size = 0; 21.3085 int super_size = 0; 21.3086 @@ -4570,7 +4441,7 @@ 21.3087 // length will be less than the max_transitive_size if duplicates were removed 21.3088 int length = result->length(); 21.3089 assert(length <= max_transitive_size, "just checking"); 21.3090 - Array<Klass*>* new_result = MetadataFactory::new_array<Klass*>(loader_data, length, CHECK_NULL); 21.3091 + Array<Klass*>* new_result = MetadataFactory::new_array<Klass*>(_loader_data, length, CHECK_NULL); 21.3092 for (int i = 0; i < length; i++) { 21.3093 Klass* e = result->at(i); 21.3094 assert(e != NULL, "just checking"); 21.3095 @@ -4580,7 +4451,6 @@ 21.3096 } 21.3097 } 21.3098 21.3099 - 21.3100 void ClassFileParser::check_super_class_access(instanceKlassHandle this_klass, TRAPS) { 21.3101 Klass* super = this_klass->super(); 21.3102 if ((super != NULL) &&
22.1 --- a/src/share/vm/classfile/classFileParser.hpp Fri Mar 15 22:07:42 2013 -0700 22.2 +++ b/src/share/vm/classfile/classFileParser.hpp Sat Mar 16 21:44:52 2013 -0700 22.3 @@ -34,6 +34,7 @@ 22.4 #include "classfile/symbolTable.hpp" 22.5 22.6 class FieldAllocationCount; 22.7 +class FieldLayoutInfo; 22.8 22.9 22.10 // Parser for for .class files 22.11 @@ -47,6 +48,7 @@ 22.12 u2 _major_version; 22.13 u2 _minor_version; 22.14 Symbol* _class_name; 22.15 + ClassLoaderData* _loader_data; 22.16 KlassHandle _host_klass; 22.17 GrowableArray<Handle>* _cp_patches; // overrides for CP entries 22.18 22.19 @@ -58,33 +60,59 @@ 22.20 22.21 // class attributes parsed before the instance klass is created: 22.22 bool _synthetic_flag; 22.23 + int _sde_length; 22.24 + char* _sde_buffer; 22.25 Symbol* _sourcefile; 22.26 Symbol* _generic_signature; 22.27 - char* _sde_buffer; 22.28 - int _sde_length; 22.29 - Array<u2>* _inner_classes; 22.30 + 22.31 + // Metadata created before the instance klass is created. Must be deallocated 22.32 + // if not transferred to the InstanceKlass upon successful class loading 22.33 + // in which case these pointers have been set to NULL. 22.34 + instanceKlassHandle _super_klass; 22.35 + ConstantPool* _cp; 22.36 + Array<u2>* _fields; 22.37 + Array<Method*>* _methods; 22.38 + Array<u2>* _inner_classes; 22.39 + Array<Klass*>* _local_interfaces; 22.40 + Array<Klass*>* _transitive_interfaces; 22.41 AnnotationArray* _annotations; 22.42 AnnotationArray* _type_annotations; 22.43 + Array<AnnotationArray*>* _fields_annotations; 22.44 + Array<AnnotationArray*>* _fields_type_annotations; 22.45 + InstanceKlass* _klass; // InstanceKlass once created. 22.46 22.47 void set_class_synthetic_flag(bool x) { _synthetic_flag = x; } 22.48 void set_class_sourcefile(Symbol* x) { _sourcefile = x; } 22.49 void set_class_generic_signature(Symbol* x) { _generic_signature = x; } 22.50 void set_class_sde_buffer(char* x, int len) { _sde_buffer = x; _sde_length = len; } 22.51 - void set_class_inner_classes(Array<u2>* x) { _inner_classes = x; } 22.52 - void set_class_annotations(AnnotationArray* x) { _annotations = x; } 22.53 - void set_class_type_annotations(AnnotationArray* x) { _type_annotations = x; } 22.54 - void init_parsed_class_attributes() { 22.55 + 22.56 + void init_parsed_class_attributes(ClassLoaderData* loader_data) { 22.57 + _loader_data = loader_data; 22.58 _synthetic_flag = false; 22.59 _sourcefile = NULL; 22.60 _generic_signature = NULL; 22.61 _sde_buffer = NULL; 22.62 _sde_length = 0; 22.63 - _annotations = _type_annotations = NULL; 22.64 // initialize the other flags too: 22.65 _has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false; 22.66 _max_bootstrap_specifier_index = -1; 22.67 + clear_class_metadata(); 22.68 + _klass = NULL; 22.69 } 22.70 void apply_parsed_class_attributes(instanceKlassHandle k); // update k 22.71 + void apply_parsed_class_metadata(instanceKlassHandle k, int fields_count, TRAPS); 22.72 + void clear_class_metadata() { 22.73 + // metadata created before the instance klass is created. Must be 22.74 + // deallocated if classfile parsing returns an error. 22.75 + _cp = NULL; 22.76 + _fields = NULL; 22.77 + _methods = NULL; 22.78 + _inner_classes = NULL; 22.79 + _local_interfaces = NULL; 22.80 + _transitive_interfaces = NULL; 22.81 + _annotations = _type_annotations = NULL; 22.82 + _fields_annotations = _fields_type_annotations = NULL; 22.83 + } 22.84 22.85 class AnnotationCollector { 22.86 public: 22.87 @@ -124,11 +152,27 @@ 22.88 void set_contended(bool contended) { set_annotation(_sun_misc_Contended); } 22.89 bool is_contended() { return has_annotation(_sun_misc_Contended); } 22.90 }; 22.91 + 22.92 + // This class also doubles as a holder for metadata cleanup. 22.93 class FieldAnnotationCollector: public AnnotationCollector { 22.94 + ClassLoaderData* _loader_data; 22.95 + AnnotationArray* _field_annotations; 22.96 + AnnotationArray* _field_type_annotations; 22.97 public: 22.98 - FieldAnnotationCollector() : AnnotationCollector(_in_field) { } 22.99 + FieldAnnotationCollector(ClassLoaderData* loader_data) : 22.100 + AnnotationCollector(_in_field), 22.101 + _loader_data(loader_data), 22.102 + _field_annotations(NULL), 22.103 + _field_type_annotations(NULL) {} 22.104 void apply_to(FieldInfo* f); 22.105 + ~FieldAnnotationCollector(); 22.106 + AnnotationArray* field_annotations() { return _field_annotations; } 22.107 + AnnotationArray* field_type_annotations() { return _field_type_annotations; } 22.108 + 22.109 + void set_field_annotations(AnnotationArray* a) { _field_annotations = a; } 22.110 + void set_field_type_annotations(AnnotationArray* a) { _field_type_annotations = a; } 22.111 }; 22.112 + 22.113 class MethodAnnotationCollector: public AnnotationCollector { 22.114 public: 22.115 MethodAnnotationCollector() : AnnotationCollector(_in_method) { } 22.116 @@ -152,38 +196,30 @@ 22.117 void set_stream(ClassFileStream* st) { _stream = st; } 22.118 22.119 // Constant pool parsing 22.120 - void parse_constant_pool_entries(ClassLoaderData* loader_data, 22.121 - constantPoolHandle cp, int length, TRAPS); 22.122 + void parse_constant_pool_entries(int length, TRAPS); 22.123 22.124 - constantPoolHandle parse_constant_pool(ClassLoaderData* loader_data, TRAPS); 22.125 + constantPoolHandle parse_constant_pool(TRAPS); 22.126 22.127 // Interface parsing 22.128 - Array<Klass*>* parse_interfaces(constantPoolHandle cp, 22.129 - int length, 22.130 - ClassLoaderData* loader_data, 22.131 + Array<Klass*>* parse_interfaces(int length, 22.132 Handle protection_domain, 22.133 Symbol* class_name, 22.134 bool* has_default_methods, 22.135 TRAPS); 22.136 void record_defined_class_dependencies(instanceKlassHandle defined_klass, TRAPS); 22.137 22.138 + instanceKlassHandle parse_super_class(int super_class_index, TRAPS); 22.139 // Field parsing 22.140 - void parse_field_attributes(ClassLoaderData* loader_data, 22.141 - constantPoolHandle cp, u2 attributes_count, 22.142 + void parse_field_attributes(u2 attributes_count, 22.143 bool is_static, u2 signature_index, 22.144 u2* constantvalue_index_addr, 22.145 bool* is_synthetic_addr, 22.146 u2* generic_signature_index_addr, 22.147 - AnnotationArray** field_annotations, 22.148 - AnnotationArray** field_type_annotations, 22.149 FieldAnnotationCollector* parsed_annotations, 22.150 TRAPS); 22.151 - Array<u2>* parse_fields(ClassLoaderData* loader_data, 22.152 - Symbol* class_name, 22.153 - constantPoolHandle cp, bool is_interface, 22.154 + Array<u2>* parse_fields(Symbol* class_name, 22.155 + bool is_interface, 22.156 FieldAllocationCount *fac, 22.157 - Array<AnnotationArray*>** fields_annotations, 22.158 - Array<AnnotationArray*>** fields_type_annotations, 22.159 u2* java_fields_count_ptr, TRAPS); 22.160 22.161 void print_field_layout(Symbol* name, 22.162 @@ -195,65 +231,52 @@ 22.163 int static_fields_end); 22.164 22.165 // Method parsing 22.166 - methodHandle parse_method(ClassLoaderData* loader_data, 22.167 - constantPoolHandle cp, 22.168 - bool is_interface, 22.169 + methodHandle parse_method(bool is_interface, 22.170 AccessFlags* promoted_flags, 22.171 TRAPS); 22.172 - Array<Method*>* parse_methods(ClassLoaderData* loader_data, 22.173 - constantPoolHandle cp, 22.174 - bool is_interface, 22.175 + Array<Method*>* parse_methods(bool is_interface, 22.176 AccessFlags* promoted_flags, 22.177 bool* has_final_method, 22.178 bool* has_default_method, 22.179 TRAPS); 22.180 - Array<int>* sort_methods(ClassLoaderData* loader_data, 22.181 - Array<Method*>* methods, 22.182 - TRAPS); 22.183 - u2* parse_exception_table(ClassLoaderData* loader_data, 22.184 - u4 code_length, u4 exception_table_length, 22.185 - constantPoolHandle cp, TRAPS); 22.186 + intArray* sort_methods(Array<Method*>* methods); 22.187 + 22.188 + u2* parse_exception_table(u4 code_length, u4 exception_table_length, 22.189 + TRAPS); 22.190 void parse_linenumber_table( 22.191 u4 code_attribute_length, u4 code_length, 22.192 CompressedLineNumberWriteStream** write_stream, TRAPS); 22.193 u2* parse_localvariable_table(u4 code_length, u2 max_locals, u4 code_attribute_length, 22.194 - constantPoolHandle cp, u2* localvariable_table_length, 22.195 + u2* localvariable_table_length, 22.196 bool isLVTT, TRAPS); 22.197 u2* parse_checked_exceptions(u2* checked_exceptions_length, u4 method_attribute_length, 22.198 - constantPoolHandle cp, TRAPS); 22.199 + TRAPS); 22.200 void parse_type_array(u2 array_length, u4 code_length, u4* u1_index, u4* u2_index, 22.201 - u1* u1_array, u2* u2_array, constantPoolHandle cp, TRAPS); 22.202 - Array<u1>* parse_stackmap_table(ClassLoaderData* loader_data, u4 code_attribute_length, TRAPS); 22.203 + u1* u1_array, u2* u2_array, TRAPS); 22.204 + u1* parse_stackmap_table(u4 code_attribute_length, TRAPS); 22.205 22.206 // Classfile attribute parsing 22.207 - void parse_classfile_sourcefile_attribute(constantPoolHandle cp, TRAPS); 22.208 - void parse_classfile_source_debug_extension_attribute(constantPoolHandle cp, 22.209 - int length, TRAPS); 22.210 - u2 parse_classfile_inner_classes_attribute(ClassLoaderData* loader_data, 22.211 - u1* inner_classes_attribute_start, 22.212 + void parse_classfile_sourcefile_attribute(TRAPS); 22.213 + void parse_classfile_source_debug_extension_attribute(int length, TRAPS); 22.214 + u2 parse_classfile_inner_classes_attribute(u1* inner_classes_attribute_start, 22.215 bool parsed_enclosingmethod_attribute, 22.216 u2 enclosing_method_class_index, 22.217 u2 enclosing_method_method_index, 22.218 - constantPoolHandle cp, 22.219 TRAPS); 22.220 - void parse_classfile_attributes(ClassLoaderData* loader_data, 22.221 - constantPoolHandle cp, 22.222 - ClassAnnotationCollector* parsed_annotations, 22.223 + void parse_classfile_attributes(ClassAnnotationCollector* parsed_annotations, 22.224 TRAPS); 22.225 - void parse_classfile_synthetic_attribute(constantPoolHandle cp, TRAPS); 22.226 - void parse_classfile_signature_attribute(constantPoolHandle cp, TRAPS); 22.227 - void parse_classfile_bootstrap_methods_attribute(ClassLoaderData* loader_data, constantPoolHandle cp, u4 attribute_length, TRAPS); 22.228 + void parse_classfile_synthetic_attribute(TRAPS); 22.229 + void parse_classfile_signature_attribute(TRAPS); 22.230 + void parse_classfile_bootstrap_methods_attribute(u4 attribute_length, TRAPS); 22.231 22.232 // Annotations handling 22.233 - AnnotationArray* assemble_annotations(ClassLoaderData* loader_data, 22.234 - u1* runtime_visible_annotations, 22.235 + AnnotationArray* assemble_annotations(u1* runtime_visible_annotations, 22.236 int runtime_visible_annotations_length, 22.237 u1* runtime_invisible_annotations, 22.238 int runtime_invisible_annotations_length, TRAPS); 22.239 int skip_annotation(u1* buffer, int limit, int index); 22.240 int skip_annotation_value(u1* buffer, int limit, int index); 22.241 - void parse_annotations(ClassLoaderData* loader_data, 22.242 - u1* buffer, int limit, constantPoolHandle cp, 22.243 + void parse_annotations(u1* buffer, int limit, 22.244 /* Results (currently, only one result is supported): */ 22.245 AnnotationCollector* result, 22.246 TRAPS); 22.247 @@ -267,8 +290,7 @@ 22.248 int* nonstatic_oop_offsets, 22.249 unsigned int* nonstatic_oop_counts); 22.250 void set_precomputed_flags(instanceKlassHandle k); 22.251 - Array<Klass*>* compute_transitive_interfaces(ClassLoaderData* loader_data, 22.252 - instanceKlassHandle super, 22.253 + Array<Klass*>* compute_transitive_interfaces(instanceKlassHandle super, 22.254 Array<Klass*>* local_ifs, TRAPS); 22.255 22.256 // Format checker methods 22.257 @@ -318,7 +340,7 @@ 22.258 bool is_supported_version(u2 major, u2 minor); 22.259 bool has_illegal_visibility(jint flags); 22.260 22.261 - void verify_constantvalue(int constantvalue_index, int signature_index, constantPoolHandle cp, TRAPS); 22.262 + void verify_constantvalue(int constantvalue_index, int signature_index, TRAPS); 22.263 void verify_legal_utf8(const unsigned char* buffer, int length, TRAPS); 22.264 void verify_legal_class_name(Symbol* name, TRAPS); 22.265 void verify_legal_field_name(Symbol* name, TRAPS); 22.266 @@ -359,10 +381,17 @@ 22.267 // In older versions of the VM, Klass*s cannot sneak into early phases of 22.268 // constant pool construction, but in later versions they can. 22.269 // %%% Let's phase out the old is_klass_reference. 22.270 - bool is_klass_reference(constantPoolHandle cp, int index) { 22.271 - return (EnableInvokeDynamic 22.272 - ? cp->tag_at(index).is_klass_or_reference() 22.273 - : cp->tag_at(index).is_klass_reference()); 22.274 + bool valid_klass_reference_at(int index) { 22.275 + return _cp->is_within_bounds(index) && 22.276 + (EnableInvokeDynamic 22.277 + ? _cp->tag_at(index).is_klass_or_reference() 22.278 + : _cp->tag_at(index).is_klass_reference()); 22.279 + } 22.280 + 22.281 + // Checks that the cpool index is in range and is a utf8 22.282 + bool valid_symbol_at(int cpool_index) { 22.283 + return (_cp->is_within_bounds(cpool_index) && 22.284 + _cp->tag_at(cpool_index).is_utf8()); 22.285 } 22.286 22.287 void copy_localvariable_table(ConstMethod* cm, int lvt_cnt, 22.288 @@ -373,8 +402,7 @@ 22.289 u2** localvariable_type_table_start, 22.290 TRAPS); 22.291 22.292 - void copy_method_annotations(ClassLoaderData* loader_data, 22.293 - ConstMethod* cm, 22.294 + void copy_method_annotations(ConstMethod* cm, 22.295 u1* runtime_visible_annotations, 22.296 int runtime_visible_annotations_length, 22.297 u1* runtime_invisible_annotations, 22.298 @@ -391,9 +419,15 @@ 22.299 int annotation_default_length, 22.300 TRAPS); 22.301 22.302 + // lays out fields in class and returns the total oopmap count 22.303 + void layout_fields(Handle class_loader, FieldAllocationCount* fac, 22.304 + ClassAnnotationCollector* parsed_annotations, 22.305 + FieldLayoutInfo* info, TRAPS); 22.306 + 22.307 public: 22.308 // Constructor 22.309 ClassFileParser(ClassFileStream* st) { set_stream(st); } 22.310 + ~ClassFileParser(); 22.311 22.312 // Parse .class file and return new Klass*. The Klass* is not hooked up 22.313 // to the system dictionary or any other structures, so a .class file can
23.1 --- a/src/share/vm/classfile/symbolTable.cpp Fri Mar 15 22:07:42 2013 -0700 23.2 +++ b/src/share/vm/classfile/symbolTable.cpp Sat Mar 16 21:44:52 2013 -0700 23.3 @@ -1,5 +1,5 @@ 23.4 /* 23.5 - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 23.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 23.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 23.8 * 23.9 * This code is free software; you can redistribute it and/or modify it 23.10 @@ -49,18 +49,17 @@ 23.11 23.12 Symbol* sym; 23.13 23.14 - if (c_heap) { 23.15 + if (DumpSharedSpaces) { 23.16 + // Allocate all symbols to CLD shared metaspace 23.17 + sym = new (len, ClassLoaderData::the_null_class_loader_data(), THREAD) Symbol(name, len, -1); 23.18 + } else if (c_heap) { 23.19 // refcount starts as 1 23.20 - assert(!DumpSharedSpaces, "never allocate to C heap"); 23.21 sym = new (len, THREAD) Symbol(name, len, 1); 23.22 assert(sym != NULL, "new should call vm_exit_out_of_memory if C_HEAP is exhausted"); 23.23 } else { 23.24 - if (DumpSharedSpaces) { 23.25 - sym = new (len, ClassLoaderData::the_null_class_loader_data(), THREAD) Symbol(name, len, -1); 23.26 - } else { 23.27 + // Allocate to global arena 23.28 sym = new (len, arena(), THREAD) Symbol(name, len, -1); 23.29 } 23.30 - } 23.31 return sym; 23.32 } 23.33
24.1 --- a/src/share/vm/code/compressedStream.cpp Fri Mar 15 22:07:42 2013 -0700 24.2 +++ b/src/share/vm/code/compressedStream.cpp Sat Mar 16 21:44:52 2013 -0700 24.3 @@ -195,7 +195,7 @@ 24.4 // for this block (a matching directive turns it back on later). 24.5 // These directives can be removed once the MS VS.NET 2005 24.6 // compiler stack overflow is fixed. 24.7 -#if _MSC_VER >=1400 && !defined(_WIN64) 24.8 +#if defined(_MSC_VER) && _MSC_VER >=1400 && !defined(_WIN64) 24.9 #pragma optimize("", off) 24.10 #pragma warning(disable: 4748) 24.11 #endif 24.12 @@ -276,7 +276,7 @@ 24.13 guarantee(fails == 0, "test failures"); 24.14 } 24.15 24.16 -#if _MSC_VER >=1400 && !defined(_WIN64) 24.17 +#if defined(_MSC_VER) &&_MSC_VER >=1400 && !defined(_WIN64) 24.18 #pragma warning(default: 4748) 24.19 #pragma optimize("", on) 24.20 #endif
25.1 --- a/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp Fri Mar 15 22:07:42 2013 -0700 25.2 +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp Sat Mar 16 21:44:52 2013 -0700 25.3 @@ -2063,11 +2063,6 @@ 25.4 // required. 25.5 _collectorState = FinalMarking; 25.6 } 25.7 - if (PrintGCDetails && 25.8 - (_collectorState > Idling || 25.9 - !GCCause::is_user_requested_gc(GenCollectedHeap::heap()->gc_cause()))) { 25.10 - gclog_or_tty->print(" (concurrent mode failure)"); 25.11 - } 25.12 collect_in_foreground(clear_all_soft_refs); 25.13 25.14 // For a mark-sweep, compute_new_size() will be called 25.15 @@ -3400,10 +3395,10 @@ 25.16 if (PrintCMSStatistics != 0) { 25.17 _collector->resetYields(); 25.18 } 25.19 - if (PrintGCDetails && PrintGCTimeStamps) { 25.20 + if (PrintGCDetails) { 25.21 gclog_or_tty->date_stamp(PrintGCDateStamps); 25.22 - gclog_or_tty->stamp(); 25.23 - gclog_or_tty->print_cr(": [%s-concurrent-%s-start]", 25.24 + gclog_or_tty->stamp(PrintGCTimeStamps); 25.25 + gclog_or_tty->print_cr("[%s-concurrent-%s-start]", 25.26 _collector->cmsGen()->short_name(), _phase); 25.27 } 25.28 _collector->resetTimer();
26.1 --- a/src/share/vm/gc_implementation/g1/concurrentMark.cpp Fri Mar 15 22:07:42 2013 -0700 26.2 +++ b/src/share/vm/gc_implementation/g1/concurrentMark.cpp Sat Mar 16 21:44:52 2013 -0700 26.3 @@ -1310,11 +1310,6 @@ 26.4 _markStack.expand(); 26.5 } 26.6 26.7 -#if VERIFY_OBJS_PROCESSED 26.8 - _scan_obj_cl.objs_processed = 0; 26.9 - ThreadLocalObjQueue::objs_enqueued = 0; 26.10 -#endif 26.11 - 26.12 // Statistics 26.13 double now = os::elapsedTime(); 26.14 _remark_mark_times.add((mark_work_end - start) * 1000.0); 26.15 @@ -2555,17 +2550,6 @@ 26.16 guarantee(satb_mq_set.completed_buffers_num() == 0, "invariant"); 26.17 26.18 print_stats(); 26.19 - 26.20 -#if VERIFY_OBJS_PROCESSED 26.21 - if (_scan_obj_cl.objs_processed != ThreadLocalObjQueue::objs_enqueued) { 26.22 - gclog_or_tty->print_cr("Processed = %d, enqueued = %d.", 26.23 - _scan_obj_cl.objs_processed, 26.24 - ThreadLocalObjQueue::objs_enqueued); 26.25 - guarantee(_scan_obj_cl.objs_processed == 26.26 - ThreadLocalObjQueue::objs_enqueued, 26.27 - "Different number of objs processed and enqueued."); 26.28 - } 26.29 -#endif 26.30 } 26.31 26.32 #ifndef PRODUCT 26.33 @@ -4111,7 +4095,7 @@ 26.34 // bitmap knows by how much we need to move it as it knows its 26.35 // granularity). 26.36 assert(_finger < _region_limit, "invariant"); 26.37 - HeapWord* new_finger = _nextMarkBitMap->nextWord(_finger); 26.38 + HeapWord* new_finger = _nextMarkBitMap->nextObject(_finger); 26.39 // Check if bitmap iteration was aborted while scanning the last object 26.40 if (new_finger >= _region_limit) { 26.41 giveup_current_region();
27.1 --- a/src/share/vm/gc_implementation/g1/concurrentMark.hpp Fri Mar 15 22:07:42 2013 -0700 27.2 +++ b/src/share/vm/gc_implementation/g1/concurrentMark.hpp Sat Mar 16 21:44:52 2013 -0700 27.3 @@ -97,7 +97,6 @@ 27.4 HeapWord* limit = NULL) const; 27.5 27.6 // conversion utilities 27.7 - // XXX Fix these so that offsets are size_t's... 27.8 HeapWord* offsetToHeapWord(size_t offset) const { 27.9 return _bmStartWord + (offset << _shifter); 27.10 } 27.11 @@ -105,8 +104,13 @@ 27.12 return pointer_delta(addr, _bmStartWord) >> _shifter; 27.13 } 27.14 int heapWordDiffToOffsetDiff(size_t diff) const; 27.15 - HeapWord* nextWord(HeapWord* addr) { 27.16 - return offsetToHeapWord(heapWordToOffset(addr) + 1); 27.17 + 27.18 + // The argument addr should be the start address of a valid object 27.19 + HeapWord* nextObject(HeapWord* addr) { 27.20 + oop obj = (oop) addr; 27.21 + HeapWord* res = addr + obj->size(); 27.22 + assert(offsetToHeapWord(heapWordToOffset(res)) == res, "sanity"); 27.23 + return res; 27.24 } 27.25 27.26 // debugging
28.1 --- a/src/share/vm/gc_implementation/g1/concurrentMark.inline.hpp Fri Mar 15 22:07:42 2013 -0700 28.2 +++ b/src/share/vm/gc_implementation/g1/concurrentMark.inline.hpp Sat Mar 16 21:44:52 2013 -0700 28.3 @@ -1,5 +1,5 @@ 28.4 /* 28.5 - * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. 28.6 + * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. 28.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 28.8 * 28.9 * This code is free software; you can redistribute it and/or modify it 28.10 @@ -252,12 +252,10 @@ 28.11 28.12 start_offset = _bm.get_next_one_offset(start_offset, end_offset); 28.13 while (start_offset < end_offset) { 28.14 - HeapWord* obj_addr = offsetToHeapWord(start_offset); 28.15 - oop obj = (oop) obj_addr; 28.16 if (!cl->do_bit(start_offset)) { 28.17 return false; 28.18 } 28.19 - HeapWord* next_addr = MIN2(obj_addr + obj->size(), end_addr); 28.20 + HeapWord* next_addr = MIN2(nextObject(offsetToHeapWord(start_offset)), end_addr); 28.21 BitMap::idx_t next_offset = heapWordToOffset(next_addr); 28.22 start_offset = _bm.get_next_one_offset(next_offset, end_offset); 28.23 }
29.1 --- a/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.cpp Fri Mar 15 22:07:42 2013 -0700 29.2 +++ b/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.cpp Sat Mar 16 21:44:52 2013 -0700 29.3 @@ -409,7 +409,7 @@ 29.4 // heap remains parsable. 29.5 const bool limit_exceeded = size_policy()->gc_overhead_limit_exceeded(); 29.6 const bool softrefs_clear = collector_policy()->all_soft_refs_clear(); 29.7 - assert(!limit_exceeded || softrefs_clear, "Should have been cleared"); 29.8 + 29.9 if (limit_exceeded && softrefs_clear) { 29.10 *gc_overhead_limit_was_exceeded = true; 29.11 size_policy()->set_gc_overhead_limit_exceeded(false);
30.1 --- a/src/share/vm/gc_implementation/shared/mutableNUMASpace.cpp Fri Mar 15 22:07:42 2013 -0700 30.2 +++ b/src/share/vm/gc_implementation/shared/mutableNUMASpace.cpp Sat Mar 16 21:44:52 2013 -0700 30.3 @@ -948,6 +948,8 @@ 30.4 break; 30.5 } 30.6 if (e != scan_end) { 30.7 + assert(e < scan_end, err_msg("e: " PTR_FORMAT " scan_end: " PTR_FORMAT, e, scan_end)); 30.8 + 30.9 if ((page_expected.size != page_size || page_expected.lgrp_id != lgrp_id()) 30.10 && page_expected.size != 0) { 30.11 os::free_memory(s, pointer_delta(e, s, sizeof(char)), page_size);
31.1 --- a/src/share/vm/interpreter/linkResolver.cpp Fri Mar 15 22:07:42 2013 -0700 31.2 +++ b/src/share/vm/interpreter/linkResolver.cpp Sat Mar 16 21:44:52 2013 -0700 31.3 @@ -803,7 +803,7 @@ 31.4 if (!direct_calling_default_method && 31.5 check_access && 31.6 // a) check if ACC_SUPER flag is set for the current class 31.7 - current_klass->is_super() && 31.8 + (current_klass->is_super() || !AllowNonVirtualCalls) && 31.9 // b) check if the method class is a superclass of the current class (superclass relation is not reflexive!) 31.10 current_klass->is_subtype_of(method_klass()) && 31.11 current_klass() != method_klass() &&
32.1 --- a/src/share/vm/interpreter/rewriter.cpp Fri Mar 15 22:07:42 2013 -0700 32.2 +++ b/src/share/vm/interpreter/rewriter.cpp Sat Mar 16 21:44:52 2013 -0700 32.3 @@ -84,15 +84,13 @@ 32.4 const int length = _cp_cache_map.length(); 32.5 ClassLoaderData* loader_data = _pool->pool_holder()->class_loader_data(); 32.6 ConstantPoolCache* cache = 32.7 - ConstantPoolCache::allocate(loader_data, length, CHECK); 32.8 + ConstantPoolCache::allocate(loader_data, length, _cp_cache_map, 32.9 + _invokedynamic_references_map, CHECK); 32.10 32.11 // initialize object cache in constant pool 32.12 _pool->initialize_resolved_references(loader_data, _resolved_references_map, 32.13 _resolved_reference_limit, 32.14 CHECK); 32.15 - 32.16 - No_Safepoint_Verifier nsv; 32.17 - cache->initialize(_cp_cache_map, _invokedynamic_references_map); 32.18 _pool->set_cache(cache); 32.19 cache->set_constant_pool(_pool()); 32.20 }
33.1 --- a/src/share/vm/memory/collectorPolicy.cpp Fri Mar 15 22:07:42 2013 -0700 33.2 +++ b/src/share/vm/memory/collectorPolicy.cpp Sat Mar 16 21:44:52 2013 -0700 33.3 @@ -620,7 +620,7 @@ 33.4 33.5 const bool limit_exceeded = size_policy()->gc_overhead_limit_exceeded(); 33.6 const bool softrefs_clear = all_soft_refs_clear(); 33.7 - assert(!limit_exceeded || softrefs_clear, "Should have been cleared"); 33.8 + 33.9 if (limit_exceeded && softrefs_clear) { 33.10 *gc_overhead_limit_was_exceeded = true; 33.11 size_policy()->set_gc_overhead_limit_exceeded(false);
34.1 --- a/src/share/vm/memory/filemap.hpp Fri Mar 15 22:07:42 2013 -0700 34.2 +++ b/src/share/vm/memory/filemap.hpp Sat Mar 16 21:44:52 2013 -0700 34.3 @@ -112,12 +112,19 @@ 34.4 char* region_base(int i) { return _header._space[i]._base; } 34.5 struct FileMapHeader* header() { return &_header; } 34.6 34.7 - static void set_current_info(FileMapInfo* info) { _current_info = info; } 34.8 - static FileMapInfo* current_info() { return _current_info; } 34.9 + static void set_current_info(FileMapInfo* info) { 34.10 + CDS_ONLY(_current_info = info;) 34.11 + } 34.12 + 34.13 + static FileMapInfo* current_info() { 34.14 + CDS_ONLY(return _current_info;) 34.15 + NOT_CDS(return NULL;) 34.16 + } 34.17 + 34.18 static void assert_mark(bool check); 34.19 34.20 // File manipulation. 34.21 - bool initialize(); 34.22 + bool initialize() NOT_CDS_RETURN_(false); 34.23 bool open_for_read(); 34.24 void open_for_write(); 34.25 void write_header(); 34.26 @@ -141,7 +148,7 @@ 34.27 void fail_continue(const char *msg, ...); 34.28 34.29 // Return true if given address is in the mapped shared space. 34.30 - bool is_in_shared_space(const void* p); 34.31 + bool is_in_shared_space(const void* p) NOT_CDS_RETURN_(false); 34.32 }; 34.33 34.34 #endif // SHARE_VM_MEMORY_FILEMAP_HPP
35.1 --- a/src/share/vm/memory/metablock.cpp Fri Mar 15 22:07:42 2013 -0700 35.2 +++ b/src/share/vm/memory/metablock.cpp Sat Mar 16 21:44:52 2013 -0700 35.3 @@ -1,5 +1,5 @@ 35.4 /* 35.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 35.6 + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 35.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 35.8 * 35.9 * This code is free software; you can redistribute it and/or modify it
36.1 --- a/src/share/vm/memory/metaspace.cpp Fri Mar 15 22:07:42 2013 -0700 36.2 +++ b/src/share/vm/memory/metaspace.cpp Sat Mar 16 21:44:52 2013 -0700 36.3 @@ -1,5 +1,5 @@ 36.4 /* 36.5 - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. 36.6 + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 36.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 36.8 * 36.9 * This code is free software; you can redistribute it and/or modify it 36.10 @@ -52,7 +52,6 @@ 36.11 const uint metadata_deallocate_a_lot_block = 10; 36.12 const uint metadata_deallocate_a_lock_chunk = 3; 36.13 size_t const allocation_from_dictionary_limit = 64 * K; 36.14 -const size_t metadata_deallocate = 0xf5f5f5f5; 36.15 36.16 MetaWord* last_allocated = 0; 36.17 36.18 @@ -2440,7 +2439,8 @@ 36.19 free_chunks_capacity_bytes / K, 36.20 used_and_free / K, 36.21 capacity_bytes / K); 36.22 - assert(used_and_free == capacity_bytes, "Accounting is wrong"); 36.23 + // Accounting can only be correct if we got the values during a safepoint 36.24 + assert(!SafepointSynchronize::is_at_safepoint() || used_and_free == capacity_bytes, "Accounting is wrong"); 36.25 } 36.26 36.27 // Print total fragmentation for class and data metaspaces separately
37.1 --- a/src/share/vm/memory/universe.cpp Fri Mar 15 22:07:42 2013 -0700 37.2 +++ b/src/share/vm/memory/universe.cpp Sat Mar 16 21:44:52 2013 -0700 37.3 @@ -885,6 +885,8 @@ 37.4 // the actual alignment depends on its size. 37.5 Universe::set_class_metaspace_size(align_size_up(ClassMetaspaceSize, alignment)); 37.6 size_t total_reserved = align_size_up(heap_size + Universe::class_metaspace_size(), alignment); 37.7 + assert(!UseCompressedOops || (total_reserved <= (OopEncodingHeapMax - os::vm_page_size())), 37.8 + "heap size is too big for compressed oops"); 37.9 char* addr = Universe::preferred_heap_base(total_reserved, Universe::UnscaledNarrowOop); 37.10 37.11 ReservedHeapSpace total_rs(total_reserved, alignment, UseLargePages, addr);
38.1 --- a/src/share/vm/oops/constMethod.cpp Fri Mar 15 22:07:42 2013 -0700 38.2 +++ b/src/share/vm/oops/constMethod.cpp Sat Mar 16 21:44:52 2013 -0700 38.3 @@ -55,11 +55,24 @@ 38.4 set_stackmap_data(NULL); 38.5 set_code_size(byte_code_size); 38.6 set_constMethod_size(size); 38.7 - set_inlined_tables_length(sizes); 38.8 + set_inlined_tables_length(sizes); // sets _flags 38.9 set_method_type(method_type); 38.10 assert(this->size() == size, "wrong size for object"); 38.11 + set_name_index(0); 38.12 + set_signature_index(0); 38.13 + set_constants(NULL); 38.14 + set_max_stack(0); 38.15 + set_max_locals(0); 38.16 + set_method_idnum(0); 38.17 + set_size_of_parameters(0); 38.18 } 38.19 38.20 +// Accessor that copies to metadata. 38.21 +void ConstMethod::copy_stackmap_data(ClassLoaderData* loader_data, 38.22 + u1* sd, int length, TRAPS) { 38.23 + _stackmap_data = MetadataFactory::new_array<u1>(loader_data, length, CHECK); 38.24 + memcpy((void*)_stackmap_data->adr_at(0), (void*)sd, length); 38.25 +} 38.26 38.27 // Deallocate metadata fields associated with ConstMethod* 38.28 void ConstMethod::deallocate_contents(ClassLoaderData* loader_data) {
39.1 --- a/src/share/vm/oops/constMethod.hpp Fri Mar 15 22:07:42 2013 -0700 39.2 +++ b/src/share/vm/oops/constMethod.hpp Sat Mar 16 21:44:52 2013 -0700 39.3 @@ -280,6 +280,7 @@ 39.4 // stackmap table data 39.5 Array<u1>* stackmap_data() const { return _stackmap_data; } 39.6 void set_stackmap_data(Array<u1>* sd) { _stackmap_data = sd; } 39.7 + void copy_stackmap_data(ClassLoaderData* loader_data, u1* sd, int length, TRAPS); 39.8 bool has_stackmap_table() const { return _stackmap_data != NULL; } 39.9 39.10 void init_fingerprint() {
40.1 --- a/src/share/vm/oops/cpCache.cpp Fri Mar 15 22:07:42 2013 -0700 40.2 +++ b/src/share/vm/oops/cpCache.cpp Sat Mar 16 21:44:52 2013 -0700 40.3 @@ -44,6 +44,8 @@ 40.4 void ConstantPoolCacheEntry::initialize_entry(int index) { 40.5 assert(0 < index && index < 0x10000, "sanity check"); 40.6 _indices = index; 40.7 + _f1 = NULL; 40.8 + _f2 = _flags = 0; 40.9 assert(constant_pool_index() == index, ""); 40.10 } 40.11 40.12 @@ -533,13 +535,17 @@ 40.13 40.14 // Implementation of ConstantPoolCache 40.15 40.16 -ConstantPoolCache* ConstantPoolCache::allocate(ClassLoaderData* loader_data, int length, TRAPS) { 40.17 +ConstantPoolCache* ConstantPoolCache::allocate(ClassLoaderData* loader_data, 40.18 + int length, 40.19 + const intStack& index_map, 40.20 + const intStack& invokedynamic_map, TRAPS) { 40.21 int size = ConstantPoolCache::size(length); 40.22 40.23 - return new (loader_data, size, false, THREAD) ConstantPoolCache(length); 40.24 + return new (loader_data, size, false, THREAD) ConstantPoolCache(length, index_map, invokedynamic_map); 40.25 } 40.26 40.27 -void ConstantPoolCache::initialize(intArray& inverse_index_map, intArray& invokedynamic_references_map) { 40.28 +void ConstantPoolCache::initialize(const intArray& inverse_index_map, 40.29 + const intArray& invokedynamic_references_map) { 40.30 assert(inverse_index_map.length() == length(), "inverse index map must have same length as cache"); 40.31 for (int i = 0; i < length(); i++) { 40.32 ConstantPoolCacheEntry* e = entry_at(i);
41.1 --- a/src/share/vm/oops/cpCache.hpp Fri Mar 15 22:07:42 2013 -0700 41.2 +++ b/src/share/vm/oops/cpCache.hpp Sat Mar 16 21:44:52 2013 -0700 41.3 @@ -377,14 +377,21 @@ 41.4 debug_only(friend class ClassVerifier;) 41.5 41.6 // Constructor 41.7 - ConstantPoolCache(int length) : _length(length), _constant_pool(NULL) { 41.8 + ConstantPoolCache(int length, const intStack& inverse_index_map, 41.9 + const intStack& invokedynamic_references_map) : 41.10 + _length(length), _constant_pool(NULL) { 41.11 + initialize(inverse_index_map, invokedynamic_references_map); 41.12 for (int i = 0; i < length; i++) { 41.13 assert(entry_at(i)->is_f1_null(), "Failed to clear?"); 41.14 } 41.15 } 41.16 41.17 + // Initialization 41.18 + void initialize(const intArray& inverse_index_map, const intArray& invokedynamic_references_map); 41.19 public: 41.20 - static ConstantPoolCache* allocate(ClassLoaderData* loader_data, int length, TRAPS); 41.21 + static ConstantPoolCache* allocate(ClassLoaderData* loader_data, int length, 41.22 + const intStack& inverse_index_map, 41.23 + const intStack& invokedynamic_references_map, TRAPS); 41.24 bool is_constantPoolCache() const { return true; } 41.25 41.26 int length() const { return _length; } 41.27 @@ -405,9 +412,6 @@ 41.28 friend class ConstantPoolCacheEntry; 41.29 41.30 public: 41.31 - // Initialization 41.32 - void initialize(intArray& inverse_index_map, intArray& invokedynamic_references_map); 41.33 - 41.34 // Accessors 41.35 void set_constant_pool(ConstantPool* pool) { _constant_pool = pool; } 41.36 ConstantPool* constant_pool() const { return _constant_pool; }
42.1 --- a/src/share/vm/oops/instanceKlass.cpp Fri Mar 15 22:07:42 2013 -0700 42.2 +++ b/src/share/vm/oops/instanceKlass.cpp Sat Mar 16 21:44:52 2013 -0700 42.3 @@ -165,7 +165,8 @@ 42.4 42.5 volatile int InstanceKlass::_total_instanceKlass_count = 0; 42.6 42.7 -Klass* InstanceKlass::allocate_instance_klass(ClassLoaderData* loader_data, 42.8 +InstanceKlass* InstanceKlass::allocate_instance_klass( 42.9 + ClassLoaderData* loader_data, 42.10 int vtable_len, 42.11 int itable_len, 42.12 int static_field_size, 42.13 @@ -207,10 +208,35 @@ 42.14 access_flags, is_anonymous); 42.15 } 42.16 42.17 + // Check for pending exception before adding to the loader data and incrementing 42.18 + // class count. Can get OOM here. 42.19 + if (HAS_PENDING_EXCEPTION) { 42.20 + return NULL; 42.21 + } 42.22 + 42.23 + // Add all classes to our internal class loader list here, 42.24 + // including classes in the bootstrap (NULL) class loader. 42.25 + loader_data->add_class(ik); 42.26 + 42.27 Atomic::inc(&_total_instanceKlass_count); 42.28 return ik; 42.29 } 42.30 42.31 + 42.32 +// copy method ordering from resource area to Metaspace 42.33 +void InstanceKlass::copy_method_ordering(intArray* m, TRAPS) { 42.34 + if (m != NULL) { 42.35 + // allocate a new array and copy contents (memcpy?) 42.36 + _method_ordering = MetadataFactory::new_array<int>(class_loader_data(), m->length(), CHECK); 42.37 + for (int i = 0; i < m->length(); i++) { 42.38 + _method_ordering->at_put(i, m->at(i)); 42.39 + } 42.40 + } else { 42.41 + _method_ordering = Universe::the_empty_int_array(); 42.42 + } 42.43 +} 42.44 + 42.45 + 42.46 InstanceKlass::InstanceKlass(int vtable_len, 42.47 int itable_len, 42.48 int static_field_size, 42.49 @@ -220,72 +246,116 @@ 42.50 bool is_anonymous) { 42.51 No_Safepoint_Verifier no_safepoint; // until k becomes parsable 42.52 42.53 - int size = InstanceKlass::size(vtable_len, itable_len, nonstatic_oop_map_size, 42.54 - access_flags.is_interface(), is_anonymous); 42.55 - 42.56 - // The sizes of these these three variables are used for determining the 42.57 - // size of the instanceKlassOop. It is critical that these are set to the right 42.58 - // sizes before the first GC, i.e., when we allocate the mirror. 42.59 - this->set_vtable_length(vtable_len); 42.60 - this->set_itable_length(itable_len); 42.61 - this->set_static_field_size(static_field_size); 42.62 - this->set_nonstatic_oop_map_size(nonstatic_oop_map_size); 42.63 - this->set_access_flags(access_flags); 42.64 - this->set_is_anonymous(is_anonymous); 42.65 - assert(this->size() == size, "wrong size for object"); 42.66 - 42.67 - this->set_array_klasses(NULL); 42.68 - this->set_methods(NULL); 42.69 - this->set_method_ordering(NULL); 42.70 - this->set_local_interfaces(NULL); 42.71 - this->set_transitive_interfaces(NULL); 42.72 - this->init_implementor(); 42.73 - this->set_fields(NULL, 0); 42.74 - this->set_constants(NULL); 42.75 - this->set_class_loader_data(NULL); 42.76 - this->set_protection_domain(NULL); 42.77 - this->set_signers(NULL); 42.78 - this->set_source_file_name(NULL); 42.79 - this->set_source_debug_extension(NULL, 0); 42.80 - this->set_array_name(NULL); 42.81 - this->set_inner_classes(NULL); 42.82 - this->set_static_oop_field_count(0); 42.83 - this->set_nonstatic_field_size(0); 42.84 - this->set_is_marked_dependent(false); 42.85 - this->set_init_state(InstanceKlass::allocated); 42.86 - this->set_init_thread(NULL); 42.87 - this->set_init_lock(NULL); 42.88 - this->set_reference_type(rt); 42.89 - this->set_oop_map_cache(NULL); 42.90 - this->set_jni_ids(NULL); 42.91 - this->set_osr_nmethods_head(NULL); 42.92 - this->set_breakpoints(NULL); 42.93 - this->init_previous_versions(); 42.94 - this->set_generic_signature(NULL); 42.95 - this->release_set_methods_jmethod_ids(NULL); 42.96 - this->release_set_methods_cached_itable_indices(NULL); 42.97 - this->set_annotations(NULL); 42.98 - this->set_jvmti_cached_class_field_map(NULL); 42.99 - this->set_initial_method_idnum(0); 42.100 + int iksize = InstanceKlass::size(vtable_len, itable_len, nonstatic_oop_map_size, 42.101 + access_flags.is_interface(), is_anonymous); 42.102 + 42.103 + set_vtable_length(vtable_len); 42.104 + set_itable_length(itable_len); 42.105 + set_static_field_size(static_field_size); 42.106 + set_nonstatic_oop_map_size(nonstatic_oop_map_size); 42.107 + set_access_flags(access_flags); 42.108 + _misc_flags = 0; // initialize to zero 42.109 + set_is_anonymous(is_anonymous); 42.110 + assert(size() == iksize, "wrong size for object"); 42.111 + 42.112 + set_array_klasses(NULL); 42.113 + set_methods(NULL); 42.114 + set_method_ordering(NULL); 42.115 + set_local_interfaces(NULL); 42.116 + set_transitive_interfaces(NULL); 42.117 + init_implementor(); 42.118 + set_fields(NULL, 0); 42.119 + set_constants(NULL); 42.120 + set_class_loader_data(NULL); 42.121 + set_protection_domain(NULL); 42.122 + set_signers(NULL); 42.123 + set_source_file_name(NULL); 42.124 + set_source_debug_extension(NULL, 0); 42.125 + set_array_name(NULL); 42.126 + set_inner_classes(NULL); 42.127 + set_static_oop_field_count(0); 42.128 + set_nonstatic_field_size(0); 42.129 + set_is_marked_dependent(false); 42.130 + set_init_state(InstanceKlass::allocated); 42.131 + set_init_thread(NULL); 42.132 + set_init_lock(NULL); 42.133 + set_reference_type(rt); 42.134 + set_oop_map_cache(NULL); 42.135 + set_jni_ids(NULL); 42.136 + set_osr_nmethods_head(NULL); 42.137 + set_breakpoints(NULL); 42.138 + init_previous_versions(); 42.139 + set_generic_signature(NULL); 42.140 + release_set_methods_jmethod_ids(NULL); 42.141 + release_set_methods_cached_itable_indices(NULL); 42.142 + set_annotations(NULL); 42.143 + set_jvmti_cached_class_field_map(NULL); 42.144 + set_initial_method_idnum(0); 42.145 + _dependencies = NULL; 42.146 + set_jvmti_cached_class_field_map(NULL); 42.147 + set_cached_class_file(NULL, 0); 42.148 + set_initial_method_idnum(0); 42.149 + set_minor_version(0); 42.150 + set_major_version(0); 42.151 + NOT_PRODUCT(_verify_count = 0;) 42.152 42.153 // initialize the non-header words to zero 42.154 intptr_t* p = (intptr_t*)this; 42.155 - for (int index = InstanceKlass::header_size(); index < size; index++) { 42.156 + for (int index = InstanceKlass::header_size(); index < iksize; index++) { 42.157 p[index] = NULL_WORD; 42.158 } 42.159 42.160 // Set temporary value until parseClassFile updates it with the real instance 42.161 // size. 42.162 - this->set_layout_helper(Klass::instance_layout_helper(0, true)); 42.163 + set_layout_helper(Klass::instance_layout_helper(0, true)); 42.164 } 42.165 42.166 42.167 +void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data, 42.168 + Array<Method*>* methods) { 42.169 + if (methods != NULL && methods != Universe::the_empty_method_array()) { 42.170 + for (int i = 0; i < methods->length(); i++) { 42.171 + Method* method = methods->at(i); 42.172 + if (method == NULL) continue; // maybe null if error processing 42.173 + // Only want to delete methods that are not executing for RedefineClasses. 42.174 + // The previous version will point to them so they're not totally dangling 42.175 + assert (!method->on_stack(), "shouldn't be called with methods on stack"); 42.176 + MetadataFactory::free_metadata(loader_data, method); 42.177 + } 42.178 + MetadataFactory::free_array<Method*>(loader_data, methods); 42.179 + } 42.180 +} 42.181 + 42.182 +void InstanceKlass::deallocate_interfaces(ClassLoaderData* loader_data, 42.183 + Klass* super_klass, 42.184 + Array<Klass*>* local_interfaces, 42.185 + Array<Klass*>* transitive_interfaces) { 42.186 + // Only deallocate transitive interfaces if not empty, same as super class 42.187 + // or same as local interfaces. See code in parseClassFile. 42.188 + Array<Klass*>* ti = transitive_interfaces; 42.189 + if (ti != Universe::the_empty_klass_array() && ti != local_interfaces) { 42.190 + // check that the interfaces don't come from super class 42.191 + Array<Klass*>* sti = (super_klass == NULL) ? NULL : 42.192 + InstanceKlass::cast(super_klass)->transitive_interfaces(); 42.193 + if (ti != sti) { 42.194 + MetadataFactory::free_array<Klass*>(loader_data, ti); 42.195 + } 42.196 + } 42.197 + 42.198 + // local interfaces can be empty 42.199 + if (local_interfaces != Universe::the_empty_klass_array()) { 42.200 + MetadataFactory::free_array<Klass*>(loader_data, local_interfaces); 42.201 + } 42.202 +} 42.203 + 42.204 // This function deallocates the metadata and C heap pointers that the 42.205 // InstanceKlass points to. 42.206 void InstanceKlass::deallocate_contents(ClassLoaderData* loader_data) { 42.207 42.208 // Orphan the mirror first, CMS thinks it's still live. 42.209 - java_lang_Class::set_klass(java_mirror(), NULL); 42.210 + if (java_mirror() != NULL) { 42.211 + java_lang_Class::set_klass(java_mirror(), NULL); 42.212 + } 42.213 42.214 // Need to take this class off the class loader data list. 42.215 loader_data->remove_class(this); 42.216 @@ -300,17 +370,7 @@ 42.217 // reference counting symbol names. 42.218 release_C_heap_structures(); 42.219 42.220 - Array<Method*>* ms = methods(); 42.221 - if (ms != Universe::the_empty_method_array()) { 42.222 - for (int i = 0; i <= methods()->length() -1 ; i++) { 42.223 - Method* method = methods()->at(i); 42.224 - // Only want to delete methods that are not executing for RedefineClasses. 42.225 - // The previous version will point to them so they're not totally dangling 42.226 - assert (!method->on_stack(), "shouldn't be called with methods on stack"); 42.227 - MetadataFactory::free_metadata(loader_data, method); 42.228 - } 42.229 - MetadataFactory::free_array<Method*>(loader_data, methods()); 42.230 - } 42.231 + deallocate_methods(loader_data, methods()); 42.232 set_methods(NULL); 42.233 42.234 if (method_ordering() != Universe::the_empty_int_array()) { 42.235 @@ -327,24 +387,8 @@ 42.236 } 42.237 set_secondary_supers(NULL); 42.238 42.239 - // Only deallocate transitive interfaces if not empty, same as super class 42.240 - // or same as local interfaces. See code in parseClassFile. 42.241 - Array<Klass*>* ti = transitive_interfaces(); 42.242 - if (ti != Universe::the_empty_klass_array() && ti != local_interfaces()) { 42.243 - // check that the interfaces don't come from super class 42.244 - Array<Klass*>* sti = (super() == NULL) ? NULL : 42.245 - InstanceKlass::cast(super())->transitive_interfaces(); 42.246 - if (ti != sti) { 42.247 - MetadataFactory::free_array<Klass*>(loader_data, ti); 42.248 - } 42.249 - } 42.250 + deallocate_interfaces(loader_data, super(), local_interfaces(), transitive_interfaces()); 42.251 set_transitive_interfaces(NULL); 42.252 - 42.253 - // local interfaces can be empty 42.254 - Array<Klass*>* li = local_interfaces(); 42.255 - if (li != Universe::the_empty_klass_array()) { 42.256 - MetadataFactory::free_array<Klass*>(loader_data, li); 42.257 - } 42.258 set_local_interfaces(NULL); 42.259 42.260 MetadataFactory::free_array<jushort>(loader_data, fields()); 42.261 @@ -352,9 +396,11 @@ 42.262 42.263 // If a method from a redefined class is using this constant pool, don't 42.264 // delete it, yet. The new class's previous version will point to this. 42.265 - assert (!constants()->on_stack(), "shouldn't be called if anything is onstack"); 42.266 - MetadataFactory::free_metadata(loader_data, constants()); 42.267 - set_constants(NULL); 42.268 + if (constants() != NULL) { 42.269 + assert (!constants()->on_stack(), "shouldn't be called if anything is onstack"); 42.270 + MetadataFactory::free_metadata(loader_data, constants()); 42.271 + set_constants(NULL); 42.272 + } 42.273 42.274 if (inner_classes() != Universe::the_empty_short_array()) { 42.275 MetadataFactory::free_array<jushort>(loader_data, inner_classes()); 42.276 @@ -2785,7 +2831,7 @@ 42.277 st->print(BULLET"protection domain: "); ((InstanceKlass*)this)->protection_domain()->print_value_on(st); st->cr(); 42.278 st->print(BULLET"host class: "); host_klass()->print_value_on_maybe_null(st); st->cr(); 42.279 st->print(BULLET"signers: "); signers()->print_value_on(st); st->cr(); 42.280 - st->print(BULLET"init_lock: "); ((oop)init_lock())->print_value_on(st); st->cr(); 42.281 + st->print(BULLET"init_lock: "); ((oop)_init_lock)->print_value_on(st); st->cr(); 42.282 if (source_file_name() != NULL) { 42.283 st->print(BULLET"source file: "); 42.284 source_file_name()->print_value_on(st);
43.1 --- a/src/share/vm/oops/instanceKlass.hpp Fri Mar 15 22:07:42 2013 -0700 43.2 +++ b/src/share/vm/oops/instanceKlass.hpp Sat Mar 16 21:44:52 2013 -0700 43.3 @@ -147,7 +147,8 @@ 43.4 AccessFlags access_flags, 43.5 bool is_anonymous); 43.6 public: 43.7 - static Klass* allocate_instance_klass(ClassLoaderData* loader_data, 43.8 + static InstanceKlass* allocate_instance_klass( 43.9 + ClassLoaderData* loader_data, 43.10 int vtable_len, 43.11 int itable_len, 43.12 int static_field_size, 43.13 @@ -266,8 +267,9 @@ 43.14 u1 _init_state; // state of class 43.15 u1 _reference_type; // reference type 43.16 43.17 + JvmtiCachedClassFieldMap* _jvmti_cached_class_field_map; // JVMTI: used during heap iteration 43.18 43.19 - JvmtiCachedClassFieldMap* _jvmti_cached_class_field_map; // JVMTI: used during heap iteration 43.20 + NOT_PRODUCT(int _verify_count;) // to avoid redundant verifies 43.21 43.22 // Method array. 43.23 Array<Method*>* _methods; 43.24 @@ -356,16 +358,19 @@ 43.25 // method ordering 43.26 Array<int>* method_ordering() const { return _method_ordering; } 43.27 void set_method_ordering(Array<int>* m) { _method_ordering = m; } 43.28 + void copy_method_ordering(intArray* m, TRAPS); 43.29 43.30 // interfaces 43.31 Array<Klass*>* local_interfaces() const { return _local_interfaces; } 43.32 void set_local_interfaces(Array<Klass*>* a) { 43.33 guarantee(_local_interfaces == NULL || a == NULL, "Just checking"); 43.34 _local_interfaces = a; } 43.35 + 43.36 Array<Klass*>* transitive_interfaces() const { return _transitive_interfaces; } 43.37 void set_transitive_interfaces(Array<Klass*>* a) { 43.38 guarantee(_transitive_interfaces == NULL || a == NULL, "Just checking"); 43.39 - _transitive_interfaces = a; } 43.40 + _transitive_interfaces = a; 43.41 + } 43.42 43.43 private: 43.44 friend class fieldDescriptor; 43.45 @@ -381,10 +386,9 @@ 43.46 int java_fields_count() const { return (int)_java_fields_count; } 43.47 43.48 Array<u2>* fields() const { return _fields; } 43.49 - 43.50 void set_fields(Array<u2>* f, u2 java_fields_count) { 43.51 guarantee(_fields == NULL || f == NULL, "Just checking"); 43.52 - _fields = f; 43.53 + _fields = f; 43.54 _java_fields_count = java_fields_count; 43.55 } 43.56 43.57 @@ -588,7 +592,7 @@ 43.58 43.59 // symbol unloading support (refcount already added) 43.60 Symbol* array_name() { return _array_name; } 43.61 - void set_array_name(Symbol* name) { assert(_array_name == NULL, "name already created"); _array_name = name; } 43.62 + void set_array_name(Symbol* name) { assert(_array_name == NULL || name == NULL, "name already created"); _array_name = name; } 43.63 43.64 // nonstatic oop-map blocks 43.65 static int nonstatic_oop_map_size(unsigned int oop_map_count) { 43.66 @@ -914,8 +918,15 @@ 43.67 void clean_method_data(BoolObjectClosure* is_alive); 43.68 43.69 // Explicit metaspace deallocation of fields 43.70 - // For RedefineClasses, we need to deallocate instanceKlasses 43.71 + // For RedefineClasses and class file parsing errors, we need to deallocate 43.72 + // instanceKlasses and the metadata they point to. 43.73 void deallocate_contents(ClassLoaderData* loader_data); 43.74 + static void deallocate_methods(ClassLoaderData* loader_data, 43.75 + Array<Method*>* methods); 43.76 + void static deallocate_interfaces(ClassLoaderData* loader_data, 43.77 + Klass* super_klass, 43.78 + Array<Klass*>* local_interfaces, 43.79 + Array<Klass*>* transitive_interfaces); 43.80 43.81 // The constant pool is on stack if any of the methods are executing or 43.82 // referenced by handles.
44.1 --- a/src/share/vm/oops/klass.cpp Fri Mar 15 22:07:42 2013 -0700 44.2 +++ b/src/share/vm/oops/klass.cpp Sat Mar 16 21:44:52 2013 -0700 44.3 @@ -146,16 +146,16 @@ 44.4 Klass::Klass() { 44.5 Klass* k = this; 44.6 44.7 - { // Preinitialize supertype information. 44.8 - // A later call to initialize_supers() may update these settings: 44.9 - set_super(NULL); 44.10 - for (juint i = 0; i < Klass::primary_super_limit(); i++) { 44.11 - _primary_supers[i] = NULL; 44.12 - } 44.13 - set_secondary_supers(NULL); 44.14 - _primary_supers[0] = k; 44.15 - set_super_check_offset(in_bytes(primary_supers_offset())); 44.16 + // Preinitialize supertype information. 44.17 + // A later call to initialize_supers() may update these settings: 44.18 + set_super(NULL); 44.19 + for (juint i = 0; i < Klass::primary_super_limit(); i++) { 44.20 + _primary_supers[i] = NULL; 44.21 } 44.22 + set_secondary_supers(NULL); 44.23 + set_secondary_super_cache(NULL); 44.24 + _primary_supers[0] = k; 44.25 + set_super_check_offset(in_bytes(primary_supers_offset())); 44.26 44.27 set_java_mirror(NULL); 44.28 set_modifier_flags(0);
45.1 --- a/src/share/vm/oops/klass.hpp Fri Mar 15 22:07:42 2013 -0700 45.2 +++ b/src/share/vm/oops/klass.hpp Sat Mar 16 21:44:52 2013 -0700 45.3 @@ -79,7 +79,6 @@ 45.4 // [last_biased_lock_bulk_revocation_time] (64 bits) 45.5 // [prototype_header] 45.6 // [biased_lock_revocation_count] 45.7 -// [verify_count ] - not in product 45.8 // [alloc_count ] 45.9 // [_modified_oops] 45.10 // [_accumulated_modified_oops] 45.11 @@ -172,10 +171,6 @@ 45.12 markOop _prototype_header; // Used when biased locking is both enabled and disabled for this type 45.13 jint _biased_lock_revocation_count; 45.14 45.15 -#ifndef PRODUCT 45.16 - int _verify_count; // to avoid redundant verifies 45.17 -#endif 45.18 - 45.19 juint _alloc_count; // allocation profiling support 45.20 45.21 TRACE_DEFINE_KLASS_TRACE_ID;
46.1 --- a/src/share/vm/oops/method.cpp Fri Mar 15 22:07:42 2013 -0700 46.2 +++ b/src/share/vm/oops/method.cpp Sat Mar 16 21:44:52 2013 -0700 46.3 @@ -77,22 +77,19 @@ 46.4 return new (loader_data, size, false, THREAD) Method(cm, access_flags, size); 46.5 } 46.6 46.7 -Method::Method(ConstMethod* xconst, 46.8 - AccessFlags access_flags, int size) { 46.9 +Method::Method(ConstMethod* xconst, AccessFlags access_flags, int size) { 46.10 No_Safepoint_Verifier no_safepoint; 46.11 set_constMethod(xconst); 46.12 set_access_flags(access_flags); 46.13 set_method_size(size); 46.14 - set_name_index(0); 46.15 - set_signature_index(0); 46.16 #ifdef CC_INTERP 46.17 set_result_index(T_VOID); 46.18 #endif 46.19 - set_constants(NULL); 46.20 - set_max_stack(0); 46.21 - set_max_locals(0); 46.22 set_intrinsic_id(vmIntrinsics::_none); 46.23 set_jfr_towrite(false); 46.24 + set_force_inline(false); 46.25 + set_hidden(false); 46.26 + set_dont_inline(false); 46.27 set_method_data(NULL); 46.28 set_interpreter_throwout_count(0); 46.29 set_vtable_index(Method::garbage_vtable_index);
47.1 --- a/src/share/vm/oops/methodData.cpp Fri Mar 15 22:07:42 2013 -0700 47.2 +++ b/src/share/vm/oops/methodData.cpp Sat Mar 16 21:44:52 2013 -0700 47.3 @@ -652,23 +652,25 @@ 47.4 // Set the method back-pointer. 47.5 _method = method(); 47.6 47.7 - if (TieredCompilation) { 47.8 - _invocation_counter.init(); 47.9 - _backedge_counter.init(); 47.10 - _invocation_counter_start = 0; 47.11 - _backedge_counter_start = 0; 47.12 - _num_loops = 0; 47.13 - _num_blocks = 0; 47.14 - _highest_comp_level = 0; 47.15 - _highest_osr_comp_level = 0; 47.16 - _would_profile = true; 47.17 - } 47.18 + _invocation_counter.init(); 47.19 + _backedge_counter.init(); 47.20 + _invocation_counter_start = 0; 47.21 + _backedge_counter_start = 0; 47.22 + _num_loops = 0; 47.23 + _num_blocks = 0; 47.24 + _highest_comp_level = 0; 47.25 + _highest_osr_comp_level = 0; 47.26 + _would_profile = true; 47.27 set_creation_mileage(mileage_of(method())); 47.28 47.29 // Initialize flags and trap history. 47.30 _nof_decompiles = 0; 47.31 _nof_overflow_recompiles = 0; 47.32 _nof_overflow_traps = 0; 47.33 + _eflags = 0; 47.34 + _arg_local = 0; 47.35 + _arg_stack = 0; 47.36 + _arg_returned = 0; 47.37 assert(sizeof(_trap_hist) % sizeof(HeapWord) == 0, "align"); 47.38 Copy::zero_to_words((HeapWord*) &_trap_hist, 47.39 sizeof(_trap_hist) / sizeof(HeapWord)); 47.40 @@ -677,6 +679,7 @@ 47.41 // corresponding data cells. 47.42 int data_size = 0; 47.43 int empty_bc_count = 0; // number of bytecodes lacking data 47.44 + _data[0] = 0; // apparently not set below. 47.45 BytecodeStream stream(method); 47.46 Bytecodes::Code c; 47.47 while ((c = stream.next()) >= 0) { 47.48 @@ -710,6 +713,7 @@ 47.49 post_initialize(&stream); 47.50 47.51 set_size(object_size); 47.52 + 47.53 } 47.54 47.55 // Get a measure of how much mileage the method has on it.
48.1 --- a/src/share/vm/opto/type.cpp Fri Mar 15 22:07:42 2013 -0700 48.2 +++ b/src/share/vm/opto/type.cpp Sat Mar 16 21:44:52 2013 -0700 48.3 @@ -4193,6 +4193,7 @@ 48.4 bool xk = klass_is_exact(); 48.5 //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0); 48.6 const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k); 48.7 + guarantee(toop != NULL, "need type for given klass"); 48.8 toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr(); 48.9 return toop->cast_to_exactness(xk)->is_oopptr(); 48.10 }
49.1 --- a/src/share/vm/prims/jvmtiImpl.cpp Fri Mar 15 22:07:42 2013 -0700 49.2 +++ b/src/share/vm/prims/jvmtiImpl.cpp Sat Mar 16 21:44:52 2013 -0700 49.3 @@ -890,7 +890,7 @@ 49.4 49.5 tty->print("Suspended Threads: ["); 49.6 for (JavaThread *thread = Threads::first(); thread != NULL; thread = thread->next()) { 49.7 -#if JVMTI_TRACE 49.8 +#ifdef JVMTI_TRACE 49.9 const char *name = JvmtiTrace::safe_get_thread_name(thread); 49.10 #else 49.11 const char *name = "";
50.1 --- a/src/share/vm/prims/jvmtiTrace.hpp Fri Mar 15 22:07:42 2013 -0700 50.2 +++ b/src/share/vm/prims/jvmtiTrace.hpp Sat Mar 16 21:44:52 2013 -0700 50.3 @@ -43,10 +43,10 @@ 50.4 50.5 // Support tracing except in product build on the client compiler 50.6 #ifndef PRODUCT 50.7 -#define JVMTI_TRACE 1 50.8 +#define JVMTI_TRACE 50.9 #else 50.10 #ifdef COMPILER2 50.11 -#define JVMTI_TRACE 1 50.12 +#define JVMTI_TRACE 50.13 #endif 50.14 #endif 50.15
51.1 --- a/src/share/vm/runtime/arguments.cpp Fri Mar 15 22:07:42 2013 -0700 51.2 +++ b/src/share/vm/runtime/arguments.cpp Sat Mar 16 21:44:52 2013 -0700 51.3 @@ -1381,6 +1381,40 @@ 51.4 return false; 51.5 } 51.6 51.7 +void Arguments::set_use_compressed_oops() { 51.8 +#ifndef ZERO 51.9 +#ifdef _LP64 51.10 + // MaxHeapSize is not set up properly at this point, but 51.11 + // the only value that can override MaxHeapSize if we are 51.12 + // to use UseCompressedOops is InitialHeapSize. 51.13 + size_t max_heap_size = MAX2(MaxHeapSize, InitialHeapSize); 51.14 + 51.15 + if (max_heap_size <= max_heap_for_compressed_oops()) { 51.16 +#if !defined(COMPILER1) || defined(TIERED) 51.17 + if (FLAG_IS_DEFAULT(UseCompressedOops)) { 51.18 + FLAG_SET_ERGO(bool, UseCompressedOops, true); 51.19 + } 51.20 +#endif 51.21 +#ifdef _WIN64 51.22 + if (UseLargePages && UseCompressedOops) { 51.23 + // Cannot allocate guard pages for implicit checks in indexed addressing 51.24 + // mode, when large pages are specified on windows. 51.25 + // This flag could be switched ON if narrow oop base address is set to 0, 51.26 + // see code in Universe::initialize_heap(). 51.27 + Universe::set_narrow_oop_use_implicit_null_checks(false); 51.28 + } 51.29 +#endif // _WIN64 51.30 + } else { 51.31 + if (UseCompressedOops && !FLAG_IS_DEFAULT(UseCompressedOops)) { 51.32 + warning("Max heap size too large for Compressed Oops"); 51.33 + FLAG_SET_DEFAULT(UseCompressedOops, false); 51.34 + FLAG_SET_DEFAULT(UseCompressedKlassPointers, false); 51.35 + } 51.36 + } 51.37 +#endif // _LP64 51.38 +#endif // ZERO 51.39 +} 51.40 + 51.41 void Arguments::set_ergonomics_flags() { 51.42 51.43 if (os::is_server_class_machine()) { 51.44 @@ -1410,30 +1444,7 @@ 51.45 51.46 #ifndef ZERO 51.47 #ifdef _LP64 51.48 - // Check that UseCompressedOops can be set with the max heap size allocated 51.49 - // by ergonomics. 51.50 - if (MaxHeapSize <= max_heap_for_compressed_oops()) { 51.51 -#if !defined(COMPILER1) || defined(TIERED) 51.52 - if (FLAG_IS_DEFAULT(UseCompressedOops)) { 51.53 - FLAG_SET_ERGO(bool, UseCompressedOops, true); 51.54 - } 51.55 -#endif 51.56 -#ifdef _WIN64 51.57 - if (UseLargePages && UseCompressedOops) { 51.58 - // Cannot allocate guard pages for implicit checks in indexed addressing 51.59 - // mode, when large pages are specified on windows. 51.60 - // This flag could be switched ON if narrow oop base address is set to 0, 51.61 - // see code in Universe::initialize_heap(). 51.62 - Universe::set_narrow_oop_use_implicit_null_checks(false); 51.63 - } 51.64 -#endif // _WIN64 51.65 - } else { 51.66 - if (UseCompressedOops && !FLAG_IS_DEFAULT(UseCompressedOops)) { 51.67 - warning("Max heap size too large for Compressed Oops"); 51.68 - FLAG_SET_DEFAULT(UseCompressedOops, false); 51.69 - FLAG_SET_DEFAULT(UseCompressedKlassPointers, false); 51.70 - } 51.71 - } 51.72 + set_use_compressed_oops(); 51.73 // UseCompressedOops must be on for UseCompressedKlassPointers to be on. 51.74 if (!UseCompressedOops) { 51.75 if (UseCompressedKlassPointers) { 51.76 @@ -1813,6 +1824,13 @@ 51.77 } 51.78 } 51.79 51.80 +void Arguments::check_deprecated_gc_flags() { 51.81 + if (FLAG_IS_CMDLINE(MaxGCMinorPauseMillis)) { 51.82 + warning("Using MaxGCMinorPauseMillis as minor pause goal is deprecated" 51.83 + "and will likely be removed in future release"); 51.84 + } 51.85 +} 51.86 + 51.87 // Check stack pages settings 51.88 bool Arguments::check_stack_pages() 51.89 { 51.90 @@ -2273,10 +2291,12 @@ 51.91 } 51.92 #if !INCLUDE_JVMTI 51.93 if ((strcmp(name, "hprof") == 0) || (strcmp(name, "jdwp") == 0)) { 51.94 - warning("profiling and debugging agents are not supported in this VM"); 51.95 - } else 51.96 + jio_fprintf(defaultStream::error_stream(), 51.97 + "Profiling and debugging agents are not supported in this VM\n"); 51.98 + return JNI_ERR; 51.99 + } 51.100 #endif // !INCLUDE_JVMTI 51.101 - add_init_library(name, options); 51.102 + add_init_library(name, options); 51.103 } 51.104 // -agentlib and -agentpath 51.105 } else if (match_option(option, "-agentlib:", &tail) || 51.106 @@ -2293,16 +2313,19 @@ 51.107 } 51.108 #if !INCLUDE_JVMTI 51.109 if ((strcmp(name, "hprof") == 0) || (strcmp(name, "jdwp") == 0)) { 51.110 - warning("profiling and debugging agents are not supported in this VM"); 51.111 - } else 51.112 + jio_fprintf(defaultStream::error_stream(), 51.113 + "Profiling and debugging agents are not supported in this VM\n"); 51.114 + return JNI_ERR; 51.115 + } 51.116 #endif // !INCLUDE_JVMTI 51.117 add_init_agent(name, options, is_absolute_path); 51.118 - 51.119 } 51.120 // -javaagent 51.121 } else if (match_option(option, "-javaagent:", &tail)) { 51.122 #if !INCLUDE_JVMTI 51.123 - warning("Instrumentation agents are not supported in this VM"); 51.124 + jio_fprintf(defaultStream::error_stream(), 51.125 + "Instrumentation agents are not supported in this VM\n"); 51.126 + return JNI_ERR; 51.127 #else 51.128 if(tail != NULL) { 51.129 char *options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(tail) + 1, mtInternal), tail); 51.130 @@ -2443,8 +2466,9 @@ 51.131 #if INCLUDE_FPROF 51.132 _has_profile = true; 51.133 #else // INCLUDE_FPROF 51.134 - // do we have to exit? 51.135 - warning("Flat profiling is not supported in this VM."); 51.136 + jio_fprintf(defaultStream::error_stream(), 51.137 + "Flat profiling is not supported in this VM.\n"); 51.138 + return JNI_ERR; 51.139 #endif // INCLUDE_FPROF 51.140 // -Xaprof 51.141 } else if (match_option(option, "-Xaprof", &tail)) { 51.142 @@ -2478,8 +2502,9 @@ 51.143 #if INCLUDE_MANAGEMENT 51.144 FLAG_SET_CMDLINE(bool, ManagementServer, true); 51.145 #else 51.146 - vm_exit_during_initialization( 51.147 - "-Dcom.sun.management is not supported in this VM.", NULL); 51.148 + jio_fprintf(defaultStream::output_stream(), 51.149 + "-Dcom.sun.management is not supported in this VM.\n"); 51.150 + return JNI_ERR; 51.151 #endif 51.152 } 51.153 // -Xint 51.154 @@ -2492,16 +2517,10 @@ 51.155 } else if (match_option(option, "-Xcomp", &tail)) { 51.156 // for testing the compiler; turn off all flags that inhibit compilation 51.157 set_mode_flags(_comp); 51.158 - 51.159 // -Xshare:dump 51.160 } else if (match_option(option, "-Xshare:dump", &tail)) { 51.161 -#if !INCLUDE_CDS 51.162 - vm_exit_during_initialization( 51.163 - "Dumping a shared archive is not supported in this VM.", NULL); 51.164 -#else 51.165 FLAG_SET_CMDLINE(bool, DumpSharedSpaces, true); 51.166 set_mode_flags(_int); // Prevent compilation, which creates objects 51.167 -#endif 51.168 // -Xshare:on 51.169 } else if (match_option(option, "-Xshare:on", &tail)) { 51.170 FLAG_SET_CMDLINE(bool, UseSharedSpaces, true); 51.171 @@ -2514,7 +2533,6 @@ 51.172 } else if (match_option(option, "-Xshare:off", &tail)) { 51.173 FLAG_SET_CMDLINE(bool, UseSharedSpaces, false); 51.174 FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false); 51.175 - 51.176 // -Xverify 51.177 } else if (match_option(option, "-Xverify", &tail)) { 51.178 if (strcmp(tail, ":all") == 0 || strcmp(tail, "") == 0) { 51.179 @@ -2828,8 +2846,9 @@ 51.180 FLAG_SET_CMDLINE(bool, UseVMInterruptibleIO, true); 51.181 #if !INCLUDE_MANAGEMENT 51.182 } else if (match_option(option, "-XX:+ManagementServer", &tail)) { 51.183 - vm_exit_during_initialization( 51.184 - "ManagementServer is not supported in this VM.", NULL); 51.185 + jio_fprintf(defaultStream::error_stream(), 51.186 + "ManagementServer is not supported in this VM.\n"); 51.187 + return JNI_ERR; 51.188 #endif // INCLUDE_MANAGEMENT 51.189 } else if (match_option(option, "-XX:", &tail)) { // -XX:xxxx 51.190 // Skip -XX:Flags= since that case has already been handled 51.191 @@ -3135,7 +3154,9 @@ 51.192 #if INCLUDE_NMT 51.193 MemTracker::init_tracking_options(tail); 51.194 #else 51.195 - warning("Native Memory Tracking is not supported in this VM"); 51.196 + jio_fprintf(defaultStream::error_stream(), 51.197 + "Native Memory Tracking is not supported in this VM\n"); 51.198 + return JNI_ERR; 51.199 #endif 51.200 } 51.201 51.202 @@ -3254,6 +3275,16 @@ 51.203 force_serial_gc(); 51.204 #endif // INCLUDE_ALL_GCS 51.205 #if !INCLUDE_CDS 51.206 + if (DumpSharedSpaces || RequireSharedSpaces) { 51.207 + jio_fprintf(defaultStream::error_stream(), 51.208 + "Shared spaces are not supported in this VM\n"); 51.209 + return JNI_ERR; 51.210 + } 51.211 + if ((UseSharedSpaces && FLAG_IS_CMDLINE(UseSharedSpaces)) || PrintSharedSpaces) { 51.212 + warning("Shared spaces are not supported in this VM"); 51.213 + FLAG_SET_DEFAULT(UseSharedSpaces, false); 51.214 + FLAG_SET_DEFAULT(PrintSharedSpaces, false); 51.215 + } 51.216 no_shared_spaces(); 51.217 #endif // INCLUDE_CDS 51.218 51.219 @@ -3292,6 +3323,7 @@ 51.220 set_g1_gc_flags(); 51.221 } 51.222 check_deprecated_gcs(); 51.223 + check_deprecated_gc_flags(); 51.224 #else // INCLUDE_ALL_GCS 51.225 assert(verify_serial_gc_flags(), "SerialGC unset"); 51.226 #endif // INCLUDE_ALL_GCS
52.1 --- a/src/share/vm/runtime/arguments.hpp Fri Mar 15 22:07:42 2013 -0700 52.2 +++ b/src/share/vm/runtime/arguments.hpp Sat Mar 16 21:44:52 2013 -0700 52.3 @@ -309,6 +309,7 @@ 52.4 // Garbage-First (UseG1GC) 52.5 static void set_g1_gc_flags(); 52.6 // GC ergonomics 52.7 + static void set_use_compressed_oops(); 52.8 static void set_ergonomics_flags(); 52.9 static void set_shared_spaces_flags(); 52.10 // Setup heap size 52.11 @@ -414,6 +415,7 @@ 52.12 // Check for consistency in the selection of the garbage collector. 52.13 static bool check_gc_consistency(); 52.14 static void check_deprecated_gcs(); 52.15 + static void check_deprecated_gc_flags(); 52.16 // Check consistecy or otherwise of VM argument settings 52.17 static bool check_vm_args_consistency(); 52.18 // Check stack pages settings
53.1 --- a/src/share/vm/runtime/globals.hpp Fri Mar 15 22:07:42 2013 -0700 53.2 +++ b/src/share/vm/runtime/globals.hpp Sat Mar 16 21:44:52 2013 -0700 53.3 @@ -3644,7 +3644,10 @@ 53.4 "Enable internal testing APIs") \ 53.5 \ 53.6 product(bool, PrintGCCause, true, \ 53.7 - "Include GC cause in GC logging") 53.8 + "Include GC cause in GC logging") \ 53.9 + \ 53.10 + product(bool, AllowNonVirtualCalls, false, \ 53.11 + "Obey the ACC_SUPER flag and allow invokenonvirtual calls") 53.12 53.13 /* 53.14 * Macros for factoring of globals
54.1 --- a/src/share/vm/runtime/thread.hpp Fri Mar 15 22:07:42 2013 -0700 54.2 +++ b/src/share/vm/runtime/thread.hpp Sat Mar 16 21:44:52 2013 -0700 54.3 @@ -1,5 +1,5 @@ 54.4 /* 54.5 - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 54.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 54.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 54.8 * 54.9 * This code is free software; you can redistribute it and/or modify it 54.10 @@ -1289,6 +1289,7 @@ 54.11 void enable_stack_red_zone(); 54.12 void disable_stack_red_zone(); 54.13 54.14 + inline bool stack_guard_zone_unused(); 54.15 inline bool stack_yellow_zone_disabled(); 54.16 inline bool stack_yellow_zone_enabled(); 54.17 54.18 @@ -1759,6 +1760,10 @@ 54.19 return (CompilerThread*)this; 54.20 } 54.21 54.22 +inline bool JavaThread::stack_guard_zone_unused() { 54.23 + return _stack_guard_state == stack_guard_unused; 54.24 +} 54.25 + 54.26 inline bool JavaThread::stack_yellow_zone_disabled() { 54.27 return _stack_guard_state == stack_guard_yellow_disabled; 54.28 }
55.1 --- a/src/share/vm/runtime/vmStructs.cpp Fri Mar 15 22:07:42 2013 -0700 55.2 +++ b/src/share/vm/runtime/vmStructs.cpp Sat Mar 16 21:44:52 2013 -0700 55.3 @@ -336,7 +336,6 @@ 55.4 nonstatic_field(Klass, _access_flags, AccessFlags) \ 55.5 nonstatic_field(Klass, _subklass, Klass*) \ 55.6 nonstatic_field(Klass, _next_sibling, Klass*) \ 55.7 - nonproduct_nonstatic_field(Klass, _verify_count, int) \ 55.8 nonstatic_field(Klass, _alloc_count, juint) \ 55.9 nonstatic_field(MethodData, _size, int) \ 55.10 nonstatic_field(MethodData, _method, Method*) \
56.1 --- a/src/share/vm/runtime/vm_operations.hpp Fri Mar 15 22:07:42 2013 -0700 56.2 +++ b/src/share/vm/runtime/vm_operations.hpp Sat Mar 16 21:44:52 2013 -0700 56.3 @@ -94,6 +94,7 @@ 56.4 template(ReportJavaOutOfMemory) \ 56.5 template(JFRCheckpoint) \ 56.6 template(Exit) \ 56.7 + template(LinuxDllLoad) \ 56.8 56.9 class VM_Operation: public CHeapObj<mtInternal> { 56.10 public:
57.1 --- a/src/share/vm/services/memoryService.cpp Fri Mar 15 22:07:42 2013 -0700 57.2 +++ b/src/share/vm/services/memoryService.cpp Sat Mar 16 21:44:52 2013 -0700 57.3 @@ -240,6 +240,7 @@ 57.4 void MemoryService::add_generation_memory_pool(Generation* gen, 57.5 MemoryManager* major_mgr, 57.6 MemoryManager* minor_mgr) { 57.7 + guarantee(gen != NULL, "No generation for memory pool"); 57.8 Generation::Name kind = gen->kind(); 57.9 int index = _pools_list->length(); 57.10
58.1 --- a/src/share/vm/utilities/elfFile.cpp Fri Mar 15 22:07:42 2013 -0700 58.2 +++ b/src/share/vm/utilities/elfFile.cpp Sat Mar 16 21:44:52 2013 -0700 58.3 @@ -197,4 +197,28 @@ 58.4 return NULL; 58.5 } 58.6 58.7 +#ifdef LINUX 58.8 +bool ElfFile::specifies_noexecstack() { 58.9 + Elf_Phdr phdr; 58.10 + if (!m_file) return true; 58.11 + 58.12 + if (!fseek(m_file, m_elfHdr.e_phoff, SEEK_SET)) { 58.13 + for (int index = 0; index < m_elfHdr.e_phnum; index ++) { 58.14 + if (fread((void*)&phdr, sizeof(Elf_Phdr), 1, m_file) != 1) { 58.15 + m_status = NullDecoder::file_invalid; 58.16 + return false; 58.17 + } 58.18 + if (phdr.p_type == PT_GNU_STACK) { 58.19 + if (phdr.p_flags == (PF_R | PF_W)) { 58.20 + return true; 58.21 + } else { 58.22 + return false; 58.23 + } 58.24 + } 58.25 + } 58.26 + } 58.27 + return false; 58.28 +} 58.29 +#endif 58.30 + 58.31 #endif // _WINDOWS
59.1 --- a/src/share/vm/utilities/elfFile.hpp Fri Mar 15 22:07:42 2013 -0700 59.2 +++ b/src/share/vm/utilities/elfFile.hpp Sat Mar 16 21:44:52 2013 -0700 59.3 @@ -43,6 +43,7 @@ 59.4 59.5 typedef Elf64_Ehdr Elf_Ehdr; 59.6 typedef Elf64_Shdr Elf_Shdr; 59.7 +typedef Elf64_Phdr Elf_Phdr; 59.8 typedef Elf64_Sym Elf_Sym; 59.9 59.10 #if !defined(_ALLBSD_SOURCE) || defined(__APPLE__) 59.11 @@ -59,6 +60,7 @@ 59.12 59.13 typedef Elf32_Ehdr Elf_Ehdr; 59.14 typedef Elf32_Shdr Elf_Shdr; 59.15 +typedef Elf32_Phdr Elf_Phdr; 59.16 typedef Elf32_Sym Elf_Sym; 59.17 59.18 #if !defined(_ALLBSD_SOURCE) || defined(__APPLE__) 59.19 @@ -123,6 +125,14 @@ 59.20 ElfFile* next() const { return m_next; } 59.21 void set_next(ElfFile* file) { m_next = file; } 59.22 59.23 + public: 59.24 + // Returns true if the elf file is marked NOT to require an executable stack, 59.25 + // or if the file could not be opened. 59.26 + // Returns false if the elf file requires an executable stack, the stack flag 59.27 + // is not set at all, or if the file can not be read. 59.28 + // On systems other than linux it always returns false. 59.29 + bool specifies_noexecstack() NOT_LINUX({ return false; }); 59.30 + 59.31 protected: 59.32 ElfFile* m_next; 59.33
60.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 60.2 +++ b/test/runtime/7107135/Test.java Sat Mar 16 21:44:52 2013 -0700 60.3 @@ -0,0 +1,65 @@ 60.4 +/* 60.5 + * Copyright (c) 2002-2013, Oracle and/or its affiliates. All rights reserved. 60.6 + * Copyright (c) 2011 SAP AG. All Rights Reserved. 60.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 60.8 + * 60.9 + * This code is free software; you can redistribute it and/or modify it 60.10 + * under the terms of the GNU General Public License version 2 only, as 60.11 + * published by the Free Software Foundation. 60.12 + * 60.13 + * This code is distributed in the hope that it will be useful, but WITHOUT 60.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 60.15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 60.16 + * version 2 for more details (a copy is included in the LICENSE file that 60.17 + * accompanied this code). 60.18 + * 60.19 + * You should have received a copy of the GNU General Public License version 60.20 + * 2 along with this work; if not, write to the Free Software Foundation, 60.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 60.22 + * 60.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 60.24 + * or visit www.oracle.com if you need additional information or have any 60.25 + * questions. 60.26 + */ 60.27 + 60.28 +class Test { 60.29 + 60.30 + static boolean loadLib(String libName){ 60.31 + try { 60.32 + System.loadLibrary(libName); 60.33 + System.out.println("Loaded library "+ libName + "."); 60.34 + return true; 60.35 + } catch (SecurityException e) { 60.36 + System.out.println("loadLibrary(\"" + libName + "\") throws: " + e + "\n"); 60.37 + } catch (UnsatisfiedLinkError e) { 60.38 + System.out.println("loadLibrary(\"" + libName + "\") throws: " + e + "\n"); 60.39 + } 60.40 + return false; 60.41 + } 60.42 + 60.43 + public static int counter = 1; 60.44 + 60.45 + static int Runner() { 60.46 + counter = counter * -1; 60.47 + int i = counter; 60.48 + if(counter < 2) counter += Runner(); 60.49 + return i; 60.50 + } 60.51 + 60.52 + public static int run() { 60.53 + try{ 60.54 + Runner(); 60.55 + } catch (StackOverflowError e) { 60.56 + System.out.println("Caught stack overflow error."); 60.57 + return 0; 60.58 + } catch (OutOfMemoryError e) { 60.59 + return 0; 60.60 + } 60.61 + return 2; 60.62 + } 60.63 + 60.64 + public static void main(String argv[]) { 60.65 + loadLib(argv[0]); 60.66 + System.exit(run()); 60.67 + } 60.68 +}
61.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 61.2 +++ b/test/runtime/7107135/Test7107135.sh Sat Mar 16 21:44:52 2013 -0700 61.3 @@ -0,0 +1,98 @@ 61.4 +#!/bin/sh 61.5 + 61.6 +# 61.7 +# Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. 61.8 +# Copyright (c) 2011 SAP AG. All Rights Reserved. 61.9 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 61.10 +# 61.11 +# This code is free software; you can redistribute it and/or modify it 61.12 +# under the terms of the GNU General Public License version 2 only, as 61.13 +# published by the Free Software Foundation. 61.14 +# 61.15 +# This code is distributed in the hope that it will be useful, but WITHOUT 61.16 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 61.17 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 61.18 +# version 2 for more details (a copy is included in the LICENSE file that 61.19 +# accompanied this code). 61.20 +# 61.21 +# You should have received a copy of the GNU General Public License version 61.22 +# 2 along with this work; if not, write to the Free Software Foundation, 61.23 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 61.24 +# 61.25 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 61.26 +# or visit www.oracle.com if you need additional information or have any 61.27 +# questions. 61.28 +# 61.29 + 61.30 +## 61.31 +## @test Test7107135.sh 61.32 +## @bug 7107135 61.33 +## @summary Stack guard pages lost after loading library with executable stack. 61.34 +## @run shell Test7107135.sh 61.35 +## 61.36 + 61.37 +if [ "${TESTSRC}" = "" ] 61.38 +then TESTSRC=. 61.39 +fi 61.40 + 61.41 +if [ "${TESTJAVA}" = "" ] 61.42 +then 61.43 + PARENT=`dirname \`which java\`` 61.44 + TESTJAVA=`dirname ${PARENT}` 61.45 + echo "TESTJAVA not set, selecting " ${TESTJAVA} 61.46 + echo "If this is incorrect, try setting the variable manually." 61.47 +fi 61.48 + 61.49 +BIT_FLAG="" 61.50 + 61.51 +# set platform-dependent variables 61.52 +OS=`uname -s` 61.53 +case "$OS" in 61.54 + Linux) 61.55 + NULL=/dev/null 61.56 + PS=":" 61.57 + FS="/" 61.58 + ;; 61.59 + *) 61.60 + NULL=NUL 61.61 + PS=";" 61.62 + FS="\\" 61.63 + echo "Test passed; only valid for Linux" 61.64 + exit 0; 61.65 + ;; 61.66 +esac 61.67 + 61.68 +ARCH=`uname -m` 61.69 + 61.70 +THIS_DIR=`pwd` 61.71 + 61.72 +cp ${TESTSRC}${FS}*.java ${THIS_DIR} 61.73 +${TESTJAVA}${FS}bin${FS}javac *.java 61.74 + 61.75 +gcc -fPIC -shared -c -o test.o -I${TESTJAVA}${FS}include -I${TESTJAVA}${FS}include${FS}linux ${TESTSRC}${FS}test.c 61.76 +ld -shared -z execstack -o libtest-rwx.so test.o 61.77 +ld -shared -z noexecstack -o libtest-rw.so test.o 61.78 + 61.79 + 61.80 +LD_LIBRARY_PATH=${THIS_DIR} 61.81 +echo LD_LIBRARY_PATH = ${LD_LIBRARY_PATH} 61.82 +export LD_LIBRARY_PATH 61.83 + 61.84 +# This should not fail. 61.85 +echo Check testprogram. Expected to pass: 61.86 +echo ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} Test test-rw 61.87 +${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} Test test-rw 61.88 + 61.89 +echo 61.90 +echo Test changing of stack protection: 61.91 +echo ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} Test test-rw 61.92 +${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} Test test-rwx 61.93 + 61.94 +if [ "$?" == "0" ] 61.95 +then 61.96 + echo 61.97 + echo ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} TestMT test-rwx 61.98 + ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} TestMT test-rwx 61.99 +fi 61.100 + 61.101 +exit $?
62.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 62.2 +++ b/test/runtime/7107135/TestMT.java Sat Mar 16 21:44:52 2013 -0700 62.3 @@ -0,0 +1,85 @@ 62.4 +/* 62.5 + * Copyright (c) 2002-2013, Oracle and/or its affiliates. All rights reserved. 62.6 + * Copyright (c) 2011 SAP AG. All Rights Reserved. 62.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 62.8 + * 62.9 + * This code is free software; you can redistribute it and/or modify it 62.10 + * under the terms of the GNU General Public License version 2 only, as 62.11 + * published by the Free Software Foundation. 62.12 + * 62.13 + * This code is distributed in the hope that it will be useful, but WITHOUT 62.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 62.15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 62.16 + * version 2 for more details (a copy is included in the LICENSE file that 62.17 + * accompanied this code). 62.18 + * 62.19 + * You should have received a copy of the GNU General Public License version 62.20 + * 2 along with this work; if not, write to the Free Software Foundation, 62.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 62.22 + * 62.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 62.24 + * or visit www.oracle.com if you need additional information or have any 62.25 + * questions. 62.26 + */ 62.27 + 62.28 +class TestMT { 62.29 + 62.30 + static boolean loadLib(String libName) { 62.31 + try { 62.32 + System.loadLibrary(libName); 62.33 + System.out.println("Loaded library "+ libName + "."); 62.34 + return true; 62.35 + } catch (SecurityException e) { 62.36 + System.out.println("loadLibrary(\"" + libName + "\") throws: " + e + "\n"); 62.37 + } catch (UnsatisfiedLinkError e) { 62.38 + System.out.println("loadLibrary(\"" + libName + "\") throws: " + e + "\n"); 62.39 + } 62.40 + return false; 62.41 + } 62.42 + 62.43 + public static int counter = 1; 62.44 + static int Runner() { 62.45 + counter = counter * -1; 62.46 + int i = counter; 62.47 + if (counter < 2) counter += Runner(); 62.48 + return i; 62.49 + } 62.50 + 62.51 + public static int run(String msg) { 62.52 + try { 62.53 + Runner(); 62.54 + } catch (StackOverflowError e) { 62.55 + System.out.println(msg + " caught stack overflow error."); 62.56 + return 0; 62.57 + } catch (OutOfMemoryError e) { 62.58 + return 0; 62.59 + } 62.60 + return 2; 62.61 + } 62.62 + 62.63 + public static void main(String argv[]) { 62.64 + try { 62.65 + for (int i = 0; i < 20; i++) { 62.66 + Thread t = new DoStackOverflow("SpawnedThread " + i); 62.67 + t.start(); 62.68 + } 62.69 + run("Main thread"); 62.70 + loadLib("test-rwx"); 62.71 + run("Main thread"); 62.72 + } catch (Exception e) { 62.73 + System.out.println(e); 62.74 + } 62.75 + } 62.76 + 62.77 + static class DoStackOverflow extends Thread { 62.78 + public DoStackOverflow(String name) { 62.79 + super(name); 62.80 + } 62.81 + public void run() { 62.82 + for (int i = 0; i < 10; ++i) { 62.83 + TestMT.run(getName()); 62.84 + yield(); 62.85 + } 62.86 + } 62.87 + } 62.88 +}
63.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 63.2 +++ b/test/runtime/7107135/test.c Sat Mar 16 21:44:52 2013 -0700 63.3 @@ -0,0 +1,39 @@ 63.4 +/* 63.5 + * Copyright (c) 2002-2013, Oracle and/or its affiliates. All rights reserved. 63.6 + * Copyright (c) 2011 SAP AG. All Rights Reserved. 63.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 63.8 + * 63.9 + * This code is free software; you can redistribute it and/or modify it 63.10 + * under the terms of the GNU General Public License version 2 only, as 63.11 + * published by the Free Software Foundation. 63.12 + * 63.13 + * This code is distributed in the hope that it will be useful, but WITHOUT 63.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 63.15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 63.16 + * version 2 for more details (a copy is included in the LICENSE file that 63.17 + * accompanied this code). 63.18 + * 63.19 + * You should have received a copy of the GNU General Public License version 63.20 + * 2 along with this work; if not, write to the Free Software Foundation, 63.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 63.22 + * 63.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 63.24 + * or visit www.oracle.com if you need additional information or have any 63.25 + * questions. 63.26 + */ 63.27 + 63.28 +#include <stdlib.h> 63.29 +#include <string.h> 63.30 +#include <stdio.h> 63.31 +#include "jni.h" 63.32 +#ifdef __cplusplus 63.33 +extern "C" { 63.34 +#endif 63.35 + 63.36 +JNIEXPORT jint JNICALL Java_Test_someMethod(JNIEnv *env, jobject mainObject) { 63.37 + return 3; 63.38 +} 63.39 + 63.40 +#ifdef __cplusplus 63.41 +} 63.42 +#endif
64.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 64.2 +++ b/test/runtime/8003985/Test8003985.java Sat Mar 16 21:44:52 2013 -0700 64.3 @@ -0,0 +1,302 @@ 64.4 +/* 64.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 64.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 64.7 + * 64.8 + * This code is free software; you can redistribute it and/or modify it 64.9 + * under the terms of the GNU General Public License version 2 only, as 64.10 + * published by the Free Software Foundation. 64.11 + * 64.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 64.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 64.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 64.15 + * version 2 for more details (a copy is included in the LICENSE file that 64.16 + * accompanied this code). 64.17 + * 64.18 + * You should have received a copy of the GNU General Public License version 64.19 + * 2 along with this work; if not, write to the Free Software Foundation, 64.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 64.21 + * 64.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 64.23 + * or visit www.oracle.com if you need additional information or have any 64.24 + * questions. 64.25 + */ 64.26 + 64.27 +import java.io.BufferedReader; 64.28 +import java.io.InputStreamReader; 64.29 +import java.lang.Class; 64.30 +import java.lang.String; 64.31 +import java.lang.System; 64.32 +import java.lang.management.ManagementFactory; 64.33 +import java.lang.management.RuntimeMXBean; 64.34 +import java.util.ArrayList; 64.35 +import java.util.List; 64.36 +import java.util.concurrent.CyclicBarrier; 64.37 +import java.util.regex.Matcher; 64.38 +import java.util.regex.Pattern; 64.39 +import java.lang.reflect.Field; 64.40 +import java.lang.reflect.Modifier; 64.41 +import sun.misc.Unsafe; 64.42 +import sun.misc.Contended; 64.43 + 64.44 +/* 64.45 + * @test 64.46 + * @bug 8003985 64.47 + * @summary Support Contended Annotation - JEP 142 64.48 + * 64.49 + * @run main/othervm -XX:-RestrictContended Test8003985 64.50 + */ 64.51 +public class Test8003985 { 64.52 + 64.53 + private static final Unsafe U; 64.54 + private static int ADDRESS_SIZE; 64.55 + private static int HEADER_SIZE; 64.56 + 64.57 + static { 64.58 + // steal Unsafe 64.59 + try { 64.60 + Field unsafe = Unsafe.class.getDeclaredField("theUnsafe"); 64.61 + unsafe.setAccessible(true); 64.62 + U = (Unsafe) unsafe.get(null); 64.63 + } catch (NoSuchFieldException | IllegalAccessException e) { 64.64 + throw new IllegalStateException(e); 64.65 + } 64.66 + 64.67 + // When running with CompressedOops on 64-bit platform, the address size 64.68 + // reported by Unsafe is still 8, while the real reference fields are 4 bytes long. 64.69 + // Try to guess the reference field size with this naive trick. 64.70 + try { 64.71 + long off1 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj1")); 64.72 + long off2 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj2")); 64.73 + ADDRESS_SIZE = (int) Math.abs(off2 - off1); 64.74 + HEADER_SIZE = (int) Math.min(off1, off2); 64.75 + } catch (NoSuchFieldException e) { 64.76 + ADDRESS_SIZE = -1; 64.77 + } 64.78 + } 64.79 + 64.80 + static class CompressedOopsClass { 64.81 + public Object obj1; 64.82 + public Object obj2; 64.83 + } 64.84 + 64.85 + public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception { 64.86 + Field f1 = klass.getDeclaredField(field1); 64.87 + Field f2 = klass.getDeclaredField(field2); 64.88 + 64.89 + if (isStatic(f1) != isStatic(f2)) { 64.90 + return true; // these guys are in naturally disjoint locations 64.91 + } 64.92 + 64.93 + int diff = offset(f1) - offset(f2); 64.94 + if (diff < 0) { 64.95 + // f1 is first 64.96 + return (offset(f2) - (offset(f1) + getSize(f1))) > 64; 64.97 + } else { 64.98 + // f2 is first 64.99 + return (offset(f1) - (offset(f2) + getSize(f2))) > 64; 64.100 + } 64.101 + } 64.102 + 64.103 + public static boolean isPadded(Class klass, String field1) throws Exception { 64.104 + Field f1 = klass.getDeclaredField(field1); 64.105 + 64.106 + if (isStatic(f1)) { 64.107 + return offset(f1) > 128 + 64; 64.108 + } 64.109 + 64.110 + return offset(f1) > 64; 64.111 + } 64.112 + 64.113 + public static boolean sameLayout(Class klass1, Class klass2) throws Exception { 64.114 + for (Field f1 : klass1.getDeclaredFields()) { 64.115 + Field f2 = klass2.getDeclaredField(f1.getName()); 64.116 + if (offset(f1) != offset(f2)) { 64.117 + return false; 64.118 + } 64.119 + } 64.120 + 64.121 + for (Field f2 : klass1.getDeclaredFields()) { 64.122 + Field f1 = klass2.getDeclaredField(f2.getName()); 64.123 + if (offset(f1) != offset(f2)) { 64.124 + return false; 64.125 + } 64.126 + } 64.127 + 64.128 + return true; 64.129 + } 64.130 + 64.131 + public static boolean isStatic(Field field) { 64.132 + return Modifier.isStatic(field.getModifiers()); 64.133 + } 64.134 + 64.135 + public static int offset(Field field) { 64.136 + if (isStatic(field)) { 64.137 + return (int) U.staticFieldOffset(field); 64.138 + } else { 64.139 + return (int) U.objectFieldOffset(field); 64.140 + } 64.141 + } 64.142 + 64.143 + public static int getSize(Field field) { 64.144 + Class type = field.getType(); 64.145 + if (type == byte.class) { return 1; } 64.146 + if (type == boolean.class) { return 1; } 64.147 + if (type == short.class) { return 2; } 64.148 + if (type == char.class) { return 2; } 64.149 + if (type == int.class) { return 4; } 64.150 + if (type == float.class) { return 4; } 64.151 + if (type == long.class) { return 8; } 64.152 + if (type == double.class) { return 8; } 64.153 + return ADDRESS_SIZE; 64.154 + } 64.155 + 64.156 + public static void main(String[] args) throws Exception { 64.157 + boolean endResult = true; 64.158 + 64.159 + // --------------- INSTANCE FIELDS --------------------- 64.160 + 64.161 + if (arePaddedPairwise(Test1.class, "int1", "int2") || 64.162 + isPadded(Test1.class, "int1") || 64.163 + isPadded(Test1.class, "int2")) { 64.164 + System.err.println("Test1 failed"); 64.165 + endResult &= false; 64.166 + } 64.167 + 64.168 + if (!arePaddedPairwise(Test2.class, "int1", "int2") || 64.169 + !isPadded(Test2.class, "int1") || 64.170 + isPadded(Test2.class, "int2")) { 64.171 + System.err.println("Test2 failed"); 64.172 + endResult &= false; 64.173 + } 64.174 + 64.175 + if (!arePaddedPairwise(Test3.class, "int1", "int2") || 64.176 + !isPadded(Test3.class, "int1") || 64.177 + !isPadded(Test3.class, "int2")) { 64.178 + System.err.println("Test3 failed"); 64.179 + endResult &= false; 64.180 + } 64.181 + 64.182 + if (arePaddedPairwise(Test4.class, "int1", "int2") || 64.183 + !isPadded(Test4.class, "int1") || 64.184 + !isPadded(Test4.class, "int2")) { 64.185 + System.err.println("Test4 failed"); 64.186 + endResult &= false; 64.187 + } 64.188 + 64.189 + if (!arePaddedPairwise(Test5.class, "int1", "int2") || 64.190 + !isPadded(Test5.class, "int1") || 64.191 + !isPadded(Test5.class, "int2")) { 64.192 + System.err.println("Test5 failed"); 64.193 + endResult &= false; 64.194 + } 64.195 + 64.196 + if (!arePaddedPairwise(Test6.class, "int1", "int2") || 64.197 + !isPadded(Test6.class, "int1") || 64.198 + !isPadded(Test6.class, "int2")) { 64.199 + System.err.println("Test6 failed"); 64.200 + endResult &= false; 64.201 + } 64.202 + 64.203 + if (arePaddedPairwise(Test7.class, "int1", "int2") || 64.204 + !isPadded(Test7.class, "int1") || 64.205 + !isPadded(Test7.class, "int2")) { 64.206 + System.err.println("Test7 failed"); 64.207 + endResult &= false; 64.208 + } 64.209 + 64.210 + if (!arePaddedPairwise(Test8.class, "int1", "int2") || 64.211 + !isPadded(Test8.class, "int1") || 64.212 + !isPadded(Test8.class, "int2")) { 64.213 + System.err.println("Test8 failed"); 64.214 + endResult &= false; 64.215 + } 64.216 + 64.217 + if (!arePaddedPairwise(Test9.class, "int1", "int2") || 64.218 + !isPadded(Test9.class, "int1") || 64.219 + !isPadded(Test9.class, "int2")) { 64.220 + System.err.println("Test9 failed"); 64.221 + endResult &= false; 64.222 + } 64.223 + 64.224 + if (!sameLayout(Test4.class, Test7.class)) { 64.225 + System.err.println("Test4 and Test7 have different layouts"); 64.226 + endResult &= false; 64.227 + } 64.228 + 64.229 + if (!sameLayout(Test5.class, Test6.class)) { 64.230 + System.err.println("Test5 and Test6 have different layouts"); 64.231 + endResult &= false; 64.232 + } 64.233 + 64.234 + if (!sameLayout(Test8.class, Test9.class)) { 64.235 + System.err.println("Test8 and Test9 have different layouts"); 64.236 + endResult &= false; 64.237 + } 64.238 + 64.239 + System.out.println(endResult ? "Test PASSES" : "Test FAILS"); 64.240 + if (!endResult) { 64.241 + throw new Error("Test failed"); 64.242 + } 64.243 + } 64.244 + 64.245 + // ----------------------------------- INSTANCE FIELDS ----------------------------------------- 64.246 + 64.247 + // naturally packed 64.248 + public static class Test1 { 64.249 + private int int1; 64.250 + private int int2; 64.251 + } 64.252 + 64.253 + // int1 is padded 64.254 + public static class Test2 { 64.255 + @Contended private int int1; 64.256 + private int int2; 64.257 + } 64.258 + 64.259 + // both fields are padded 64.260 + public static class Test3 { 64.261 + @Contended private int int1; 64.262 + @Contended private int int2; 64.263 + } 64.264 + 64.265 + // fields are padded in the singular group 64.266 + public static class Test4 { 64.267 + @Contended("sameGroup") private int int1; 64.268 + @Contended("sameGroup") private int int2; 64.269 + } 64.270 + 64.271 + // fields are padded in disjoint groups 64.272 + public static class Test5 { 64.273 + @Contended("diffGroup1") private int int1; 64.274 + @Contended("diffGroup2") private int int2; 64.275 + } 64.276 + 64.277 + // fields are padded in disjoint groups 64.278 + public static class Test6 { 64.279 + @Contended private int int1; 64.280 + @Contended("diffGroup2") private int int2; 64.281 + } 64.282 + 64.283 + // fields are padded in the singular group 64.284 + @Contended 64.285 + public static class Test7 { 64.286 + private int int1; 64.287 + private int int2; 64.288 + } 64.289 + 64.290 + // all fields are padded as the group, and one field is padded specifically 64.291 + @Contended 64.292 + public static class Test8 { 64.293 + @Contended private int int1; 64.294 + private int int2; 64.295 + } 64.296 + 64.297 + // all fields are padded as the group, and one field is padded specifically 64.298 + @Contended 64.299 + public static class Test9 { 64.300 + @Contended("group") private int int1; 64.301 + private int int2; 64.302 + } 64.303 + 64.304 +} 64.305 +