changeset 13584:2dfe246179c0 nestmates

Merge
author dholmes
date Wed, 20 Sep 2017 23:55:35 -0400
parents 8ee20a905c42 821ef7c10085
children 64bc704066cd
files src/cpu/aarch64/vm/globals_aarch64.hpp src/cpu/x86/vm/globals_x86.hpp src/cpu/x86/vm/interp_masm_x86.cpp src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/MiscUtils.java src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/utils/Timer.java src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/memory/LoaderConstraintEntry.java src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/memory/LoaderConstraintTable.java src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/memory/PlaceholderEntry.java src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/memory/PlaceholderTable.java src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/memory/ProtectionDomainCacheEntry.java src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/memory/ProtectionDomainEntry.java src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/TwoOopHashtable.java src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.microbenchmarks/src/micro/benchmarks/ArrayDuplicationBenchmark.java src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.microbenchmarks/src/micro/benchmarks/ArrayListBenchmark.java src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.microbenchmarks/src/micro/benchmarks/BoxingBenchmark.java src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.microbenchmarks/src/micro/benchmarks/ConcurrentSkipListBenchmark.java src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.microbenchmarks/src/micro/benchmarks/GuardedIntrinsicBenchmark.java src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.microbenchmarks/src/micro/benchmarks/HashBenchmark.java src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.microbenchmarks/src/micro/benchmarks/MathFunctionBenchmark.java src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.microbenchmarks/src/micro/benchmarks/SimpleSyncBenchmark.java src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.microbenchmarks/src/micro/benchmarks/package-info.java src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.microbenchmarks/src/org/graalvm/compiler/microbenchmarks/graal/TestJMH.java src/os_cpu/solaris_x86/vm/solaris_x86_32.il src/os_cpu/solaris_x86/vm/solaris_x86_32.s src/share/vm/classfile/classFileParser.cpp src/share/vm/classfile/javaClasses.cpp src/share/vm/classfile/systemDictionary.cpp src/share/vm/classfile/systemDictionary.hpp src/share/vm/classfile/vmSymbols.cpp src/share/vm/classfile/vmSymbols.hpp src/share/vm/gc/g1/workerDataArray.cpp src/share/vm/gc/g1/workerDataArray.hpp src/share/vm/gc/g1/workerDataArray.inline.hpp src/share/vm/gc/parallel/psParallelCompact.cpp src/share/vm/gc/serial/markSweep.cpp src/share/vm/interpreter/interpreterRuntime.cpp src/share/vm/interpreter/linkResolver.cpp src/share/vm/interpreter/rewriter.cpp src/share/vm/jvmci/jvmciCompilerToVM.cpp src/share/vm/logging/logTag.hpp src/share/vm/oops/arrayKlass.cpp src/share/vm/oops/arrayKlass.hpp src/share/vm/oops/constantPool.cpp src/share/vm/oops/cpCache.cpp src/share/vm/oops/cpCache.hpp src/share/vm/oops/instanceKlass.cpp src/share/vm/oops/instanceKlass.hpp src/share/vm/oops/klass.hpp src/share/vm/oops/klassVtable.cpp src/share/vm/oops/klassVtable.hpp src/share/vm/oops/method.cpp src/share/vm/oops/methodData.cpp src/share/vm/oops/objArrayKlass.cpp src/share/vm/oops/oop.cpp src/share/vm/oops/oop.hpp src/share/vm/oops/oop.inline.hpp src/share/vm/oops/oopsHierarchy.hpp src/share/vm/opto/classes.hpp src/share/vm/opto/compile.cpp src/share/vm/opto/library_call.cpp src/share/vm/opto/macroArrayCopy.cpp src/share/vm/opto/memnode.cpp src/share/vm/opto/runtime.cpp src/share/vm/precompiled/precompiled.hpp src/share/vm/prims/jni.cpp src/share/vm/prims/jvm.cpp src/share/vm/prims/whitebox.cpp src/share/vm/runtime/arguments.cpp src/share/vm/runtime/deoptimization.cpp src/share/vm/runtime/globals.hpp src/share/vm/runtime/handles.hpp src/share/vm/runtime/javaCalls.cpp src/share/vm/runtime/reflection.cpp src/share/vm/runtime/sharedRuntime.cpp src/share/vm/utilities/globalDefinitions.hpp test/native/gc/g1/test_workerDataArray.cpp test/runtime/CommandLine/OptionsValidation/TestOptionsWithRanges.java test/runtime/SharedArchiveFile/LargeSharedSpace.java test/runtime/SharedArchiveFile/LimitSharedSizes.java
diffstat 812 files changed, 21696 insertions(+), 14074 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Mon Sep 11 23:44:23 2017 -0400
+++ b/.hgtags	Wed Sep 20 23:55:35 2017 -0400
@@ -592,3 +592,16 @@
 070aa7a2eb14c4645f7eb31384cba0a2ba72a4b5 jdk-10+12
 8f04d457168b9f1f4a1b2c37f49e0513ca9d33a7 jdk-9+175
 a9da03357f190807591177fe9846d6e68ad64fc0 jdk-10+13
+e920b4d008d914f3414bd4630b58837cf0b7f08d jdk-10+14
+2ab74e5dbdc2b6a962c865500cafd23cf387dc60 jdk-9+176
+1ca8f038fceb88c640badf9bd18905205bc63b43 jdk-9+177
+c1f3649a3a42f124b418a5a916dbad13d059b757 jdk-10+15
+2fe2a593e8ebf3a9e4dcd9ba3333a7b43126589d jdk-10+16
+9d032191f82fca5ba0aac98682f69c4ff0f1283d jdk-9+178
+d2661aa42bff322badbe6c1337fc638d2e0f5730 jdk-9+179
+73e2cb8700bfa51304bd4b02f224620859a3f600 jdk-10+17
+c9d3317623d48da3327232c81e3f8cfc0d29d888 jdk-10+18
+33b74e13c1457f36041addb8b850831f81ca6e9f jdk-10+19
+d7baadc223e790c08bc69bf7e553bce65b4e7e40 jdk-9+180
+4a443796f6f57842d6a0434ac27ca3d1033ccc20 jdk-9+181
+e93ed1a092409351c90b3a76d80b9aa8b44d5e6a jdk-10+20
--- a/make/test/JtregNative.gmk	Mon Sep 11 23:44:23 2017 -0400
+++ b/make/test/JtregNative.gmk	Wed Sep 20 23:55:35 2017 -0400
@@ -61,6 +61,7 @@
     $(HOTSPOT_TOPDIR)/test/runtime/noClassDefFoundMsg \
     $(HOTSPOT_TOPDIR)/test/compiler/floatingpoint/ \
     $(HOTSPOT_TOPDIR)/test/compiler/calls \
+    $(HOTSPOT_TOPDIR)/test/serviceability/jvmti/GetOwnedMonitorInfo \
     $(HOTSPOT_TOPDIR)/test/serviceability/jvmti/GetNamedModule \
     $(HOTSPOT_TOPDIR)/test/serviceability/jvmti/IsModifiableModule \
     $(HOTSPOT_TOPDIR)/test/serviceability/jvmti/AddModuleReads \
@@ -92,6 +93,7 @@
 ifeq ($(TOOLCHAIN_TYPE), solstudio)
     BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_liboverflow := -lc
     BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libSimpleClassFileLoadHook := -lc
+    BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libGetOwnedMonitorInfoTest := -lc
     BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libGetNamedModuleTest := -lc
     BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libIsModifiableModuleTest := -lc
     BUILD_HOTSPOT_JTREG_LIBRARIES_LDFLAGS_libAddModuleReadsTest := -lc
--- a/src/cpu/aarch64/vm/aarch64.ad	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/aarch64/vm/aarch64.ad	Wed Sep 20 23:55:35 2017 -0400
@@ -3806,15 +3806,24 @@
       // Any use that can't embed the address computation?
       for (DUIterator_Fast imax, i = addp->fast_outs(imax); i < imax; i++) {
         Node* u = addp->fast_out(i);
-        if (!u->is_Mem() || u->is_LoadVector() || u->is_StoreVector() || u->Opcode() == Op_StoreCM) {
+        if (!u->is_Mem()) {
           return;
         }
+        if (u->is_LoadVector() || u->is_StoreVector() || u->Opcode() == Op_StoreCM) {
+          return;
+        }
+        if (addp2->in(AddPNode::Offset)->Opcode() != Op_ConvI2L) {
+          int scale = 1 << addp2->in(AddPNode::Offset)->in(2)->get_int();
+          if (VM_Version::expensive_load(u->as_Mem()->memory_size(), scale)) {
+            return;
+          }
+        }
       }
-      
+
       Node* off = addp->in(AddPNode::Offset);
       Node* addr2 = addp2->in(AddPNode::Address);
       Node* base = addp->in(AddPNode::Base);
-      
+
       Node* new_addr = NULL;
       // Check whether the graph already has the new AddP we need
       // before we create one (no GVN available here).
@@ -3828,7 +3837,7 @@
           break;
         }
       }
-      
+
       if (new_addr == NULL) {
         new_addr = new AddPNode(base, addr2, off);
       }
@@ -4415,6 +4424,22 @@
                /*weak*/ false, noreg);
   %}
 
+  enc_class aarch64_enc_cmpxchgs(memory mem, iRegINoSp oldval, iRegINoSp newval) %{
+    MacroAssembler _masm(&cbuf);
+    guarantee($mem$$index == -1 && $mem$$disp == 0, "impossible encoding");
+    __ cmpxchg($mem$$base$$Register, $oldval$$Register, $newval$$Register,
+               Assembler::halfword, /*acquire*/ false, /*release*/ true,
+               /*weak*/ false, noreg);
+  %}
+
+  enc_class aarch64_enc_cmpxchgb(memory mem, iRegINoSp oldval, iRegINoSp newval) %{
+    MacroAssembler _masm(&cbuf);
+    guarantee($mem$$index == -1 && $mem$$disp == 0, "impossible encoding");
+    __ cmpxchg($mem$$base$$Register, $oldval$$Register, $newval$$Register,
+               Assembler::byte, /*acquire*/ false, /*release*/ true,
+               /*weak*/ false, noreg);
+  %}  
+    
 
   // The only difference between aarch64_enc_cmpxchg and
   // aarch64_enc_cmpxchg_acq is that we use load-acquire in the
@@ -9637,6 +9662,42 @@
 // XXX No flag versions for CompareAndSwap{I,L,P,N} because matcher
 // can't match them
 
+instruct compareAndSwapB(iRegINoSp res, indirect mem, iRegINoSp oldval, iRegINoSp newval, rFlagsReg cr) %{
+
+  match(Set res (CompareAndSwapB mem (Binary oldval newval)));
+  ins_cost(2 * VOLATILE_REF_COST);
+
+  effect(KILL cr);
+
+  format %{
+    "cmpxchgb $mem, $oldval, $newval\t# (int) if $mem == $oldval then $mem <-- $newval"
+    "cset $res, EQ\t# $res <-- (EQ ? 1 : 0)"
+  %}
+
+  ins_encode(aarch64_enc_cmpxchgb(mem, oldval, newval),
+            aarch64_enc_cset_eq(res));
+
+  ins_pipe(pipe_slow);
+%}
+
+instruct compareAndSwapS(iRegINoSp res, indirect mem, iRegINoSp oldval, iRegINoSp newval, rFlagsReg cr) %{
+
+  match(Set res (CompareAndSwapS mem (Binary oldval newval)));
+  ins_cost(2 * VOLATILE_REF_COST);
+
+  effect(KILL cr);
+
+  format %{
+    "cmpxchgs $mem, $oldval, $newval\t# (int) if $mem == $oldval then $mem <-- $newval"
+    "cset $res, EQ\t# $res <-- (EQ ? 1 : 0)"
+  %}
+
+  ins_encode(aarch64_enc_cmpxchgs(mem, oldval, newval),
+            aarch64_enc_cset_eq(res));
+
+  ins_pipe(pipe_slow);
+%}
+
 instruct compareAndSwapI(iRegINoSp res, indirect mem, iRegINoSp oldval, iRegINoSp newval, rFlagsReg cr) %{
 
   match(Set res (CompareAndSwapI mem (Binary oldval newval)));
@@ -14693,7 +14754,7 @@
   ins_pipe(icmp_reg_reg);
 %}
 
-instruct compL_reg_immI0(rFlagsReg cr, iRegL op1, immI0 zero)
+instruct compL_reg_immL0(rFlagsReg cr, iRegL op1, immL0 zero)
 %{
   match(Set cr (CmpL op1 zero));
 
@@ -14735,6 +14796,62 @@
   ins_pipe(icmp_reg_imm);
 %}
 
+instruct compUL_reg_reg(rFlagsRegU cr, iRegL op1, iRegL op2)
+%{
+  match(Set cr (CmpUL op1 op2));
+
+  effect(DEF cr, USE op1, USE op2);
+
+  ins_cost(INSN_COST);
+  format %{ "cmp  $op1, $op2" %}
+
+  ins_encode(aarch64_enc_cmp(op1, op2));
+
+  ins_pipe(icmp_reg_reg);
+%}
+
+instruct compUL_reg_immL0(rFlagsRegU cr, iRegL op1, immL0 zero)
+%{
+  match(Set cr (CmpUL op1 zero));
+
+  effect(DEF cr, USE op1);
+
+  ins_cost(INSN_COST);
+  format %{ "tst  $op1" %}
+
+  ins_encode(aarch64_enc_cmp_imm_addsub(op1, zero));
+
+  ins_pipe(icmp_reg_imm);
+%}
+
+instruct compUL_reg_immLAddSub(rFlagsRegU cr, iRegL op1, immLAddSub op2)
+%{
+  match(Set cr (CmpUL op1 op2));
+
+  effect(DEF cr, USE op1);
+
+  ins_cost(INSN_COST);
+  format %{ "cmp  $op1, $op2" %}
+
+  ins_encode(aarch64_enc_cmp_imm_addsub(op1, op2));
+
+  ins_pipe(icmp_reg_imm);
+%}
+
+instruct compUL_reg_immL(rFlagsRegU cr, iRegL op1, immL op2)
+%{
+  match(Set cr (CmpUL op1 op2));
+
+  effect(DEF cr, USE op1);
+
+  ins_cost(INSN_COST * 2);
+  format %{ "cmp  $op1, $op2" %}
+
+  ins_encode(aarch64_enc_cmp_imm(op1, op2));
+
+  ins_pipe(icmp_reg_imm);
+%}
+
 instruct compP_reg_reg(rFlagsRegU cr, iRegP op1, iRegP op2)
 %{
   match(Set cr (CmpP op1 op2));
@@ -15219,7 +15336,7 @@
 %}
 
 instruct cmpUL_imm0_branch(cmpOpUEqNeLtGe cmp, iRegL op1, immL0 op2, label labl, rFlagsRegU cr) %{
-  match(If cmp (CmpU op1 op2));
+  match(If cmp (CmpUL op1 op2));
   effect(USE labl);
 
   ins_cost(BRANCH_COST);
@@ -16046,6 +16163,16 @@
   ins_pipe(pipe_class_memory);
 %}
 
+instruct has_negatives(iRegP_R1 ary1, iRegI_R2 len, iRegI_R0 result, rFlagsReg cr)
+%{
+  match(Set result (HasNegatives ary1 len));
+  effect(USE_KILL ary1, USE_KILL len, KILL cr);
+  format %{ "has negatives byte[] $ary1,$len -> $result" %}
+  ins_encode %{
+    __ has_negatives($ary1$$Register, $len$$Register, $result$$Register);
+  %}
+  ins_pipe( pipe_slow );
+%}
 
 // fast char[] to byte[] compression
 instruct string_compress(iRegP_R2 src, iRegP_R1 dst, iRegI_R3 len,
--- a/src/cpu/aarch64/vm/c2_globals_aarch64.hpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/aarch64/vm/c2_globals_aarch64.hpp	Wed Sep 20 23:55:35 2017 -0400
@@ -49,12 +49,11 @@
 define_pd_global(intx, FLOATPRESSURE,                64);
 define_pd_global(intx, FreqInlineSize,               325);
 define_pd_global(intx, MinJumpTableSize,             10);
-define_pd_global(intx, INTPRESSURE,                  25);
+define_pd_global(intx, INTPRESSURE,                  24);
 define_pd_global(intx, InteriorEntryAlignment,       16);
 define_pd_global(intx, NewSizeThreadIncrease, ScaleForWordSize(4*K));
 define_pd_global(intx, LoopUnrollLimit,              60);
 define_pd_global(intx, LoopPercentProfileLimit,      10);
-define_pd_global(intx, PostLoopMultiversioning,      false);
 // InitialCodeCacheSize derived from specjbb2000 run.
 define_pd_global(intx, InitialCodeCacheSize,         2496*K); // Integral multiple of CodeCacheExpansionSize
 define_pd_global(intx, CodeCacheExpansionSize,       64*K);
--- a/src/cpu/aarch64/vm/globals_aarch64.hpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/aarch64/vm/globals_aarch64.hpp	Wed Sep 20 23:55:35 2017 -0400
@@ -154,8 +154,11 @@
   product(intx, BlockZeroingLowLimit, 256,                              \
           "Minimum size in bytes when block zeroing will be used")      \
           range(1, max_jint)                                            \
-  product(bool, TraceTraps, false, "Trace all traps the signal handler")
-
+  product(bool, TraceTraps, false, "Trace all traps the signal handler")\
+  product(int, SoftwarePrefetchHintDistance, -1,                        \
+          "Use prfm hint with specified distance in compiled code."     \
+          "Value -1 means off.")                                        \
+          range(-1, 32760)
 #endif
 
 
--- a/src/cpu/aarch64/vm/interp_masm_aarch64.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/aarch64/vm/interp_masm_aarch64.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -272,8 +272,7 @@
   // load pointer for resolved_references[] objArray
   ldr(result, Address(result, ConstantPool::cache_offset_in_bytes()));
   ldr(result, Address(result, ConstantPoolCache::resolved_references_offset_in_bytes()));
-  // JNIHandles::resolve(obj);
-  ldr(result, Address(result, 0));
+  resolve_oop_handle(result);
   // Add in the index
   add(result, result, tmp);
   load_heap_oop(result, Address(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
--- a/src/cpu/aarch64/vm/macroAssembler_aarch64.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/aarch64/vm/macroAssembler_aarch64.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -3279,6 +3279,12 @@
   }
 }
 
+// ((OopHandle)result).resolve();
+void MacroAssembler::resolve_oop_handle(Register result) {
+  // OopHandle::resolve is an indirection.
+  ldr(result, Address(result, 0));
+}
+
 void MacroAssembler::load_mirror(Register dst, Register method) {
   const int mirror_offset = in_bytes(Klass::java_mirror_offset());
   ldr(dst, Address(rmethod, Method::const_offset()));
@@ -4829,6 +4835,62 @@
   BLOCK_COMMENT("} string_compare");
 }
 
+// This method checks if provided byte array contains byte with highest bit set.
+void MacroAssembler::has_negatives(Register ary1, Register len, Register result) {
+    // Simple and most common case of aligned small array which is not at the
+    // end of memory page is placed here. All other cases are in stub.
+    Label LOOP, END, STUB, STUB_LONG, SET_RESULT, DONE;
+    const uint64_t UPPER_BIT_MASK=0x8080808080808080;
+    assert_different_registers(ary1, len, result);
+
+    cmpw(len, 0);
+    br(LE, SET_RESULT);
+    cmpw(len, 4 * wordSize);
+    br(GE, STUB_LONG); // size > 32 then go to stub
+
+    int shift = 64 - exact_log2(os::vm_page_size());
+    lsl(rscratch1, ary1, shift);
+    mov(rscratch2, (size_t)(4 * wordSize) << shift);
+    adds(rscratch2, rscratch1, rscratch2);  // At end of page?
+    br(CS, STUB); // at the end of page then go to stub
+    subs(len, len, wordSize);
+    br(LT, END);
+
+  BIND(LOOP);
+    ldr(rscratch1, Address(post(ary1, wordSize)));
+    tst(rscratch1, UPPER_BIT_MASK);
+    br(NE, SET_RESULT);
+    subs(len, len, wordSize);
+    br(GE, LOOP);
+    cmpw(len, -wordSize);
+    br(EQ, SET_RESULT);
+
+  BIND(END);
+    ldr(result, Address(ary1));
+    sub(len, zr, len, LSL, 3); // LSL 3 is to get bits from bytes
+    lslv(result, result, len);
+    tst(result, UPPER_BIT_MASK);
+    b(SET_RESULT);
+
+  BIND(STUB);
+    RuntimeAddress has_neg =  RuntimeAddress(StubRoutines::aarch64::has_negatives());
+    assert(has_neg.target() != NULL, "has_negatives stub has not been generated");
+    trampoline_call(has_neg);
+    b(DONE);
+
+  BIND(STUB_LONG);
+    RuntimeAddress has_neg_long =  RuntimeAddress(
+            StubRoutines::aarch64::has_negatives_long());
+    assert(has_neg_long.target() != NULL, "has_negatives stub has not been generated");
+    trampoline_call(has_neg_long);
+    b(DONE);
+
+  BIND(SET_RESULT);
+    cset(result, NE); // set true or false
+
+  BIND(DONE);
+}
+
 // Compare Strings or char/byte arrays.
 
 // is_string is true iff this is a string comparison.
--- a/src/cpu/aarch64/vm/macroAssembler_aarch64.hpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/aarch64/vm/macroAssembler_aarch64.hpp	Wed Sep 20 23:55:35 2017 -0400
@@ -790,6 +790,7 @@
   void store_klass(Register dst, Register src);
   void cmp_klass(Register oop, Register trial_klass, Register tmp);
 
+  void resolve_oop_handle(Register result);
   void load_mirror(Register dst, Register method);
 
   void load_heap_oop(Register dst, Address src);
@@ -1210,6 +1211,8 @@
                       Register tmp1,
                       FloatRegister vtmp, FloatRegister vtmpZ, int ae);
 
+  void has_negatives(Register ary1, Register len, Register result);
+
   void arrays_equals(Register a1, Register a2,
                      Register result, Register cnt1,
                      int elem_size, bool is_string);
--- a/src/cpu/aarch64/vm/stubGenerator_aarch64.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/aarch64/vm/stubGenerator_aarch64.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -3670,6 +3670,167 @@
     __ eor(result, __ T16B, lo, t0);
   }
 
+  address generate_has_negatives(address &has_negatives_long) {
+    StubCodeMark mark(this, "StubRoutines", "has_negatives");
+    const int large_loop_size = 64;
+    const uint64_t UPPER_BIT_MASK=0x8080808080808080;
+    int dcache_line = VM_Version::dcache_line_size();
+
+    Register ary1 = r1, len = r2, result = r0;
+
+    __ align(CodeEntryAlignment);
+    address entry = __ pc();
+
+    __ enter();
+
+  Label RET_TRUE, RET_TRUE_NO_POP, RET_FALSE, ALIGNED, LOOP16, CHECK_16, DONE,
+        LARGE_LOOP, POST_LOOP16, LEN_OVER_15, LEN_OVER_8, POST_LOOP16_LOAD_TAIL;
+
+  __ cmp(len, 15);
+  __ br(Assembler::GT, LEN_OVER_15);
+  // The only case when execution falls into this code is when pointer is near
+  // the end of memory page and we have to avoid reading next page
+  __ add(ary1, ary1, len);
+  __ subs(len, len, 8);
+  __ br(Assembler::GT, LEN_OVER_8);
+  __ ldr(rscratch2, Address(ary1, -8));
+  __ sub(rscratch1, zr, len, __ LSL, 3);  // LSL 3 is to get bits from bytes.
+  __ lsrv(rscratch2, rscratch2, rscratch1);
+  __ tst(rscratch2, UPPER_BIT_MASK);
+  __ cset(result, Assembler::NE);
+  __ leave();
+  __ ret(lr);
+  __ bind(LEN_OVER_8);
+  __ ldp(rscratch1, rscratch2, Address(ary1, -16));
+  __ sub(len, len, 8); // no data dep., then sub can be executed while loading
+  __ tst(rscratch2, UPPER_BIT_MASK);
+  __ br(Assembler::NE, RET_TRUE_NO_POP);
+  __ sub(rscratch2, zr, len, __ LSL, 3); // LSL 3 is to get bits from bytes
+  __ lsrv(rscratch1, rscratch1, rscratch2);
+  __ tst(rscratch1, UPPER_BIT_MASK);
+  __ cset(result, Assembler::NE);
+  __ leave();
+  __ ret(lr);
+
+  Register tmp1 = r3, tmp2 = r4, tmp3 = r5, tmp4 = r6, tmp5 = r7, tmp6 = r10;
+  const RegSet spilled_regs = RegSet::range(tmp1, tmp5) + tmp6;
+
+  has_negatives_long = __ pc(); // 2nd entry point
+
+  __ enter();
+
+  __ bind(LEN_OVER_15);
+    __ push(spilled_regs, sp);
+    __ andr(rscratch2, ary1, 15); // check pointer for 16-byte alignment
+    __ cbz(rscratch2, ALIGNED);
+    __ ldp(tmp6, tmp1, Address(ary1));
+    __ mov(tmp5, 16);
+    __ sub(rscratch1, tmp5, rscratch2); // amount of bytes until aligned address
+    __ add(ary1, ary1, rscratch1);
+    __ sub(len, len, rscratch1);
+    __ orr(tmp6, tmp6, tmp1);
+    __ tst(tmp6, UPPER_BIT_MASK);
+    __ br(Assembler::NE, RET_TRUE);
+
+  __ bind(ALIGNED);
+    __ cmp(len, large_loop_size);
+    __ br(Assembler::LT, CHECK_16);
+    // Perform 16-byte load as early return in pre-loop to handle situation
+    // when initially aligned large array has negative values at starting bytes,
+    // so LARGE_LOOP would do 4 reads instead of 1 (in worst case), which is
+    // slower. Cases with negative bytes further ahead won't be affected that
+    // much. In fact, it'll be faster due to early loads, less instructions and
+    // less branches in LARGE_LOOP.
+    __ ldp(tmp6, tmp1, Address(__ post(ary1, 16)));
+    __ sub(len, len, 16);
+    __ orr(tmp6, tmp6, tmp1);
+    __ tst(tmp6, UPPER_BIT_MASK);
+    __ br(Assembler::NE, RET_TRUE);
+    __ cmp(len, large_loop_size);
+    __ br(Assembler::LT, CHECK_16);
+
+    if (SoftwarePrefetchHintDistance >= 0
+        && SoftwarePrefetchHintDistance >= dcache_line) {
+      // initial prefetch
+      __ prfm(Address(ary1, SoftwarePrefetchHintDistance - dcache_line));
+    }
+  __ bind(LARGE_LOOP);
+    if (SoftwarePrefetchHintDistance >= 0) {
+      __ prfm(Address(ary1, SoftwarePrefetchHintDistance));
+    }
+    // Issue load instructions first, since it can save few CPU/MEM cycles, also
+    // instead of 4 triples of "orr(...), addr(...);cbnz(...);" (for each ldp)
+    // better generate 7 * orr(...) + 1 andr(...) + 1 cbnz(...) which saves 3
+    // instructions per cycle and have less branches, but this approach disables
+    // early return, thus, all 64 bytes are loaded and checked every time.
+    __ ldp(tmp2, tmp3, Address(ary1));
+    __ ldp(tmp4, tmp5, Address(ary1, 16));
+    __ ldp(rscratch1, rscratch2, Address(ary1, 32));
+    __ ldp(tmp6, tmp1, Address(ary1, 48));
+    __ add(ary1, ary1, large_loop_size);
+    __ sub(len, len, large_loop_size);
+    __ orr(tmp2, tmp2, tmp3);
+    __ orr(tmp4, tmp4, tmp5);
+    __ orr(rscratch1, rscratch1, rscratch2);
+    __ orr(tmp6, tmp6, tmp1);
+    __ orr(tmp2, tmp2, tmp4);
+    __ orr(rscratch1, rscratch1, tmp6);
+    __ orr(tmp2, tmp2, rscratch1);
+    __ tst(tmp2, UPPER_BIT_MASK);
+    __ br(Assembler::NE, RET_TRUE);
+    __ cmp(len, large_loop_size);
+    __ br(Assembler::GE, LARGE_LOOP);
+
+  __ bind(CHECK_16); // small 16-byte load pre-loop
+    __ cmp(len, 16);
+    __ br(Assembler::LT, POST_LOOP16);
+
+  __ bind(LOOP16); // small 16-byte load loop
+    __ ldp(tmp2, tmp3, Address(__ post(ary1, 16)));
+    __ sub(len, len, 16);
+    __ orr(tmp2, tmp2, tmp3);
+    __ tst(tmp2, UPPER_BIT_MASK);
+    __ br(Assembler::NE, RET_TRUE);
+    __ cmp(len, 16);
+    __ br(Assembler::GE, LOOP16); // 16-byte load loop end
+
+  __ bind(POST_LOOP16); // 16-byte aligned, so we can read unconditionally
+    __ cmp(len, 8);
+    __ br(Assembler::LE, POST_LOOP16_LOAD_TAIL);
+    __ ldr(tmp3, Address(__ post(ary1, 8)));
+    __ sub(len, len, 8);
+    __ tst(tmp3, UPPER_BIT_MASK);
+    __ br(Assembler::NE, RET_TRUE);
+
+  __ bind(POST_LOOP16_LOAD_TAIL);
+    __ cbz(len, RET_FALSE); // Can't shift left by 64 when len==0
+    __ ldr(tmp1, Address(ary1));
+    __ mov(tmp2, 64);
+    __ sub(tmp4, tmp2, len, __ LSL, 3);
+    __ lslv(tmp1, tmp1, tmp4);
+    __ tst(tmp1, UPPER_BIT_MASK);
+    __ br(Assembler::NE, RET_TRUE);
+    // Fallthrough
+
+  __ bind(RET_FALSE);
+    __ pop(spilled_regs, sp);
+    __ leave();
+    __ mov(result, zr);
+    __ ret(lr);
+
+  __ bind(RET_TRUE);
+    __ pop(spilled_regs, sp);
+  __ bind(RET_TRUE_NO_POP);
+    __ leave();
+    __ mov(result, 1);
+    __ ret(lr);
+
+  __ bind(DONE);
+    __ pop(spilled_regs, sp);
+    __ leave();
+    __ ret(lr);
+    return entry;
+  }
   /**
    *  Arguments:
    *
@@ -4686,6 +4847,7 @@
     // }
   };
 
+
   // Initialization
   void generate_initial() {
     // Generate initial stubs and initializes the entry points
@@ -4744,6 +4906,9 @@
     // arraycopy stubs used by compilers
     generate_arraycopy_stubs();
 
+    // has negatives stub for large arrays.
+    StubRoutines::aarch64::_has_negatives = generate_has_negatives(StubRoutines::aarch64::_has_negatives_long);
+
     if (UseMultiplyToLenIntrinsic) {
       StubRoutines::_multiplyToLen = generate_multiplyToLen();
     }
--- a/src/cpu/aarch64/vm/stubRoutines_aarch64.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/aarch64/vm/stubRoutines_aarch64.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -44,6 +44,8 @@
 address StubRoutines::aarch64::_double_sign_mask = NULL;
 address StubRoutines::aarch64::_double_sign_flip = NULL;
 address StubRoutines::aarch64::_zero_blocks = NULL;
+address StubRoutines::aarch64::_has_negatives = NULL;
+address StubRoutines::aarch64::_has_negatives_long = NULL;
 bool StubRoutines::aarch64::_completed = false;
 
 /**
--- a/src/cpu/aarch64/vm/stubRoutines_aarch64.hpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/aarch64/vm/stubRoutines_aarch64.hpp	Wed Sep 20 23:55:35 2017 -0400
@@ -62,6 +62,9 @@
   static address _double_sign_flip;
 
   static address _zero_blocks;
+
+  static address _has_negatives;
+  static address _has_negatives_long;
   static bool _completed;
 
  public:
@@ -120,6 +123,14 @@
     return _zero_blocks;
   }
 
+  static address has_negatives() {
+    return _has_negatives;
+  }
+
+  static address has_negatives_long() {
+      return _has_negatives_long;
+  }
+
   static bool complete() {
     return _completed;
   }
--- a/src/cpu/aarch64/vm/vm_version_aarch64.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/aarch64/vm/vm_version_aarch64.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -137,6 +137,8 @@
     FLAG_SET_DEFAULT(PrefetchScanIntervalInBytes, 3*dcache_line);
   if (FLAG_IS_DEFAULT(PrefetchCopyIntervalInBytes))
     FLAG_SET_DEFAULT(PrefetchCopyIntervalInBytes, 3*dcache_line);
+  if (FLAG_IS_DEFAULT(SoftwarePrefetchHintDistance))
+    FLAG_SET_DEFAULT(SoftwarePrefetchHintDistance, 3*dcache_line);
 
   if (PrefetchCopyIntervalInBytes != -1 &&
        ((PrefetchCopyIntervalInBytes & 7) || (PrefetchCopyIntervalInBytes >= 32768))) {
@@ -146,6 +148,12 @@
       PrefetchCopyIntervalInBytes = 32760;
   }
 
+  if (SoftwarePrefetchHintDistance != -1 &&
+       (SoftwarePrefetchHintDistance & 7)) {
+    warning("SoftwarePrefetchHintDistance must be -1, or a multiple of 8");
+    SoftwarePrefetchHintDistance &= ~7;
+  }
+
   unsigned long auxv = getauxval(AT_HWCAP);
 
   char buf[512];
--- a/src/cpu/aarch64/vm/vm_version_aarch64.hpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/aarch64/vm/vm_version_aarch64.hpp	Wed Sep 20 23:55:35 2017 -0400
@@ -56,6 +56,17 @@
   static void assert_is_initialized() {
   }
 
+  static bool expensive_load(int ld_size, int scale) {
+    if (cpu_family() == CPU_ARM) {
+      // Half-word load with index shift by 1 (aka scale is 2) has
+      // extra cycle latency, e.g. ldrsh w0, [x1,w2,sxtw #1].
+      if (ld_size == 2 && scale == 2) {
+        return true;
+      }
+    }
+    return false;
+  }
+
   enum Family {
     CPU_ARM       = 'A',
     CPU_BROADCOM  = 'B',
--- a/src/cpu/arm/vm/arm.ad	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/arm/vm/arm.ad	Wed Sep 20 23:55:35 2017 -0400
@@ -2695,6 +2695,30 @@
   format %{ "apsr_L_LEGT" %}
   interface(REG_INTER);
 %}
+
+operand flagsRegUL_LTGE() %{
+  constraint(ALLOC_IN_RC(int_flags));
+  match(RegFlags);
+
+  format %{ "apsr_UL_LTGE" %}
+  interface(REG_INTER);
+%}
+
+operand flagsRegUL_EQNE() %{
+  constraint(ALLOC_IN_RC(int_flags));
+  match(RegFlags);
+
+  format %{ "apsr_UL_EQNE" %}
+  interface(REG_INTER);
+%}
+
+operand flagsRegUL_LEGT() %{
+  constraint(ALLOC_IN_RC(int_flags));
+  match(RegFlags);
+
+  format %{ "apsr_UL_LEGT" %}
+  interface(REG_INTER);
+%}
 #endif
 
 // Condition Code Register, floating comparisons, unordered same as "less".
@@ -3249,6 +3273,39 @@
   %}
 %}
 
+operand cmpOpUL() %{
+  match(Bool);
+
+  format %{ "UL" %}
+  interface(COND_INTER) %{
+    equal(0x0);
+    not_equal(0x1);
+    less(0x3);
+    greater_equal(0x2);
+    less_equal(0x9);
+    greater(0x8);
+    overflow(0x0); // unsupported/unimplemented
+    no_overflow(0x0); // unsupported/unimplemented
+  %}
+%}
+
+operand cmpOpUL_commute() %{
+  match(Bool);
+
+  format %{ "UL" %}
+  interface(COND_INTER) %{
+    equal(0x0);
+    not_equal(0x1);
+    less(0x8);
+    greater_equal(0x9);
+    less_equal(0x2);
+    greater(0x3);
+    overflow(0x0); // unsupported/unimplemented
+    no_overflow(0x0); // unsupported/unimplemented
+  %}
+%}
+
+
 //----------OPERAND CLASSES----------------------------------------------------
 // Operand Classes are groups of operands that are used to simplify
 // instruction definitions by not requiring the AD writer to specify separate
@@ -10467,6 +10524,17 @@
   %}
   ins_pipe(ialu_cconly_reg_reg);
 %}
+
+instruct compUL_iReg(flagsRegU xcc, iRegL op1, iRegL op2) %{
+  match(Set xcc (CmpUL op1 op2));
+
+  size(4);
+  format %{ "CMP     $op1,$op2\t! unsigned long" %}
+  ins_encode %{
+    __ cmp($op1$$Register, $op2$$Register);
+  %}
+  ins_pipe(ialu_cconly_reg_reg);
+%}
 #else
 instruct compL_reg_reg_LTGE(flagsRegL_LTGE xcc, iRegL op1, iRegL op2, iRegL tmp) %{
   match(Set xcc (CmpL op1 op2));
@@ -10481,6 +10549,20 @@
   %}
   ins_pipe(ialu_cconly_reg_reg);
 %}
+
+instruct compUL_reg_reg_LTGE(flagsRegUL_LTGE xcc, iRegL op1, iRegL op2, iRegL tmp) %{
+  match(Set xcc (CmpUL op1 op2));
+  effect(DEF xcc, USE op1, USE op2, TEMP tmp);
+
+  size(8);
+  format %{ "SUBS    $tmp,$op1.low,$op2.low\t\t! unsigned long\n\t"
+            "SBCS    $tmp,$op1.hi,$op2.hi" %}
+  ins_encode %{
+    __ subs($tmp$$Register, $op1$$Register, $op2$$Register);
+    __ sbcs($tmp$$Register->successor(), $op1$$Register->successor(), $op2$$Register->successor());
+  %}
+  ins_pipe(ialu_cconly_reg_reg);
+%}
 #endif
 
 #ifdef AARCH64
@@ -10496,6 +10578,19 @@
 
   ins_pipe(ialu_cconly_reg_imm);
 %}
+
+instruct compUL_reg_con(flagsRegU xcc, iRegL op1, aimmL con) %{
+  match(Set xcc (CmpUL op1 con));
+  effect(DEF xcc, USE op1, USE con);
+
+  size(8);
+  format %{ "CMP     $op1,$con\t\t! unsigned long"  %}
+  ins_encode %{
+    __ cmp($op1$$Register, $con$$constant);
+  %}
+
+  ins_pipe(ialu_cconly_reg_imm);
+%}
 #else
 instruct compL_reg_reg_EQNE(flagsRegL_EQNE xcc, iRegL op1, iRegL op2) %{
   match(Set xcc (CmpL op1 op2));
@@ -10575,6 +10670,85 @@
 
   ins_pipe(ialu_cconly_reg_reg);
 %}
+
+instruct compUL_reg_reg_EQNE(flagsRegUL_EQNE xcc, iRegL op1, iRegL op2) %{
+  match(Set xcc (CmpUL op1 op2));
+  effect(DEF xcc, USE op1, USE op2);
+
+  size(8);
+  format %{ "TEQ    $op1.hi,$op2.hi\t\t! unsigned long\n\t"
+            "TEQ.eq $op1.lo,$op2.lo" %}
+  ins_encode %{
+    __ teq($op1$$Register->successor(), $op2$$Register->successor());
+    __ teq($op1$$Register, $op2$$Register, eq);
+  %}
+  ins_pipe(ialu_cconly_reg_reg);
+%}
+
+instruct compUL_reg_reg_LEGT(flagsRegUL_LEGT xcc, iRegL op1, iRegL op2, iRegL tmp) %{
+  match(Set xcc (CmpUL op1 op2));
+  effect(DEF xcc, USE op1, USE op2, TEMP tmp);
+
+  size(8);
+  format %{ "SUBS    $tmp,$op2.low,$op1.low\t\t! unsigned long\n\t"
+            "SBCS    $tmp,$op2.hi,$op1.hi" %}
+  ins_encode %{
+    __ subs($tmp$$Register, $op2$$Register, $op1$$Register);
+    __ sbcs($tmp$$Register->successor(), $op2$$Register->successor(), $op1$$Register->successor());
+  %}
+  ins_pipe(ialu_cconly_reg_reg);
+%}
+
+// TODO: try immLRot2 instead, (0, $con$$constant) becomes
+// (hi($con$$constant), lo($con$$constant)) becomes
+instruct compUL_reg_con_LTGE(flagsRegUL_LTGE xcc, iRegL op1, immLlowRot con, iRegL tmp) %{
+  match(Set xcc (CmpUL op1 con));
+  effect(DEF xcc, USE op1, USE con, TEMP tmp);
+
+  size(8);
+  format %{ "SUBS    $tmp,$op1.low,$con\t\t! unsigned long\n\t"
+            "SBCS    $tmp,$op1.hi,0" %}
+  ins_encode %{
+    __ subs($tmp$$Register, $op1$$Register, $con$$constant);
+    __ sbcs($tmp$$Register->successor(), $op1$$Register->successor(), 0);
+  %}
+
+  ins_pipe(ialu_cconly_reg_reg);
+%}
+
+// TODO: try immLRot2 instead, (0, $con$$constant) becomes
+// (hi($con$$constant), lo($con$$constant)) becomes
+instruct compUL_reg_con_EQNE(flagsRegUL_EQNE xcc, iRegL op1, immLlowRot con) %{
+  match(Set xcc (CmpUL op1 con));
+  effect(DEF xcc, USE op1, USE con);
+
+  size(8);
+  format %{ "TEQ    $op1.hi,0\t\t! unsigned long\n\t"
+            "TEQ.eq $op1.lo,$con" %}
+  ins_encode %{
+    __ teq($op1$$Register->successor(), 0);
+    __ teq($op1$$Register, $con$$constant, eq);
+  %}
+
+  ins_pipe(ialu_cconly_reg_reg);
+%}
+
+// TODO: try immLRot2 instead, (0, $con$$constant) becomes
+// (hi($con$$constant), lo($con$$constant)) becomes
+instruct compUL_reg_con_LEGT(flagsRegUL_LEGT xcc, iRegL op1, immLlowRot con, iRegL tmp) %{
+  match(Set xcc (CmpUL op1 con));
+  effect(DEF xcc, USE op1, USE con, TEMP tmp);
+
+  size(8);
+  format %{ "RSBS    $tmp,$op1.low,$con\t\t! unsigned long\n\t"
+            "RSCS    $tmp,$op1.hi,0" %}
+  ins_encode %{
+    __ rsbs($tmp$$Register, $op1$$Register, $con$$constant);
+    __ rscs($tmp$$Register->successor(), $op1$$Register->successor(), 0);
+  %}
+
+  ins_pipe(ialu_cconly_reg_reg);
+%}
 #endif
 
 /* instruct testL_reg_reg(flagsRegL xcc, iRegL op1, iRegL op2, immL0 zero) %{ */
@@ -11126,6 +11300,48 @@
   %}
   ins_pipe(br_cc);
 %}
+
+instruct branchConUL_LTGE(cmpOpUL cmp, flagsRegUL_LTGE xcc, label labl) %{
+  match(If cmp xcc);
+  effect(USE labl);
+  predicate(_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::lt || _kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ge);
+
+  size(4);
+  ins_cost(BRANCH_COST);
+  format %{ "B$cmp  $xcc,$labl" %}
+  ins_encode %{
+    __ b(*($labl$$label), (AsmCondition)($cmp$$cmpcode));
+  %}
+  ins_pipe(br_cc);
+%}
+
+instruct branchConUL_EQNE(cmpOpUL cmp, flagsRegUL_EQNE xcc, label labl) %{
+  match(If cmp xcc);
+  effect(USE labl);
+  predicate(_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::eq || _kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ne);
+
+  size(4);
+  ins_cost(BRANCH_COST);
+  format %{ "B$cmp  $xcc,$labl" %}
+  ins_encode %{
+    __ b(*($labl$$label), (AsmCondition)($cmp$$cmpcode));
+  %}
+  ins_pipe(br_cc);
+%}
+
+instruct branchConUL_LEGT(cmpOpUL_commute cmp, flagsRegUL_LEGT xcc, label labl) %{
+  match(If cmp xcc);
+  effect(USE labl);
+  predicate(_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::gt || _kids[0]->_leaf->as_Bool()->_test._test == BoolTest::le);
+
+  size(4);
+  ins_cost(BRANCH_COST);
+  format %{ "B$cmp  $xcc,$labl" %}
+  ins_encode %{
+    __ b(*($labl$$label), (AsmCondition)($cmp$$cmpcode));
+  %}
+  ins_pipe(br_cc);
+%}
 #endif
 
 instruct branchLoopEnd(cmpOp cmp, flagsReg icc, label labl) %{
--- a/src/cpu/arm/vm/c2_globals_arm.hpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/arm/vm/c2_globals_arm.hpp	Wed Sep 20 23:55:35 2017 -0400
@@ -70,7 +70,6 @@
 define_pd_global(bool, ResizeTLAB,                   true);
 define_pd_global(intx, LoopUnrollLimit,              60); // Design center runs on 1.3.1
 define_pd_global(intx, LoopPercentProfileLimit,      10);
-define_pd_global(intx, PostLoopMultiversioning,      false);
 define_pd_global(intx, MinJumpTableSize,             16);
 
 // Peephole and CISC spilling both break the graph, and so makes the
--- a/src/cpu/arm/vm/interp_masm_arm.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/arm/vm/interp_masm_arm.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -300,8 +300,7 @@
   // load pointer for resolved_references[] objArray
   ldr(cache, Address(result, ConstantPool::cache_offset_in_bytes()));
   ldr(cache, Address(result, ConstantPoolCache::resolved_references_offset_in_bytes()));
-  // JNIHandles::resolve(result)
-  ldr(cache, Address(cache, 0));
+  resolve_oop_handle(cache);
   // Add in the index
   // convert from field index to resolved_references() index and from
   // word index to byte offset. Since this is a java object, it can be compressed
--- a/src/cpu/arm/vm/macroAssembler_arm.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/arm/vm/macroAssembler_arm.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -2887,6 +2887,11 @@
   return offset();
 }
 
+// ((OopHandle)result).resolve();
+void MacroAssembler::resolve_oop_handle(Register result) {
+  // OopHandle::resolve is an indirection.
+  ldr(result, Address(result, 0));
+}
 
 void MacroAssembler::load_mirror(Register mirror, Register method, Register tmp) {
   const int mirror_offset = in_bytes(Klass::java_mirror_offset());
@@ -2896,6 +2901,7 @@
   ldr(mirror, Address(tmp, mirror_offset));
 }
 
+
 ///////////////////////////////////////////////////////////////////////////////
 
 // Compressed pointers
--- a/src/cpu/arm/vm/macroAssembler_arm.hpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/arm/vm/macroAssembler_arm.hpp	Wed Sep 20 23:55:35 2017 -0400
@@ -687,6 +687,7 @@
     AbstractAssembler::emit_address((address)L.data());
   }
 
+  void resolve_oop_handle(Register result);
   void load_mirror(Register mirror, Register method, Register tmp);
 
   // Porting layer between 32-bit ARM and AArch64
--- a/src/cpu/arm/vm/methodHandles_arm.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/arm/vm/methodHandles_arm.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -559,7 +559,7 @@
     values.print(p);
   }
   if (Verbose) {
-    if (has_mh && mh->is_oop()) {
+    if (has_mh && oopDesc::is_oop(mh)) {
       mh->print();
       if (java_lang_invoke_MethodHandle::is_instance(mh)) {
         if (java_lang_invoke_MethodHandle::form_offset_in_bytes() != 0)
--- a/src/cpu/ppc/vm/assembler_ppc.hpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/ppc/vm/assembler_ppc.hpp	Wed Sep 20 23:55:35 2017 -0400
@@ -510,8 +510,13 @@
     LXVD2X_OPCODE  = (31u << OPCODE_SHIFT |  844u << 1),
     STXVD2X_OPCODE = (31u << OPCODE_SHIFT |  972u << 1),
     MTVSRD_OPCODE  = (31u << OPCODE_SHIFT |  179u << 1),
+    MTVSRWZ_OPCODE = (31u << OPCODE_SHIFT |  243u << 1),
     MFVSRD_OPCODE  = (31u << OPCODE_SHIFT |   51u << 1),
     MTVSRWA_OPCODE = (31u << OPCODE_SHIFT |  211u << 1),
+    MFVSRWZ_OPCODE = (31u << OPCODE_SHIFT |  115u << 1),
+    XXPERMDI_OPCODE= (60u << OPCODE_SHIFT |   10u << 3),
+    XXMRGHW_OPCODE = (60u << OPCODE_SHIFT |   18u << 3),
+    XXMRGLW_OPCODE = (60u << OPCODE_SHIFT |   50u << 3),
 
     // Vector Permute and Formatting
     VPKPX_OPCODE   = (4u  << OPCODE_SHIFT |  782u     ),
@@ -561,6 +566,7 @@
     VADDUBM_OPCODE = (4u  << OPCODE_SHIFT |    0u     ),
     VADDUWM_OPCODE = (4u  << OPCODE_SHIFT |  128u     ),
     VADDUHM_OPCODE = (4u  << OPCODE_SHIFT |   64u     ),
+    VADDUDM_OPCODE = (4u  << OPCODE_SHIFT |  192u     ),
     VADDUBS_OPCODE = (4u  << OPCODE_SHIFT |  512u     ),
     VADDUWS_OPCODE = (4u  << OPCODE_SHIFT |  640u     ),
     VADDUHS_OPCODE = (4u  << OPCODE_SHIFT |  576u     ),
@@ -1099,16 +1105,19 @@
   static int vrs(   VectorRegister r)  { return  vrs(r->encoding());}
   static int vrt(   VectorRegister r)  { return  vrt(r->encoding());}
 
+  // Only used on SHA sigma instructions (VX-form)
+  static int vst(      int         x)  { return  opp_u_field(x,             16, 16); }
+  static int vsix(     int         x)  { return  opp_u_field(x,             20, 17); }
+
   // Support Vector-Scalar (VSX) instructions.
-  static int vsra(      int         x)  { return  opp_u_field(x,            15, 11); }
-  static int vsrb(      int         x)  { return  opp_u_field(x,            20, 16); }
-  static int vsrc(      int         x)  { return  opp_u_field(x,            25, 21); }
-  static int vsrs(      int         x)  { return  opp_u_field(x,            10,  6); }
-  static int vsrt(      int         x)  { return  opp_u_field(x,            10,  6); }
+  static int vsra(      int         x)  { return  opp_u_field(x & 0x1F,     15, 11) | opp_u_field((x & 0x20) >> 5, 29, 29); }
+  static int vsrb(      int         x)  { return  opp_u_field(x & 0x1F,     20, 16) | opp_u_field((x & 0x20) >> 5, 30, 30); }
+  static int vsrs(      int         x)  { return  opp_u_field(x & 0x1F,     10,  6) | opp_u_field((x & 0x20) >> 5, 31, 31); }
+  static int vsrt(      int         x)  { return  vsrs(x); }
+  static int vsdm(      int         x)  { return  opp_u_field(x,            23, 22); }
 
   static int vsra(   VectorSRegister r)  { return  vsra(r->encoding());}
   static int vsrb(   VectorSRegister r)  { return  vsrb(r->encoding());}
-  static int vsrc(   VectorSRegister r)  { return  vsrc(r->encoding());}
   static int vsrs(   VectorSRegister r)  { return  vsrs(r->encoding());}
   static int vsrt(   VectorSRegister r)  { return  vsrt(r->encoding());}
 
@@ -2027,7 +2036,7 @@
   inline void vperm(    VectorRegister d, VectorRegister a, VectorRegister b, VectorRegister c);
   inline void vsel(     VectorRegister d, VectorRegister a, VectorRegister b, VectorRegister c);
   inline void vsl(      VectorRegister d, VectorRegister a, VectorRegister b);
-  inline void vsldoi(   VectorRegister d, VectorRegister a, VectorRegister b, int si4);
+  inline void vsldoi(   VectorRegister d, VectorRegister a, VectorRegister b, int ui4);
   inline void vslo(     VectorRegister d, VectorRegister a, VectorRegister b);
   inline void vsr(      VectorRegister d, VectorRegister a, VectorRegister b);
   inline void vsro(     VectorRegister d, VectorRegister a, VectorRegister b);
@@ -2038,6 +2047,7 @@
   inline void vaddubm(  VectorRegister d, VectorRegister a, VectorRegister b);
   inline void vadduwm(  VectorRegister d, VectorRegister a, VectorRegister b);
   inline void vadduhm(  VectorRegister d, VectorRegister a, VectorRegister b);
+  inline void vaddudm(  VectorRegister d, VectorRegister a, VectorRegister b);
   inline void vaddubs(  VectorRegister d, VectorRegister a, VectorRegister b);
   inline void vadduws(  VectorRegister d, VectorRegister a, VectorRegister b);
   inline void vadduhs(  VectorRegister d, VectorRegister a, VectorRegister b);
@@ -2113,6 +2123,7 @@
   inline void vandc(    VectorRegister d, VectorRegister a, VectorRegister b);
   inline void vnor(     VectorRegister d, VectorRegister a, VectorRegister b);
   inline void vor(      VectorRegister d, VectorRegister a, VectorRegister b);
+  inline void vmr(      VectorRegister d, VectorRegister a);
   inline void vxor(     VectorRegister d, VectorRegister a, VectorRegister b);
   inline void vrld(     VectorRegister d, VectorRegister a, VectorRegister b);
   inline void vrlb(     VectorRegister d, VectorRegister a, VectorRegister b);
@@ -2136,8 +2147,19 @@
   inline void lxvd2x(   VectorSRegister d, Register a, Register b);
   inline void stxvd2x(  VectorSRegister d, Register a);
   inline void stxvd2x(  VectorSRegister d, Register a, Register b);
+  inline void mtvrwz(   VectorRegister  d, Register a);
+  inline void mfvrwz(   Register        a, VectorRegister d);
   inline void mtvrd(    VectorRegister  d, Register a);
   inline void mfvrd(    Register        a, VectorRegister d);
+  inline void xxpermdi( VectorSRegister d, VectorSRegister a, VectorSRegister b, int dm);
+  inline void xxmrghw(  VectorSRegister d, VectorSRegister a, VectorSRegister b);
+  inline void xxmrglw(  VectorSRegister d, VectorSRegister a, VectorSRegister b);
+
+  // VSX Extended Mnemonics
+  inline void xxspltd(  VectorSRegister d, VectorSRegister a, int x);
+  inline void xxmrghd(  VectorSRegister d, VectorSRegister a, VectorSRegister b);
+  inline void xxmrgld(  VectorSRegister d, VectorSRegister a, VectorSRegister b);
+  inline void xxswapd(  VectorSRegister d, VectorSRegister a);
 
   // Vector-Scalar (VSX) instructions.
   inline void mtfprd(   FloatRegister   d, Register a);
--- a/src/cpu/ppc/vm/assembler_ppc.inline.hpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/ppc/vm/assembler_ppc.inline.hpp	Wed Sep 20 23:55:35 2017 -0400
@@ -758,12 +758,23 @@
 inline void Assembler::lvsr(  VectorRegister d, Register s1, Register s2) { emit_int32( LVSR_OPCODE   | vrt(d) | ra0mem(s1) | rb(s2)); }
 
 // Vector-Scalar (VSX) instructions.
-inline void Assembler::lxvd2x (VectorSRegister d, Register s1) { emit_int32( LXVD2X_OPCODE  | vsrt(d) | ra(0) | rb(s1)); }
-inline void Assembler::lxvd2x (VectorSRegister d, Register s1, Register s2) { emit_int32( LXVD2X_OPCODE  | vsrt(d) | ra0mem(s1) | rb(s2)); }
-inline void Assembler::stxvd2x(VectorSRegister d, Register s1) { emit_int32( STXVD2X_OPCODE | vsrt(d) | ra(0) | rb(s1)); }
-inline void Assembler::stxvd2x(VectorSRegister d, Register s1, Register s2) { emit_int32( STXVD2X_OPCODE | vsrt(d) | ra0mem(s1) | rb(s2)); }
-inline void Assembler::mtvrd(  VectorRegister  d, Register a)               { emit_int32( MTVSRD_OPCODE  | vrt(d)  | ra(a)  | 1u); } // 1u: d is treated as Vector (VMX/Altivec).
-inline void Assembler::mfvrd(  Register        a, VectorRegister d)         { emit_int32( MFVSRD_OPCODE  | vrt(d)  | ra(a)  | 1u); } // 1u: d is treated as Vector (VMX/Altivec).
+inline void Assembler::lxvd2x(  VectorSRegister d, Register s1)              { emit_int32( LXVD2X_OPCODE  | vsrt(d) | ra(0) | rb(s1)); }
+inline void Assembler::lxvd2x(  VectorSRegister d, Register s1, Register s2) { emit_int32( LXVD2X_OPCODE  | vsrt(d) | ra0mem(s1) | rb(s2)); }
+inline void Assembler::stxvd2x( VectorSRegister d, Register s1)              { emit_int32( STXVD2X_OPCODE | vsrt(d) | ra(0) | rb(s1)); }
+inline void Assembler::stxvd2x( VectorSRegister d, Register s1, Register s2) { emit_int32( STXVD2X_OPCODE | vsrt(d) | ra0mem(s1) | rb(s2)); }
+inline void Assembler::mtvrd(   VectorRegister  d, Register a)               { emit_int32( MTVSRD_OPCODE  | vsrt(d->to_vsr()) | ra(a)); }
+inline void Assembler::mfvrd(   Register        a, VectorRegister d)         { emit_int32( MFVSRD_OPCODE  | vsrt(d->to_vsr()) | ra(a)); }
+inline void Assembler::mtvrwz(  VectorRegister  d, Register a)               { emit_int32( MTVSRWZ_OPCODE | vsrt(d->to_vsr()) | ra(a)); }
+inline void Assembler::mfvrwz(  Register        a, VectorRegister d)         { emit_int32( MFVSRWZ_OPCODE | vsrt(d->to_vsr()) | ra(a)); }
+inline void Assembler::xxpermdi(VectorSRegister d, VectorSRegister a, VectorSRegister b, int dm) { emit_int32( XXPERMDI_OPCODE | vsrt(d) | vsra(a) | vsrb(b) | vsdm(dm)); }
+inline void Assembler::xxmrghw( VectorSRegister d, VectorSRegister a, VectorSRegister b) { emit_int32( XXMRGHW_OPCODE | vsrt(d) | vsra(a) | vsrb(b)); }
+inline void Assembler::xxmrglw( VectorSRegister d, VectorSRegister a, VectorSRegister b) { emit_int32( XXMRGHW_OPCODE | vsrt(d) | vsra(a) | vsrb(b)); }
+
+// VSX Extended Mnemonics
+inline void Assembler::xxspltd( VectorSRegister d, VectorSRegister a, int x)             { xxpermdi(d, a, a, x ? 3 : 0); }
+inline void Assembler::xxmrghd( VectorSRegister d, VectorSRegister a, VectorSRegister b) { xxpermdi(d, a, b, 0); }
+inline void Assembler::xxmrgld( VectorSRegister d, VectorSRegister a, VectorSRegister b) { xxpermdi(d, a, b, 3); }
+inline void Assembler::xxswapd( VectorSRegister d, VectorSRegister a)                    { xxpermdi(d, a, a, 2); }
 
 // Vector-Scalar (VSX) instructions.
 inline void Assembler::mtfprd(  FloatRegister   d, Register a)      { emit_int32( MTVSRD_OPCODE  | frt(d)  | ra(a)); }
@@ -800,7 +811,7 @@
 inline void Assembler::vperm(   VectorRegister d, VectorRegister a, VectorRegister b, VectorRegister c){ emit_int32( VPERM_OPCODE | vrt(d) | vra(a) | vrb(b) | vrc(c)); }
 inline void Assembler::vsel(    VectorRegister d, VectorRegister a, VectorRegister b, VectorRegister c){ emit_int32( VSEL_OPCODE  | vrt(d) | vra(a) | vrb(b) | vrc(c)); }
 inline void Assembler::vsl(     VectorRegister d, VectorRegister a, VectorRegister b)                  { emit_int32( VSL_OPCODE   | vrt(d) | vra(a) | vrb(b)); }
-inline void Assembler::vsldoi(  VectorRegister d, VectorRegister a, VectorRegister b, int si4)         { emit_int32( VSLDOI_OPCODE| vrt(d) | vra(a) | vrb(b) | vsldoi_shb(simm(si4,4))); }
+inline void Assembler::vsldoi(  VectorRegister d, VectorRegister a, VectorRegister b, int ui4)         { emit_int32( VSLDOI_OPCODE| vrt(d) | vra(a) | vrb(b) | vsldoi_shb(uimm(ui4,4))); }
 inline void Assembler::vslo(    VectorRegister d, VectorRegister a, VectorRegister b) { emit_int32( VSLO_OPCODE    | vrt(d) | vra(a) | vrb(b)); }
 inline void Assembler::vsr(     VectorRegister d, VectorRegister a, VectorRegister b) { emit_int32( VSR_OPCODE     | vrt(d) | vra(a) | vrb(b)); }
 inline void Assembler::vsro(    VectorRegister d, VectorRegister a, VectorRegister b) { emit_int32( VSRO_OPCODE    | vrt(d) | vra(a) | vrb(b)); }
@@ -811,6 +822,7 @@
 inline void Assembler::vaddubm( VectorRegister d, VectorRegister a, VectorRegister b) { emit_int32( VADDUBM_OPCODE | vrt(d) | vra(a) | vrb(b)); }
 inline void Assembler::vadduwm( VectorRegister d, VectorRegister a, VectorRegister b) { emit_int32( VADDUWM_OPCODE | vrt(d) | vra(a) | vrb(b)); }
 inline void Assembler::vadduhm( VectorRegister d, VectorRegister a, VectorRegister b) { emit_int32( VADDUHM_OPCODE | vrt(d) | vra(a) | vrb(b)); }
+inline void Assembler::vaddudm( VectorRegister d, VectorRegister a, VectorRegister b) { emit_int32( VADDUDM_OPCODE | vrt(d) | vra(a) | vrb(b)); }
 inline void Assembler::vaddubs( VectorRegister d, VectorRegister a, VectorRegister b) { emit_int32( VADDUBS_OPCODE | vrt(d) | vra(a) | vrb(b)); }
 inline void Assembler::vadduws( VectorRegister d, VectorRegister a, VectorRegister b) { emit_int32( VADDUWS_OPCODE | vrt(d) | vra(a) | vrb(b)); }
 inline void Assembler::vadduhs( VectorRegister d, VectorRegister a, VectorRegister b) { emit_int32( VADDUHS_OPCODE | vrt(d) | vra(a) | vrb(b)); }
@@ -887,6 +899,7 @@
 inline void Assembler::vandc(   VectorRegister d, VectorRegister a, VectorRegister b) { emit_int32( VANDC_OPCODE    | vrt(d) | vra(a) | vrb(b)); }
 inline void Assembler::vnor(    VectorRegister d, VectorRegister a, VectorRegister b) { emit_int32( VNOR_OPCODE     | vrt(d) | vra(a) | vrb(b)); }
 inline void Assembler::vor(     VectorRegister d, VectorRegister a, VectorRegister b) { emit_int32( VOR_OPCODE      | vrt(d) | vra(a) | vrb(b)); }
+inline void Assembler::vmr(     VectorRegister d, VectorRegister a)                   { emit_int32( VOR_OPCODE      | vrt(d) | vra(a) | vrb(a)); }
 inline void Assembler::vxor(    VectorRegister d, VectorRegister a, VectorRegister b) { emit_int32( VXOR_OPCODE     | vrt(d) | vra(a) | vrb(b)); }
 inline void Assembler::vrld(    VectorRegister d, VectorRegister a, VectorRegister b) { emit_int32( VRLD_OPCODE     | vrt(d) | vra(a) | vrb(b)); }
 inline void Assembler::vrlb(    VectorRegister d, VectorRegister a, VectorRegister b) { emit_int32( VRLB_OPCODE     | vrt(d) | vra(a) | vrb(b)); }
--- a/src/cpu/ppc/vm/c2_globals_ppc.hpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/ppc/vm/c2_globals_ppc.hpp	Wed Sep 20 23:55:35 2017 -0400
@@ -55,7 +55,6 @@
 define_pd_global(bool, ResizeTLAB,                   true);
 define_pd_global(intx, LoopUnrollLimit,              60);
 define_pd_global(intx, LoopPercentProfileLimit,      10);
-define_pd_global(intx, PostLoopMultiversioning,      false);
 
 // Peephole and CISC spilling both break the graph, and so make the
 // scheduler sick.
--- a/src/cpu/ppc/vm/interp_masm_ppc_64.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/ppc/vm/interp_masm_ppc_64.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -464,8 +464,7 @@
   // Load pointer for resolved_references[] objArray.
   ld(result, ConstantPool::cache_offset_in_bytes(), result);
   ld(result, ConstantPoolCache::resolved_references_offset_in_bytes(), result);
-  // JNIHandles::resolve(result)
-  ld(result, 0, result);
+  resolve_oop_handle(result);
 #ifdef ASSERT
   Label index_ok;
   lwa(R0, arrayOopDesc::length_offset_in_bytes(), result);
--- a/src/cpu/ppc/vm/macroAssembler_ppc.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/ppc/vm/macroAssembler_ppc.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -3372,6 +3372,12 @@
   }
 }
 
+// ((OopHandle)result).resolve();
+void MacroAssembler::resolve_oop_handle(Register result) {
+  // OopHandle::resolve is an indirection.
+  ld(result, 0, result);
+}
+
 void MacroAssembler::load_mirror_from_const_method(Register mirror, Register const_method) {
   ld(mirror, in_bytes(ConstMethod::constants_offset()), const_method);
   ld(mirror, ConstantPool::pool_holder_offset_in_bytes(), mirror);
@@ -4576,12 +4582,12 @@
   vspltisw(VR0, -1);
 
   vsldoi(mask_32bit, zeroes, VR0, 4);
-  vsldoi(mask_64bit, zeroes, VR0, -8);
+  vsldoi(mask_64bit, zeroes, VR0, 8);
 
   // Get the initial value into v8
   vxor(VR8, VR8, VR8);
   mtvrd(VR8, crc);
-  vsldoi(VR8, zeroes, VR8, -8); // shift into bottom 32 bits
+  vsldoi(VR8, zeroes, VR8, 8); // shift into bottom 32 bits
 
   li (rLoaded, 0);
 
@@ -4930,7 +4936,7 @@
   addi(barretConstants, barretConstants, 16);
   lvx(const2, barretConstants);
 
-  vsldoi(VR1, VR0, VR0, -8);
+  vsldoi(VR1, VR0, VR0, 8);
   vxor(VR0, VR0, VR1);    // xor two 64 bit results together
 
   // shift left one bit
--- a/src/cpu/ppc/vm/macroAssembler_ppc.hpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/ppc/vm/macroAssembler_ppc.hpp	Wed Sep 20 23:55:35 2017 -0400
@@ -725,6 +725,7 @@
   void store_klass(Register dst_oop, Register klass, Register tmp = R0);
   void store_klass_gap(Register dst_oop, Register val = noreg); // Will store 0 if val not specified.
 
+  void resolve_oop_handle(Register result);
   void load_mirror_from_const_method(Register mirror, Register const_method);
 
   static int instr_size_for_decode_klass_not_null();
--- a/src/cpu/ppc/vm/methodHandles_ppc.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/ppc/vm/methodHandles_ppc.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -525,7 +525,7 @@
       values.print(p);
     }
 
-    if (has_mh && mh->is_oop()) {
+    if (has_mh && oopDesc::is_oop(mh)) {
       mh->print();
       if (java_lang_invoke_MethodHandle::is_instance(mh)) {
         if (java_lang_invoke_MethodHandle::form_offset_in_bytes() != 0)
--- a/src/cpu/ppc/vm/ppc.ad	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/ppc/vm/ppc.ad	Wed Sep 20 23:55:35 2017 -0400
@@ -11394,6 +11394,29 @@
   ins_pipe(pipe_class_compare);
 %}
 
+// Added CmpUL for LoopPredicate.
+instruct cmpUL_reg_reg(flagsReg crx, iRegLsrc src1, iRegLsrc src2) %{
+  match(Set crx (CmpUL src1 src2));
+  format %{ "CMPLD   $crx, $src1, $src2" %}
+  size(4);
+  ins_encode %{
+    // TODO: PPC port $archOpcode(ppc64Opcode_cmpl);
+    __ cmpld($crx$$CondRegister, $src1$$Register, $src2$$Register);
+  %}
+  ins_pipe(pipe_class_compare);
+%}
+
+instruct cmpUL_reg_imm16(flagsReg crx, iRegLsrc src1, uimmL16 src2) %{
+  match(Set crx (CmpUL src1 src2));
+  format %{ "CMPLDI  $crx, $src1, $src2" %}
+  size(4);
+  ins_encode %{
+    // TODO: PPC port $archOpcode(ppc64Opcode_cmpli);
+    __ cmpldi($crx$$CondRegister, $src1$$Register, $src2$$constant);
+  %}
+  ins_pipe(pipe_class_compare);
+%}
+
 instruct testL_reg_reg(flagsRegCR0 cr0, iRegLsrc src1, iRegLsrc src2, immL_0 zero) %{
   match(Set cr0 (CmpL (AndL src1 src2) zero));
   // r0 is killed
--- a/src/cpu/ppc/vm/register_ppc.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/ppc/vm/register_ppc.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2013 SAP SE. All rights reserved.
+ * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017 SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -81,8 +81,17 @@
     "VSR0",  "VSR1",  "VSR2",  "VSR3",  "VSR4",  "VSR5",  "VSR6",  "VSR7",
     "VSR8",  "VSR9",  "VSR10", "VSR11", "VSR12", "VSR13", "VSR14", "VSR15",
     "VSR16", "VSR17", "VSR18", "VSR19", "VSR20", "VSR21", "VSR22", "VSR23",
-    "VSR24", "VSR25", "VSR26", "VSR27", "VSR28", "VSR29", "VSR30", "VSR31"
+    "VSR24", "VSR25", "VSR26", "VSR27", "VSR28", "VSR29", "VSR30", "VSR31",
+    "VSR32", "VSR33", "VSR34", "VSR35", "VSR36", "VSR37", "VSR38", "VSR39",
+    "VSR40", "VSR41", "VSR42", "VSR43", "VSR44", "VSR45", "VSR46", "VSR47",
+    "VSR48", "VSR49", "VSR50", "VSR51", "VSR52", "VSR53", "VSR54", "VSR55",
+    "VSR56", "VSR57", "VSR58", "VSR59", "VSR60", "VSR61", "VSR62", "VSR63"
   };
   return is_valid() ? names[encoding()] : "vsnoreg";
 }
 
+// Method to convert a VectorRegister to a Vector-Scalar Register (VectorSRegister)
+VectorSRegister VectorRegisterImpl::to_vsr() const {
+  if (this == vnoreg) { return vsnoregi; }
+  return as_VectorSRegister(encoding() + 32);
+}
--- a/src/cpu/ppc/vm/register_ppc.hpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/ppc/vm/register_ppc.hpp	Wed Sep 20 23:55:35 2017 -0400
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2016 SAP SE. All rights reserved.
+ * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017 SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -398,6 +398,11 @@
   return (VectorRegister)(intptr_t)encoding;
 }
 
+// Forward declaration
+// Use VectorSRegister as a shortcut.
+class VectorSRegisterImpl;
+typedef VectorSRegisterImpl* VectorSRegister;
+
 // The implementation of vector registers for the Power architecture
 class VectorRegisterImpl: public AbstractRegisterImpl {
  public:
@@ -415,6 +420,9 @@
   bool is_valid()       const { return   0 <=  value()       &&  value() < number_of_registers; }
 
   const char* name() const;
+
+  // convert to VSR
+  VectorSRegister to_vsr() const;
 };
 
 // The Vector registers of the Power architecture
@@ -491,10 +499,6 @@
 #endif // DONT_USE_REGISTER_DEFINES
 
 
-// Use VectorSRegister as a shortcut.
-class VectorSRegisterImpl;
-typedef VectorSRegisterImpl* VectorSRegister;
-
 inline VectorSRegister as_VectorSRegister(int encoding) {
   return (VectorSRegister)(intptr_t)encoding;
 }
@@ -503,7 +507,7 @@
 class VectorSRegisterImpl: public AbstractRegisterImpl {
  public:
   enum {
-    number_of_registers = 32
+    number_of_registers = 64
   };
 
   // construction
@@ -554,6 +558,38 @@
 CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR29, (29));
 CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR30, (30));
 CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR31, (31));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR32, (32));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR33, (33));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR34, (34));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR35, (35));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR36, (36));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR37, (37));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR38, (38));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR39, (39));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR40, (40));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR41, (41));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR42, (42));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR43, (43));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR44, (44));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR45, (45));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR46, (46));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR47, (47));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR48, (48));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR49, (49));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR50, (50));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR51, (51));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR52, (52));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR53, (53));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR54, (54));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR55, (55));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR56, (56));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR57, (57));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR58, (58));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR59, (59));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR60, (60));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR61, (61));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR62, (62));
+CONSTANT_REGISTER_DECLARATION(VectorSRegister, VSR63, (63));
 
 #ifndef DONT_USE_REGISTER_DEFINES
 #define vsnoregi ((VectorSRegister)(vsnoreg_VectorSRegisterEnumValue))
@@ -589,6 +625,38 @@
 #define VSR29   ((VectorSRegister)(  VSR29_VectorSRegisterEnumValue))
 #define VSR30   ((VectorSRegister)(  VSR30_VectorSRegisterEnumValue))
 #define VSR31   ((VectorSRegister)(  VSR31_VectorSRegisterEnumValue))
+#define VSR32   ((VectorSRegister)(  VSR32_VectorSRegisterEnumValue))
+#define VSR33   ((VectorSRegister)(  VSR33_VectorSRegisterEnumValue))
+#define VSR34   ((VectorSRegister)(  VSR34_VectorSRegisterEnumValue))
+#define VSR35   ((VectorSRegister)(  VSR35_VectorSRegisterEnumValue))
+#define VSR36   ((VectorSRegister)(  VSR36_VectorSRegisterEnumValue))
+#define VSR37   ((VectorSRegister)(  VSR37_VectorSRegisterEnumValue))
+#define VSR38   ((VectorSRegister)(  VSR38_VectorSRegisterEnumValue))
+#define VSR39   ((VectorSRegister)(  VSR39_VectorSRegisterEnumValue))
+#define VSR40   ((VectorSRegister)(  VSR40_VectorSRegisterEnumValue))
+#define VSR41   ((VectorSRegister)(  VSR41_VectorSRegisterEnumValue))
+#define VSR42   ((VectorSRegister)(  VSR42_VectorSRegisterEnumValue))
+#define VSR43   ((VectorSRegister)(  VSR43_VectorSRegisterEnumValue))
+#define VSR44   ((VectorSRegister)(  VSR44_VectorSRegisterEnumValue))
+#define VSR45   ((VectorSRegister)(  VSR45_VectorSRegisterEnumValue))
+#define VSR46   ((VectorSRegister)(  VSR46_VectorSRegisterEnumValue))
+#define VSR47   ((VectorSRegister)(  VSR47_VectorSRegisterEnumValue))
+#define VSR48   ((VectorSRegister)(  VSR48_VectorSRegisterEnumValue))
+#define VSR49   ((VectorSRegister)(  VSR49_VectorSRegisterEnumValue))
+#define VSR50   ((VectorSRegister)(  VSR50_VectorSRegisterEnumValue))
+#define VSR51   ((VectorSRegister)(  VSR51_VectorSRegisterEnumValue))
+#define VSR52   ((VectorSRegister)(  VSR52_VectorSRegisterEnumValue))
+#define VSR53   ((VectorSRegister)(  VSR53_VectorSRegisterEnumValue))
+#define VSR54   ((VectorSRegister)(  VSR54_VectorSRegisterEnumValue))
+#define VSR55   ((VectorSRegister)(  VSR55_VectorSRegisterEnumValue))
+#define VSR56   ((VectorSRegister)(  VSR56_VectorSRegisterEnumValue))
+#define VSR57   ((VectorSRegister)(  VSR57_VectorSRegisterEnumValue))
+#define VSR58   ((VectorSRegister)(  VSR58_VectorSRegisterEnumValue))
+#define VSR59   ((VectorSRegister)(  VSR59_VectorSRegisterEnumValue))
+#define VSR60   ((VectorSRegister)(  VSR60_VectorSRegisterEnumValue))
+#define VSR61   ((VectorSRegister)(  VSR61_VectorSRegisterEnumValue))
+#define VSR62   ((VectorSRegister)(  VSR62_VectorSRegisterEnumValue))
+#define VSR63   ((VectorSRegister)(  VSR63_VectorSRegisterEnumValue))
 #endif // DONT_USE_REGISTER_DEFINES
 
 // Maximum number of incoming arguments that can be passed in i registers.
@@ -609,7 +677,7 @@
       * 2                                          // register halves
       + ConditionRegisterImpl::number_of_registers // condition code registers
       + SpecialRegisterImpl::number_of_registers   // special registers
-      + VectorRegisterImpl::number_of_registers    // vector registers
+      + VectorRegisterImpl::number_of_registers    // VSX registers
   };
 
   static const int max_gpr;
--- a/src/cpu/ppc/vm/stubGenerator_ppc.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/ppc/vm/stubGenerator_ppc.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -830,7 +830,7 @@
   // Wrapper which calls oopDesc::is_oop_or_null()
   // Only called by MacroAssembler::verify_oop
   static void verify_oop_helper(const char* message, oop o) {
-    if (!o->is_oop_or_null()) {
+    if (!oopDesc::is_oop_or_null(o)) {
       fatal("%s", message);
     }
     ++ StubRoutines::_verify_oop_count;
@@ -2729,7 +2729,7 @@
     __ vspltisb        (vTmp2, -16);
     __ vrld            (keyPerm, keyPerm, vTmp2);
     __ vrld            (keyPerm, keyPerm, vTmp2);
-    __ vsldoi          (keyPerm, keyPerm, keyPerm, -8);
+    __ vsldoi          (keyPerm, keyPerm, keyPerm, 8);
 
     // load the 1st round key to vKey1
     __ li              (keypos, 0);
@@ -2929,7 +2929,7 @@
     __ vspltisb        (vTmp2, -16);
     __ vrld            (keyPerm, keyPerm, vTmp2);
     __ vrld            (keyPerm, keyPerm, vTmp2);
-    __ vsldoi          (keyPerm, keyPerm, keyPerm, -8);
+    __ vsldoi          (keyPerm, keyPerm, keyPerm, 8);
 
     __ cmpwi           (CCR0, keylen, 44);
     __ beq             (CCR0, L_do44);
--- a/src/cpu/ppc/vm/templateInterpreterGenerator_ppc.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/ppc/vm/templateInterpreterGenerator_ppc.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -56,7 +56,7 @@
 // if too small.
 // Run with +PrintInterpreter to get the VM to print out the size.
 // Max size with JVMTI
-int TemplateInterpreter::InterpreterCodeSize = 230*K;
+int TemplateInterpreter::InterpreterCodeSize = 256*K;
 
 #ifdef PRODUCT
 #define BLOCK_COMMENT(str) /* nothing */
--- a/src/cpu/s390/vm/assembler_s390.inline.hpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/s390/vm/assembler_s390.inline.hpp	Wed Sep 20 23:55:35 2017 -0400
@@ -246,8 +246,8 @@
 inline void Assembler::z_mvhhi( int64_t d1, Register b1, int64_t i2) { emit_48( MVHHI_ZOPC | uimm12( d1, 20, 48) | regz(b1, 16, 48) | simm16(i2, 32, 48)); }
 inline void Assembler::z_mvhi ( int64_t d1, Register b1, int64_t i2) { emit_48( MVHI_ZOPC  | uimm12( d1, 20, 48) | regz(b1, 16, 48) | simm16(i2, 32, 48)); }
 inline void Assembler::z_mvghi( int64_t d1, Register b1, int64_t i2) { emit_48( MVGHI_ZOPC | uimm12( d1, 20, 48) | regz(b1, 16, 48) | simm16(i2, 32, 48)); }
-inline void Assembler::z_mvhhi( const Address &d, int64_t i2) { assert(!d.has_index(), " no index reg allowed in MVHHI"); z_mvghi( d.disp(), d.baseOrR0(), i2); }
-inline void Assembler::z_mvhi ( const Address &d, int64_t i2) { assert(!d.has_index(), " no index reg allowed in MVHI");  z_mvghi( d.disp(), d.baseOrR0(), i2); }
+inline void Assembler::z_mvhhi( const Address &d, int64_t i2) { assert(!d.has_index(), " no index reg allowed in MVHHI"); z_mvhhi( d.disp(), d.baseOrR0(), i2); }
+inline void Assembler::z_mvhi ( const Address &d, int64_t i2) { assert(!d.has_index(), " no index reg allowed in MVHI");  z_mvhi(  d.disp(), d.baseOrR0(), i2); }
 inline void Assembler::z_mvghi( const Address &d, int64_t i2) { assert(!d.has_index(), " no index reg allowed in MVGHI"); z_mvghi( d.disp(), d.baseOrR0(), i2); }
 
 inline void Assembler::z_ex(Register r1, int64_t d2, Register x2, Register b2) { emit_32( EX_ZOPC | regz(r1, 8, 32) | uimm12(d2, 20, 32) | reg(x2, 12, 32) | regz(b2, 16, 32)); }
--- a/src/cpu/s390/vm/c2_globals_s390.hpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/s390/vm/c2_globals_s390.hpp	Wed Sep 20 23:55:35 2017 -0400
@@ -56,7 +56,6 @@
 define_pd_global(bool, ResizeTLAB,                   true);
 define_pd_global(intx, LoopUnrollLimit,              60);
 define_pd_global(intx, LoopPercentProfileLimit,      10);
-define_pd_global(intx, PostLoopMultiversioning,      false);
 define_pd_global(intx, MinJumpTableSize,             18);
 
 // Peephole and CISC spilling both break the graph, and so makes the
--- a/src/cpu/s390/vm/compiledIC_s390.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/s390/vm/compiledIC_s390.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -105,15 +105,18 @@
   NativeMovConstReg* method_holder = nativeMovConstReg_at(stub + NativeCall::get_IC_pos_in_java_to_interp_stub());
   NativeJump*        jump          = nativeJump_at(method_holder->next_instruction_address());
 
+#ifdef ASSERT
   // A generated lambda form might be deleted from the Lambdaform
   // cache in MethodTypeForm.  If a jit compiled lambdaform method
   // becomes not entrant and the cache access returns null, the new
   // resolve will lead to a new generated LambdaForm.
-
-  assert(method_holder->data() == 0 || method_holder->data() == (intptr_t)callee() || callee->is_compiled_lambda_form(),
+  volatile intptr_t data = method_holder->data();
+  volatile address destination = jump->jump_destination();
+  assert(data == 0 || data == (intptr_t)callee() || callee->is_compiled_lambda_form(),
          "a) MT-unsafe modification of inline cache");
-  assert(jump->jump_destination() == (address)-1 || jump->jump_destination() == entry,
+  assert(destination == (address)-1 || destination == entry,
          "b) MT-unsafe modification of inline cache");
+#endif
 
   // Update stub.
   method_holder->set_data((intptr_t)callee());
--- a/src/cpu/s390/vm/interp_masm_s390.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/s390/vm/interp_masm_s390.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -364,8 +364,7 @@
   // Load pointer for resolved_references[] objArray.
   z_lg(result, ConstantPool::cache_offset_in_bytes(), result);
   z_lg(result, ConstantPoolCache::resolved_references_offset_in_bytes(), result);
-  // JNIHandles::resolve(result)
-  z_lg(result, 0, result); // Load resolved references array itself.
+  resolve_oop_handle(result); // Load resolved references array itself.
 #ifdef ASSERT
   NearLabel index_ok;
   z_lgf(Z_R0, Address(result, arrayOopDesc::length_offset_in_bytes()));
--- a/src/cpu/s390/vm/macroAssembler_s390.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/s390/vm/macroAssembler_s390.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -4660,6 +4660,12 @@
   }
 }
 
+// ((OopHandle)result).resolve();
+void MacroAssembler::resolve_oop_handle(Register result) {
+  // OopHandle::resolve is an indirection.
+  z_lg(result, 0, result);
+}
+
 void MacroAssembler::load_mirror(Register mirror, Register method) {
   mem2reg_opt(mirror, Address(method, Method::const_offset()));
   mem2reg_opt(mirror, Address(mirror, ConstMethod::constants_offset()));
--- a/src/cpu/s390/vm/macroAssembler_s390.hpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/s390/vm/macroAssembler_s390.hpp	Wed Sep 20 23:55:35 2017 -0400
@@ -832,6 +832,7 @@
   void oop_decoder(Register Rdst, Register Rsrc, bool maybeNULL,
                    Register Rbase = Z_R1, int pow2_offset = -1);
 
+  void resolve_oop_handle(Register result);
   void load_mirror(Register mirror, Register method);
 
   //--------------------------
--- a/src/cpu/s390/vm/methodHandles_s390.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/s390/vm/methodHandles_s390.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -595,7 +595,7 @@
     // Note: the unextended_sp may not be correct.
     tty->print_cr("  stack layout:");
     values.print(p);
-    if (has_mh && mh->is_oop()) {
+    if (has_mh && oopDesc::is_oop(mh)) {
       mh->print();
       if (java_lang_invoke_MethodHandle::is_instance(mh)) {
         if (java_lang_invoke_MethodHandle::form_offset_in_bytes() != 0) {
--- a/src/cpu/s390/vm/s390.ad	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/s390/vm/s390.ad	Wed Sep 20 23:55:35 2017 -0400
@@ -8470,6 +8470,24 @@
 %}
 
 //  LONG unsigned
+// Added CmpUL for LoopPredicate.
+instruct compUL_reg_reg(flagsReg cr, iRegL op1, iRegL op2) %{
+  match(Set cr (CmpUL op1 op2));
+  size(4);
+  format %{ "CLGR    $op1,$op2\t # long" %}
+  opcode(CLGR_ZOPC);
+  ins_encode(z_rreform(op1, op2));
+  ins_pipe(pipe_class_dummy);
+%}
+
+instruct compUL_reg_imm32(flagsReg cr, iRegL op1, uimmL32 con) %{
+  match(Set cr (CmpUL op1 con));
+  size(6);
+  format %{ "CLGFI   $op1,$con" %}
+  opcode(CLGFI_ZOPC);
+  ins_encode(z_rilform_unsigned(op1, con));
+  ins_pipe(pipe_class_dummy);
+%}
 
 //  PTR unsigned
 
--- a/src/cpu/s390/vm/stubGenerator_s390.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/s390/vm/stubGenerator_s390.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -1683,7 +1683,7 @@
   //   src    must designate an even/odd register pair, holding the address/length of the original message
 
   // Helper function which generates code to
-  //  - load the function code in register fCode (== Z_R0)
+  //  - load the function code in register fCode (== Z_R0).
   //  - load the data block length (depends on cipher function) into register srclen if requested.
   //  - is_decipher switches between cipher/decipher function codes
   //  - set_len requests (if true) loading the data block length in register srclen
@@ -1695,13 +1695,13 @@
       bool  identical_dataBlk_len =  (VM_Version::Cipher::_AES128_dataBlk == VM_Version::Cipher::_AES192_dataBlk)
                                   && (VM_Version::Cipher::_AES128_dataBlk == VM_Version::Cipher::_AES256_dataBlk);
       // Expanded key length is 44/52/60 * 4 bytes for AES-128/AES-192/AES-256.
-      __ z_cghi(keylen, 52);
-
-      __ z_lghi(fCode, VM_Version::Cipher::_AES256 + mode);
+      __ z_cghi(keylen, 52); // Check only once at the beginning. keylen and fCode may share the same register.
+
+      __ z_lghi(fCode, VM_Version::Cipher::_AES128 + mode);
       if (!identical_dataBlk_len) {
-        __ z_lghi(srclen, VM_Version::Cipher::_AES256_dataBlk);
+        __ z_lghi(srclen, VM_Version::Cipher::_AES128_dataBlk);
       }
-      __ z_brh(fCode_set);  // keyLen >  52: AES256
+      __ z_brl(fCode_set);  // keyLen <  52: AES128
 
       __ z_lghi(fCode, VM_Version::Cipher::_AES192 + mode);
       if (!identical_dataBlk_len) {
@@ -1709,11 +1709,11 @@
       }
       __ z_bre(fCode_set);  // keyLen == 52: AES192
 
-      __ z_lghi(fCode, VM_Version::Cipher::_AES128 + mode);
+      __ z_lghi(fCode, VM_Version::Cipher::_AES256 + mode);
       if (!identical_dataBlk_len) {
-        __ z_lghi(srclen, VM_Version::Cipher::_AES128_dataBlk);
+        __ z_lghi(srclen, VM_Version::Cipher::_AES256_dataBlk);
       }
-      // __ z_brl(fCode_set);  // keyLen <  52: AES128           // fallthru
+      // __ z_brh(fCode_set);  // keyLen <  52: AES128           // fallthru
 
       __ bind(fCode_set);
       if (identical_dataBlk_len) {
@@ -1724,6 +1724,54 @@
   }
 
   // Push a parameter block for the cipher/decipher instruction on the stack.
+  // Layout of the additional stack space allocated for AES_cipherBlockChaining:
+  //
+  //   |        |
+  //   +--------+ <-- SP before expansion
+  //   |        |
+  //   :        :  alignment loss, 0..(AES_parmBlk_align-8) bytes
+  //   |        |
+  //   +--------+
+  //   |        |
+  //   :        :  space for parameter block, size VM_Version::Cipher::_AES*_parmBlk_C
+  //   |        |
+  //   +--------+ <-- parmBlk, octoword-aligned, start of parameter block
+  //   |        |
+  //   :        :  additional stack space for spills etc., size AES_parmBlk_addspace, DW @ Z_SP not usable!!!
+  //   |        |
+  //   +--------+ <-- Z_SP after expansion
+
+  void generate_push_Block(int dataBlk_len, int parmBlk_len, int crypto_fCode,
+                           Register parmBlk, Register keylen, Register fCode, Register cv, Register key) {
+    const int AES_parmBlk_align    = 32;  // octoword alignment.
+    const int AES_parmBlk_addspace = 24;  // Must be sufficiently large to hold all spilled registers
+                                          // (currently 2) PLUS 1 DW for the frame pointer.
+
+    const int cv_len     = dataBlk_len;
+    const int key_len    = parmBlk_len - cv_len;
+    // This len must be known at JIT compile time. Only then are we able to recalc the SP before resize.
+    // We buy this knowledge by wasting some (up to AES_parmBlk_align) bytes of stack space.
+    const int resize_len = cv_len + key_len + AES_parmBlk_align + AES_parmBlk_addspace;
+
+    // Use parmBlk as temp reg here to hold the frame pointer.
+    __ resize_frame(-resize_len, parmBlk, true);
+
+    // calculate parmBlk address from updated (resized) SP.
+    __ add2reg(parmBlk, resize_len - (cv_len + key_len), Z_SP);
+    __ z_nill(parmBlk, (~(AES_parmBlk_align-1)) & 0xffff); // Align parameter block.
+
+    // There is room for stuff in the range [parmBlk-AES_parmBlk_addspace+8, parmBlk).
+    __ z_stg(keylen,  -8, parmBlk);                        // Spill keylen for later use.
+
+    // calculate (SP before resize) from updated SP.
+    __ add2reg(keylen, resize_len, Z_SP);                  // keylen holds prev SP for now.
+    __ z_stg(keylen, -16, parmBlk);                        // Spill prev SP for easy revert.
+
+    __ z_mvc(0,      cv_len-1,  parmBlk, 0, cv);     // Copy cv.
+    __ z_mvc(cv_len, key_len-1, parmBlk, 0, key);    // Copy key.
+    __ z_lghi(fCode, crypto_fCode);
+  }
+
   // NOTE:
   //   Before returning, the stub has to copy the chaining value from
   //   the parmBlk, where it was updated by the crypto instruction, back
@@ -1732,17 +1780,14 @@
   //   the key length across the KMC instruction. We do so by spilling it to the stack,
   //   just preceding the parmBlk (at (parmBlk - 8)).
   void generate_push_parmBlk(Register keylen, Register fCode, Register parmBlk, Register key, Register cv, bool is_decipher) {
-    const int AES_parmBlk_align    = 32;
-    const int AES_parmBlk_addspace = AES_parmBlk_align; // Must be multiple of AES_parmblk_align.
-    int       cv_len, key_len;
     int       mode = is_decipher ? VM_Version::CipherMode::decipher : VM_Version::CipherMode::cipher;
     Label     parmBlk_128, parmBlk_192, parmBlk_256, parmBlk_set;
 
     BLOCK_COMMENT("push parmBlk {");
     if (VM_Version::has_Crypto_AES()   ) { __ z_cghi(keylen, 52); }
+    if (VM_Version::has_Crypto_AES128()) { __ z_brl(parmBlk_128); }  // keyLen <  52: AES128
+    if (VM_Version::has_Crypto_AES192()) { __ z_bre(parmBlk_192); }  // keyLen == 52: AES192
     if (VM_Version::has_Crypto_AES256()) { __ z_brh(parmBlk_256); }  // keyLen >  52: AES256
-    if (VM_Version::has_Crypto_AES192()) { __ z_bre(parmBlk_192); }  // keyLen == 52: AES192
-    if (VM_Version::has_Crypto_AES128()) { __ z_brl(parmBlk_128); }  // keyLen <  52: AES128
 
     // Security net: requested AES function not available on this CPU.
     // NOTE:
@@ -1751,71 +1796,35 @@
     //   at all, we have at least AES-128.
     __ stop_static("AES key strength not supported by CPU. Use -XX:-UseAES as remedy.", 0);
 
-    if (VM_Version::has_Crypto_AES128()) {
-      __ bind(parmBlk_128);
-      cv_len  = VM_Version::Cipher::_AES128_dataBlk;
-      key_len = VM_Version::Cipher::_AES128_parmBlk_C - cv_len;
-      __ z_lay(parmBlk, -(VM_Version::Cipher::_AES128_parmBlk_C+AES_parmBlk_align)+(AES_parmBlk_align-1), Z_SP);
-      __ z_nill(parmBlk, (~(AES_parmBlk_align-1)) & 0xffff);  // align parameter block
-
-      // Resize the frame to accommodate for the aligned parameter block and other stuff.
-      // There is room for stuff in the range [parmBlk-AES_parmBlk_addspace, parmBlk).
-      __ z_stg(keylen, -8, parmBlk);                   // Spill keylen for later use.
-      __ z_stg(Z_SP,  -16, parmBlk);                   // Spill SP for easy revert.
-      __ z_aghi(parmBlk, -AES_parmBlk_addspace);       // Additional space for keylen, etc..
-      __ resize_frame_absolute(parmBlk, keylen, true); // Resize frame with parmBlk being the new SP.
-      __ z_aghi(parmBlk,  AES_parmBlk_addspace);       // Restore parameter block address.
-
-      __ z_mvc(0,      cv_len-1,  parmBlk, 0, cv);     // Copy cv.
-      __ z_mvc(cv_len, key_len-1, parmBlk, 0, key);    // Copy key.
-      __ z_lghi(fCode, VM_Version::Cipher::_AES128 + mode);
-      if (VM_Version::has_Crypto_AES192() || VM_Version::has_Crypto_AES256()) {
+    if (VM_Version::has_Crypto_AES256()) {
+      __ bind(parmBlk_256);
+      generate_push_Block(VM_Version::Cipher::_AES256_dataBlk,
+                          VM_Version::Cipher::_AES256_parmBlk_C,
+                          VM_Version::Cipher::_AES256 + mode,
+                          parmBlk, keylen, fCode, cv, key);
+      if (VM_Version::has_Crypto_AES128() || VM_Version::has_Crypto_AES192()) {
         __ z_bru(parmBlk_set);  // Fallthru otherwise.
       }
     }
 
     if (VM_Version::has_Crypto_AES192()) {
       __ bind(parmBlk_192);
-      cv_len  = VM_Version::Cipher::_AES192_dataBlk;
-      key_len = VM_Version::Cipher::_AES192_parmBlk_C - cv_len;
-      __ z_lay(parmBlk, -(VM_Version::Cipher::_AES192_parmBlk_C+AES_parmBlk_align)+(AES_parmBlk_align-1), Z_SP);
-      __ z_nill(parmBlk, (~(AES_parmBlk_align-1)) & 0xffff);  // Align parameter block.
-
-      // Resize the frame to accommodate for the aligned parameter block and other stuff.
-      // There is room for stuff in the range [parmBlk-AES_parmBlk_addspace, parmBlk).
-      __ z_stg(keylen, -8, parmBlk);                   // Spill keylen for later use.
-      __ z_stg(Z_SP,  -16, parmBlk);                   // Spill SP for easy revert.
-      __ z_aghi(parmBlk, -AES_parmBlk_addspace);       // Additional space for keylen, etc..
-      __ resize_frame_absolute(parmBlk, keylen, true); // Resize frame with parmBlk being the new SP.
-      __ z_aghi(parmBlk, AES_parmBlk_addspace);        // Restore parameter block address.
-
-      __ z_mvc(0,      cv_len-1,  parmBlk, 0, cv);     // Copy cv.
-      __ z_mvc(cv_len, key_len-1, parmBlk, 0, key);    // Copy key.
-      __ z_lghi(fCode,    VM_Version::Cipher::_AES192 + mode);
-      if (VM_Version::has_Crypto_AES256()) {
+      generate_push_Block(VM_Version::Cipher::_AES192_dataBlk,
+                          VM_Version::Cipher::_AES192_parmBlk_C,
+                          VM_Version::Cipher::_AES192 + mode,
+                          parmBlk, keylen, fCode, cv, key);
+      if (VM_Version::has_Crypto_AES128()) {
         __ z_bru(parmBlk_set);  // Fallthru otherwise.
       }
     }
 
-    if (VM_Version::has_Crypto_AES256()) {
-      __ bind(parmBlk_256);
-      cv_len  = VM_Version::Cipher::_AES256_dataBlk;
-      key_len = VM_Version::Cipher::_AES256_parmBlk_C - cv_len;
-      __ z_lay(parmBlk, -(VM_Version::Cipher::_AES256_parmBlk_C+AES_parmBlk_align)+(AES_parmBlk_align-1), Z_SP);
-      __ z_nill(parmBlk, (~(AES_parmBlk_align-1)) & 0xffff);  // Align parameter block.
-
-      // Resize the frame to accommodate for the aligned parameter block and other stuff.
-      // There is room for stuff in the range [parmBlk-AES_parmBlk_addspace, parmBlk).
-      __ z_stg(keylen, -8, parmBlk);                   // Spill keylen for later use.
-      __ z_stg(Z_SP,  -16, parmBlk);                   // Spill SP for easy revert.
-      __ z_aghi(parmBlk, -AES_parmBlk_addspace);       // Additional space for keylen, etc..
-      __ resize_frame_absolute(parmBlk, keylen, true); // Resize frame with parmBlk being the new SP.
-      __ z_aghi(parmBlk,  AES_parmBlk_addspace);       // Restore parameter block address.
-
-      __ z_mvc(0,      cv_len-1,  parmBlk, 0, cv);     // Copy cv.
-      __ z_mvc(cv_len, key_len-1, parmBlk, 0, key);    // Copy key.
-      __ z_lghi(fCode, VM_Version::Cipher::_AES256 + mode);
-      // __ z_bru(parmBlk_set);  // fallthru
+    if (VM_Version::has_Crypto_AES128()) {
+      __ bind(parmBlk_128);
+      generate_push_Block(VM_Version::Cipher::_AES128_dataBlk,
+                          VM_Version::Cipher::_AES128_parmBlk_C,
+                          VM_Version::Cipher::_AES128 + mode,
+                          parmBlk, keylen, fCode, cv, key);
+      // Fallthru
     }
 
     __ bind(parmBlk_set);
@@ -1871,41 +1880,49 @@
       }
       __ bind(parmBlk_set);
     }
-    __ z_lg(Z_SP, -16, parmBlk); // Revert resize_frame_absolute.
+    __ z_lg(Z_SP, -16, parmBlk); // Revert resize_frame_absolute. Z_SP saved by push_parmBlk.
     BLOCK_COMMENT("} pop parmBlk");
   }
 
+  // Compute AES encrypt/decrypt function.
+  void generate_AES_cipherBlock(bool is_decipher) {
+    // Incoming arguments.
+    Register       from    = Z_ARG1; // source byte array
+    Register       to      = Z_ARG2; // destination byte array
+    Register       key     = Z_ARG3; // expanded key array
+
+    const Register keylen  = Z_R0;   // Temporarily (until fCode is set) holds the expanded key array length.
+
+    // Register definitions as required by KM instruction.
+    const Register fCode   = Z_R0;   // crypto function code
+    const Register parmBlk = Z_R1;   // parameter block address (points to crypto key)
+    const Register src     = Z_ARG1; // Must be even reg (KM requirement).
+    const Register srclen  = Z_ARG2; // Must be odd reg and pair with src. Overwrites destination address.
+    const Register dst     = Z_ARG3; // Must be even reg (KM requirement). Overwrites expanded key address.
+
+    // Read key len of expanded key (in 4-byte words).
+    __ z_lgf(keylen, Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT)));
+
+    // Copy arguments to registers as required by crypto instruction.
+    __ z_lgr(parmBlk, key);          // crypto key (in T_INT array).
+    __ lgr_if_needed(src, from);     // Copy src address. Will not emit, src/from are identical.
+    __ z_lgr(dst, to);               // Copy dst address, even register required.
+
+    // Construct function code into fCode(Z_R0), data block length into srclen(Z_ARG2).
+    generate_load_AES_fCode(keylen, fCode, srclen, is_decipher);
+
+    __ km(dst, src);                 // Cipher the message.
+
+    __ z_br(Z_R14);
+  }
+
   // Compute AES encrypt function.
   address generate_AES_encryptBlock(const char* name) {
     __ align(CodeEntryAlignment);
     StubCodeMark mark(this, "StubRoutines", name);
-    unsigned int   start_off = __ offset();  // Remember stub start address (is rtn value).
-
-    Register       from    = Z_ARG1; // source byte array
-    Register       to      = Z_ARG2; // destination byte array
-    Register       key     = Z_ARG3; // expanded key array
-
-    const Register keylen  = Z_R0;   // Temporarily (until fCode is set) holds the expanded key array length.
-    const Register fCode   = Z_R0;   // crypto function code
-    const Register parmBlk = Z_R1;   // parameter block address (points to crypto key)
-    const Register src     = Z_ARG1; // is Z_R2
-    const Register srclen  = Z_ARG2; // Overwrites destination address.
-    const Register dst     = Z_ARG3; // Overwrites expanded key address.
-
-    // Read key len of expanded key (in 4-byte words).
-    __ z_lgf(keylen, Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT)));
-
-    // Copy arguments to registers as required by crypto instruction.
-    __ z_lgr(parmBlk, key);          // crypto key (in T_INT array).
-    // __ z_lgr(src, from);          // Copy not needed, src/from are identical.
-    __ z_lgr(dst, to);               // Copy destination address to even register.
-
-    // Construct function code in Z_R0, data block length in Z_ARG2.
-    generate_load_AES_fCode(keylen, fCode, srclen, false);
-
-    __ km(dst, src);          // Cipher the message.
-
-    __ z_br(Z_R14);
+    unsigned int start_off = __ offset();  // Remember stub start address (is rtn value).
+
+    generate_AES_cipherBlock(false);
 
     return __ addr_at(start_off);
   }
@@ -1914,33 +1931,9 @@
   address generate_AES_decryptBlock(const char* name) {
     __ align(CodeEntryAlignment);
     StubCodeMark mark(this, "StubRoutines", name);
-    unsigned int   start_off = __ offset();  // Remember stub start address (is rtn value).
-
-    Register       from    = Z_ARG1; // source byte array
-    Register       to      = Z_ARG2; // destination byte array
-    Register       key     = Z_ARG3; // expanded key array, not preset at entry!!!
-
-    const Register keylen  = Z_R0;   // Temporarily (until fCode is set) holds the expanded key array length.
-    const Register fCode   = Z_R0;   // crypto function code
-    const Register parmBlk = Z_R1;   // parameter block address (points to crypto key)
-    const Register src     = Z_ARG1; // is Z_R2
-    const Register srclen  = Z_ARG2; // Overwrites destination address.
-    const Register dst     = Z_ARG3; // Overwrites key address.
-
-    // Read key len of expanded key (in 4-byte words).
-    __ z_lgf(keylen, Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT)));
-
-    // Copy arguments to registers as required by crypto instruction.
-    __ z_lgr(parmBlk, key);     // Copy crypto key address.
-    // __ z_lgr(src, from);     // Copy not needed, src/from are identical.
-    __ z_lgr(dst, to);          // Copy destination address to even register.
-
-    // Construct function code in Z_R0, data block length in Z_ARG2.
-    generate_load_AES_fCode(keylen, fCode, srclen, true);
-
-    __ km(dst, src);          // Cipher the message.
-
-    __ z_br(Z_R14);
+    unsigned int start_off = __ offset();  // Remember stub start address (is rtn value).
+
+    generate_AES_cipherBlock(true);
 
     return __ addr_at(start_off);
   }
@@ -1958,10 +1951,7 @@
   // We align the parameter block to the next available octoword.
   //
   // Compute chained AES encrypt function.
-  address generate_cipherBlockChaining_AES_encrypt(const char* name) {
-    __ align(CodeEntryAlignment);
-    StubCodeMark mark(this, "StubRoutines", name);
-    unsigned int   start_off = __ offset();  // Remember stub start address (is rtn value).
+  void generate_AES_cipherBlockChaining(bool is_decipher) {
 
     Register       from    = Z_ARG1; // source byte array (clear text)
     Register       to      = Z_ARG2; // destination byte array (ciphered)
@@ -1981,20 +1971,29 @@
     __ z_lgf(keylen, Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT)));
 
     // Construct parm block address in parmBlk (== Z_R1), copy cv and key to parm block.
-    // Construct function code in Z_R0.
-    generate_push_parmBlk(keylen, fCode, parmBlk, key, cv, false);
+    // Construct function code in fCode (Z_R0).
+    generate_push_parmBlk(keylen, fCode, parmBlk, key, cv, is_decipher);
 
     // Prepare other registers for instruction.
-    // __ z_lgr(src, from);     // Not needed, registers are the same.
+    __ lgr_if_needed(src, from);     // Copy src address. Will not emit, src/from are identical.
     __ z_lgr(dst, to);
-    __ z_llgfr(srclen, msglen); // We pass the offsets as ints, not as longs as required.
-
-    __ kmc(dst, src);           // Cipher the message.
+    __ z_llgfr(srclen, msglen);      // We pass the offsets as ints, not as longs as required.
+
+    __ kmc(dst, src);                // Cipher the message.
 
     generate_pop_parmBlk(keylen, parmBlk, key, cv);
 
-    __ z_llgfr(Z_RET, msglen);  // We pass the offsets as ints, not as longs as required.
+    __ z_llgfr(Z_RET, msglen);       // We pass the offsets as ints, not as longs as required.
     __ z_br(Z_R14);
+  }
+
+  // Compute chained AES encrypt function.
+  address generate_cipherBlockChaining_AES_encrypt(const char* name) {
+    __ align(CodeEntryAlignment);
+    StubCodeMark mark(this, "StubRoutines", name);
+    unsigned int   start_off = __ offset();  // Remember stub start address (is rtn value).
+
+    generate_AES_cipherBlockChaining(false);
 
     return __ addr_at(start_off);
   }
@@ -2005,38 +2004,7 @@
     StubCodeMark mark(this, "StubRoutines", name);
     unsigned int   start_off = __ offset();  // Remember stub start address (is rtn value).
 
-    Register       from    = Z_ARG1; // source byte array (ciphered)
-    Register       to      = Z_ARG2; // destination byte array (clear text)
-    Register       key     = Z_ARG3; // expanded key array, not preset at entry!!!
-    Register       cv      = Z_ARG4; // chaining value
-    const Register msglen  = Z_ARG5; // Total length of the msg to be encrypted. Value must be returned
-                                     // in Z_RET upon completion of this stub.
-
-    const Register keylen  = Z_R0;   // Expanded key length, as read from key array. Temp only.
-    const Register fCode   = Z_R0;   // crypto function code
-    const Register parmBlk = Z_R1;   // parameter block address (points to crypto key)
-    const Register src     = Z_ARG1; // is Z_R2
-    const Register srclen  = Z_ARG2; // Overwrites destination address.
-    const Register dst     = Z_ARG3; // Overwrites key address.
-
-    // Read key len of expanded key (in 4-byte words).
-    __ z_lgf(keylen, Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT)));
-
-    // Construct parm block address in parmBlk (== Z_R1), copy cv and key to parm block.
-    // Construct function code in Z_R0.
-    generate_push_parmBlk(keylen, fCode, parmBlk, key, cv, true);
-
-    // Prepare other registers for instruction.
-    // __ z_lgr(src, from);     // Not needed, registers are the same.
-    __ z_lgr(dst, to);
-    __ z_llgfr(srclen, msglen); // We pass the offsets as ints, not as longs as required.
-
-    __ kmc(dst, src);           // Decipher the message.
-
-    generate_pop_parmBlk(keylen, parmBlk, key, cv);
-
-    __ z_llgfr(Z_RET, msglen);  // We pass the offsets as ints, not as longs as required.
-    __ z_br(Z_R14);
+    generate_AES_cipherBlockChaining(true);
 
     return __ addr_at(start_off);
   }
--- a/src/cpu/s390/vm/vm_version_s390.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/s390/vm/vm_version_s390.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2016 SAP SE. All rights reserved.
+ * Copyright (c) 2016, 2017 SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -153,6 +153,10 @@
     warning("AES intrinsics are not available on this CPU");
     FLAG_SET_DEFAULT(UseAESIntrinsics, false);
   }
+  if (UseAESIntrinsics && !UseAES) {
+    warning("AES intrinsics require UseAES flag to be enabled. Intrinsics will be disabled.");
+    FLAG_SET_DEFAULT(UseAESIntrinsics, false);
+  }
 
   // TODO: implement AES/CTR intrinsics
   if (UseAESCTRIntrinsics) {
--- a/src/cpu/sparc/vm/c2_globals_sparc.hpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/sparc/vm/c2_globals_sparc.hpp	Wed Sep 20 23:55:35 2017 -0400
@@ -53,7 +53,6 @@
 define_pd_global(bool, ResizeTLAB,                   true);
 define_pd_global(intx, LoopUnrollLimit,              60); // Design center runs on 1.3.1
 define_pd_global(intx, LoopPercentProfileLimit,      10);
-define_pd_global(intx, PostLoopMultiversioning,      false);
 define_pd_global(intx, MinJumpTableSize,             5);
 
 // Peephole and CISC spilling both break the graph, and so makes the
--- a/src/cpu/sparc/vm/interp_masm_sparc.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/sparc/vm/interp_masm_sparc.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -730,8 +730,7 @@
   // load pointer for resolved_references[] objArray
   ld_ptr(result, ConstantPool::cache_offset_in_bytes(), result);
   ld_ptr(result, ConstantPoolCache::resolved_references_offset_in_bytes(), result);
-  // JNIHandles::resolve(result)
-  ld_ptr(result, 0, result);
+  resolve_oop_handle(result);
   // Add in the index
   add(result, tmp, result);
   load_heap_oop(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT), result);
--- a/src/cpu/sparc/vm/macroAssembler_sparc.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/sparc/vm/macroAssembler_sparc.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -3822,6 +3822,12 @@
   card_table_write(bs->byte_map_base, tmp, store_addr);
 }
 
+// ((OopHandle)result).resolve();
+void MacroAssembler::resolve_oop_handle(Register result) {
+  // OopHandle::resolve is an indirection.
+  ld_ptr(result, 0, result);
+}
+
 void MacroAssembler::load_mirror(Register mirror, Register method) {
   const int mirror_offset = in_bytes(Klass::java_mirror_offset());
   ld_ptr(method, in_bytes(Method::const_offset()), mirror);
--- a/src/cpu/sparc/vm/macroAssembler_sparc.hpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/sparc/vm/macroAssembler_sparc.hpp	Wed Sep 20 23:55:35 2017 -0400
@@ -995,6 +995,7 @@
   inline void ldbool(const Address& a, Register d);
   inline void movbool( bool boolconst, Register d);
 
+  void resolve_oop_handle(Register result);
   void load_mirror(Register mirror, Register method);
 
   // klass oop manipulations if compressed
--- a/src/cpu/sparc/vm/methodHandles_sparc.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/sparc/vm/methodHandles_sparc.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -562,7 +562,7 @@
     // Note: the unextended_sp may not be correct
     tty->print_cr("  stack layout:");
     values.print(p);
-    if (has_mh && mh->is_oop()) {
+    if (has_mh && oopDesc::is_oop(mh)) {
       mh->print();
       if (java_lang_invoke_MethodHandle::is_instance(mh)) {
         if (java_lang_invoke_MethodHandle::form_offset_in_bytes() != 0)
--- a/src/cpu/sparc/vm/sparc.ad	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/sparc/vm/sparc.ad	Wed Sep 20 23:55:35 2017 -0400
@@ -3182,6 +3182,16 @@
   interface(CONST_INTER);
 %}
 
+// Unsigned Long Immediate: 12-bit (non-negative that fits in simm13)
+operand immUL12() %{
+  predicate((0 <= n->get_long()) && (n->get_long() == (int)n->get_long()) && Assembler::is_simm13((int)n->get_long()));
+  match(ConL);
+  op_cost(0);
+
+  format %{ %}
+  interface(CONST_INTER);
+%}
+
 // Integer Immediate non-negative
 operand immU31()
 %{
@@ -3709,6 +3719,15 @@
   interface(REG_INTER);
 %}
 
+// Condition Code Register, unsigned long comparisons.
+operand flagsRegUL() %{
+  constraint(ALLOC_IN_RC(int_flags));
+  match(RegFlags);
+
+  format %{ "xcc_UL" %}
+  interface(REG_INTER);
+%}
+
 // Condition Code Register, floating comparisons, unordered same as "less".
 operand flagsRegF() %{
   constraint(ALLOC_IN_RC(float_flags));
@@ -8416,6 +8435,17 @@
   ins_pipe(ialu_cconly_reg_reg);
 %}
 
+instruct compUL_iReg(flagsRegUL xcc, iRegL op1, iRegL op2) %{
+  match(Set xcc (CmpUL op1 op2));
+  effect(DEF xcc, USE op1, USE op2);
+
+  size(4);
+  format %{ "CMP    $op1,$op2\t! unsigned long" %}
+  opcode(Assembler::subcc_op3, Assembler::arith_op);
+  ins_encode(form3_rs1_rs2_rd(op1, op2, R_G0));
+  ins_pipe(ialu_cconly_reg_reg);
+%}
+
 instruct compI_iReg_imm13(flagsReg icc, iRegI op1, immI13 op2) %{
   match(Set icc (CmpI op1 op2));
   effect( DEF icc, USE op1 );
@@ -8502,6 +8532,17 @@
   ins_pipe(ialu_cconly_reg_imm);
 %}
 
+instruct compUL_iReg_imm13(flagsRegUL xcc, iRegL op1, immUL12 op2) %{
+  match(Set xcc (CmpUL op1 op2));
+  effect(DEF xcc, USE op1, USE op2);
+
+  size(4);
+  format %{ "CMP    $op1,$op2\t! unsigned long" %}
+  opcode(Assembler::subcc_op3, Assembler::arith_op);
+  ins_encode(form3_rs1_simm13_rd(op1, op2, R_G0));
+  ins_pipe(ialu_cconly_reg_imm);
+%}
+
 // Compare Pointers
 instruct compP_iRegP(flagsRegP pcc, iRegP op1, iRegP op2 ) %{
   match(Set pcc (CmpP op1 op2));
@@ -8875,6 +8916,44 @@
   ins_pipe(cmp_br_reg_imm);
 %}
 
+instruct cmpUL_reg_branch(cmpOpU cmp, iRegL op1, iRegL op2, label labl, flagsRegUL xcc) %{
+  match(If cmp (CmpUL op1 op2));
+  effect(USE labl, KILL xcc);
+
+  size(12);
+  ins_cost(BRANCH_COST);
+  format %{ "CMP    $op1,$op2\t! unsigned long\n\t"
+            "BP$cmp   $labl" %}
+  ins_encode %{
+    Label* L = $labl$$label;
+    Assembler::Predict predict_taken =
+      cbuf.is_backward_branch(*L) ? Assembler::pt : Assembler::pn;
+    __ cmp($op1$$Register, $op2$$Register);
+    __ bp((Assembler::Condition)($cmp$$cmpcode), false, Assembler::xcc, predict_taken, *L);
+    __ delayed()->nop();
+  %}
+  ins_pipe(cmp_br_reg_reg);
+%}
+
+instruct cmpUL_imm_branch(cmpOpU cmp, iRegL op1, immL5 op2, label labl, flagsRegUL xcc) %{
+  match(If cmp (CmpUL op1 op2));
+  effect(USE labl, KILL xcc);
+
+  size(12);
+  ins_cost(BRANCH_COST);
+  format %{ "CMP    $op1,$op2\t! unsigned long\n\t"
+            "BP$cmp   $labl" %}
+  ins_encode %{
+    Label* L = $labl$$label;
+    Assembler::Predict predict_taken =
+      cbuf.is_backward_branch(*L) ? Assembler::pt : Assembler::pn;
+    __ cmp($op1$$Register, $op2$$constant);
+    __ bp((Assembler::Condition)($cmp$$cmpcode), false, Assembler::xcc, predict_taken, *L);
+    __ delayed()->nop();
+  %}
+  ins_pipe(cmp_br_reg_imm);
+%}
+
 instruct cmpL_reg_branch(cmpOp cmp, iRegL op1, iRegL op2, label labl, flagsRegL xcc) %{
   match(If cmp (CmpL op1 op2));
   effect(USE labl, KILL xcc);
@@ -9103,6 +9182,42 @@
   ins_pipe(cbcond_reg_imm);
 %}
 
+instruct cmpUL_reg_branch_short(cmpOpU cmp, iRegL op1, iRegL op2, label labl, flagsRegUL xcc) %{
+  match(If cmp (CmpUL op1 op2));
+  predicate(UseCBCond);
+  effect(USE labl, KILL xcc);
+
+  size(4);
+  ins_cost(BRANCH_COST);
+  format %{ "CXB$cmp  $op1,$op2,$labl\t! unsigned long" %}
+  ins_encode %{
+    Label* L = $labl$$label;
+    assert(__ use_cbcond(*L), "back to back cbcond");
+    __ cbcond((Assembler::Condition)($cmp$$cmpcode), Assembler::xcc, $op1$$Register, $op2$$Register, *L);
+  %}
+  ins_short_branch(1);
+  ins_avoid_back_to_back(AVOID_BEFORE_AND_AFTER);
+  ins_pipe(cbcond_reg_reg);
+%}
+
+instruct cmpUL_imm_branch_short(cmpOpU cmp, iRegL op1, immL5 op2, label labl, flagsRegUL xcc) %{
+  match(If cmp (CmpUL op1 op2));
+  predicate(UseCBCond);
+  effect(USE labl, KILL xcc);
+
+  size(4);
+  ins_cost(BRANCH_COST);
+  format %{ "CXB$cmp  $op1,$op2,$labl\t! unsigned long" %}
+  ins_encode %{
+    Label* L = $labl$$label;
+    assert(__ use_cbcond(*L), "back to back cbcond");
+    __ cbcond((Assembler::Condition)($cmp$$cmpcode), Assembler::xcc, $op1$$Register, $op2$$constant, *L);
+  %}
+  ins_short_branch(1);
+  ins_avoid_back_to_back(AVOID_BEFORE_AND_AFTER);
+  ins_pipe(cbcond_reg_imm);
+%}
+
 instruct cmpL_reg_branch_short(cmpOp cmp, iRegL op1, iRegL op2, label labl, flagsRegL xcc) %{
   match(If cmp (CmpL op1 op2));
   predicate(UseCBCond);
@@ -9333,6 +9448,25 @@
   ins_pipe(br_cc);
 %}
 
+instruct branchConU_long(cmpOpU cmp, flagsRegUL xcc, label labl) %{
+  match(If cmp xcc);
+  effect(USE labl);
+
+  size(8);
+  ins_cost(BRANCH_COST);
+  format %{ "BP$cmp   $xcc,$labl" %}
+  ins_encode %{
+    Label* L = $labl$$label;
+    Assembler::Predict predict_taken =
+      cbuf.is_backward_branch(*L) ? Assembler::pt : Assembler::pn;
+
+    __ bp((Assembler::Condition)($cmp$$cmpcode), false, Assembler::xcc, predict_taken, *L);
+    __ delayed()->nop();
+  %}
+  ins_avoid_back_to_back(AVOID_BEFORE);
+  ins_pipe(br_cc);
+%}
+
 // Manifest a CmpL3 result in an integer register.  Very painful.
 // This is the test to avoid.
 instruct cmpL3_reg_reg(iRegI dst, iRegL src1, iRegL src2, flagsReg ccr ) %{
--- a/src/cpu/x86/vm/c2_globals_x86.hpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/x86/vm/c2_globals_x86.hpp	Wed Sep 20 23:55:35 2017 -0400
@@ -47,7 +47,6 @@
 define_pd_global(intx, FreqInlineSize,               325);
 define_pd_global(intx, MinJumpTableSize,             10);
 define_pd_global(intx, LoopPercentProfileLimit,      30);
-define_pd_global(intx, PostLoopMultiversioning,      true);
 #ifdef AMD64
 define_pd_global(intx, INTPRESSURE,                  13);
 define_pd_global(intx, FLOATPRESSURE,                14);
--- a/src/cpu/x86/vm/globals_x86.hpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/x86/vm/globals_x86.hpp	Wed Sep 20 23:55:35 2017 -0400
@@ -116,7 +116,7 @@
   product(bool, UseStoreImmI16, true,                                       \
           "Use store immediate 16-bits value instruction on x86")           \
                                                                             \
-  product(intx, UseAVX, 99,                                                 \
+  product(intx, UseAVX, 3,                                                  \
           "Highest supported AVX instructions set on x86/x64")              \
           range(0, 99)                                                      \
                                                                             \
--- a/src/cpu/x86/vm/interp_masm_x86.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/x86/vm/interp_masm_x86.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -511,8 +511,7 @@
   // load pointer for resolved_references[] objArray
   movptr(result, Address(result, ConstantPool::cache_offset_in_bytes()));
   movptr(result, Address(result, ConstantPoolCache::resolved_references_offset_in_bytes()));
-  // JNIHandles::resolve(obj);
-  movptr(result, Address(result, 0));
+  resolve_oop_handle(result);
   // Add in the index
   addptr(result, tmp);
   load_heap_oop(result, Address(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
@@ -1089,7 +1088,6 @@
 
     call_VM_leaf(
       CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), rthread);
-    push(rthread);
     call_VM(noreg, CAST_FROM_FN_PTR(address,
                    InterpreterRuntime::throw_delayed_StackOverflowError));
     should_not_reach_here();
--- a/src/cpu/x86/vm/macroAssembler_x86.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/x86/vm/macroAssembler_x86.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -6604,6 +6604,12 @@
 #endif // _LP64
 }
 
+// ((OopHandle)result).resolve();
+void MacroAssembler::resolve_oop_handle(Register result) {
+  // OopHandle::resolve is an indirection.
+  movptr(result, Address(result, 0));
+}
+
 void MacroAssembler::load_mirror(Register mirror, Register method) {
   // get mirror
   const int mirror_offset = in_bytes(Klass::java_mirror_offset());
@@ -7030,7 +7036,6 @@
 
 #endif // _LP64
 
-
 // C2 compiled method's prolog code.
 void MacroAssembler::verified_entry(int framesize, int stack_bang_size, bool fp_mode_24b) {
 
--- a/src/cpu/x86/vm/macroAssembler_x86.hpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/x86/vm/macroAssembler_x86.hpp	Wed Sep 20 23:55:35 2017 -0400
@@ -327,6 +327,7 @@
   void movbool(Address dst, Register src);
   void testbool(Register dst);
 
+  void resolve_oop_handle(Register result);
   void load_mirror(Register mirror, Register method);
 
   // oop manipulations
--- a/src/cpu/x86/vm/methodHandles_x86.cpp	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/x86/vm/methodHandles_x86.cpp	Wed Sep 20 23:55:35 2017 -0400
@@ -561,7 +561,7 @@
       tty->print_cr("Stack layout:");
       values.print(p);
     }
-    if (has_mh && mh->is_oop()) {
+    if (has_mh && oopDesc::is_oop(mh)) {
       mh->print();
       if (java_lang_invoke_MethodHandle::is_instance(mh)) {
         if (java_lang_invoke_MethodHandle::form_offset_in_bytes() != 0)
--- a/src/cpu/x86/vm/x86_32.ad	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/x86/vm/x86_32.ad	Wed Sep 20 23:55:35 2017 -0400
@@ -1,5 +1,5 @@
 //
-// Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+// Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
 // DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 //
 // This code is free software; you can redistribute it and/or modify it
@@ -391,7 +391,7 @@
         int format) {
 #ifdef ASSERT
   if (rspec.reloc()->type() == relocInfo::oop_type && d32 != 0 && d32 != (int)Universe::non_oop_word()) {
-    assert(cast_to_oop(d32)->is_oop() && (ScavengeRootsInCode || !cast_to_oop(d32)->is_scavengable()), "cannot embed scavengable oops in code");
+    assert(oopDesc::is_oop(cast_to_oop(d32)) && (ScavengeRootsInCode || !cast_to_oop(d32)->is_scavengable()), "cannot embed scavengable oops in code");
   }
 #endif
   cbuf.relocate(cbuf.insts_mark(), rspec, format);
@@ -4027,6 +4027,26 @@
   interface(REG_INTER);
 %}
 
+// Condition Code Register used by unsigned long compare
+operand flagsReg_ulong_LTGE() %{
+  constraint(ALLOC_IN_RC(int_flags));
+  match(RegFlags);
+  format %{ "FLAGS_U_LTGE" %}
+  interface(REG_INTER);
+%}
+operand flagsReg_ulong_EQNE() %{
+  constraint(ALLOC_IN_RC(int_flags));
+  match(RegFlags);
+  format %{ "FLAGS_U_EQNE" %}
+  interface(REG_INTER);
+%}
+operand flagsReg_ulong_LEGT() %{
+  constraint(ALLOC_IN_RC(int_flags));
+  match(RegFlags);
+  format %{ "FLAGS_U_LEGT" %}
+  interface(REG_INTER);
+%}
+
 // Float register operands
 operand regDPR() %{
   predicate( UseSSE < 2 );
@@ -4585,7 +4605,7 @@
   %}
 %}
 
-// Comparision Code used in long compares
+// Comparison Code used in long compares
 operand cmpOp_commute() %{
   match(Bool);
 
@@ -4602,6 +4622,23 @@
   %}
 %}
 
+// Comparison Code used in unsigned long compares
+operand cmpOpU_commute() %{
+  match(Bool);
+
+  format %{ "" %}
+  interface(COND_INTER) %{
+    equal(0x4, "e");
+    not_equal(0x5, "ne");
+    less(0x7, "nbe");
+    greater_equal(0x6, "be");
+    less_equal(0x3, "nb");
+    greater(0x2, "b");
+    overflow(0x0, "o");
+    no_overflow(0x1, "no");
+  %}
+%}
+
 //----------OPERAND CLASSES----------------------------------------------------
 // Operand Classes are groups of operands that are used as to simplify
 // instruction definitions by not requiring the AD writer to specify separate
@@ -12636,6 +12673,44 @@
   %}
 %}
 
+//======
+// Manifest a CmpUL result in the normal flags.  Only good for LT or GE
+// compares.  Can be used for LE or GT compares by reversing arguments.
+// NOT GOOD FOR EQ/NE tests.
+instruct cmpUL_zero_flags_LTGE(flagsReg_ulong_LTGE flags, eRegL src, immL0 zero) %{
+  match(Set flags (CmpUL src zero));
+  ins_cost(100);
+  format %{ "TEST   $src.hi,$src.hi" %}
+  opcode(0x85);
+  ins_encode(OpcP, RegReg_Hi2(src, src));
+  ins_pipe(ialu_cr_reg_reg);
+%}
+
+// Manifest a CmpUL result in the normal flags.  Only good for LT or GE
+// compares.  Can be used for LE or GT compares by reversing arguments.
+// NOT GOOD FOR EQ/NE tests.
+instruct cmpUL_reg_flags_LTGE(flagsReg_ulong_LTGE flags, eRegL src1, eRegL src2, rRegI tmp) %{
+  match(Set flags (CmpUL src1 src2));
+  effect(TEMP tmp);
+  ins_cost(300);
+  format %{ "CMP    $src1.lo,$src2.lo\t! Unsigned long compare; set flags for low bits\n\t"
+            "MOV    $tmp,$src1.hi\n\t"
+            "SBB    $tmp,$src2.hi\t! Compute flags for unsigned long compare" %}
+  ins_encode(long_cmp_flags2(src1, src2, tmp));
+  ins_pipe(ialu_cr_reg_reg);
+%}
+
+// Unsigned long compares reg < zero/req OR reg >= zero/req.
+// Just a wrapper for a normal branch, plus the predicate test.
+instruct cmpUL_LTGE(cmpOpU cmp, flagsReg_ulong_LTGE flags, label labl) %{
+  match(If cmp flags);
+  effect(USE labl);
+  predicate(_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::lt || _kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ge);
+  expand %{
+    jmpCon(cmp, flags, labl);    // JLT or JGE...
+  %}
+%}
+
 // Compare 2 longs and CMOVE longs.
 instruct cmovLL_reg_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, eRegL dst, eRegL src) %{
   match(Set dst (CMoveL (Binary cmp flags) (Binary dst src)));
@@ -12764,6 +12839,41 @@
   %}
 %}
 
+//======
+// Manifest a CmpUL result in the normal flags.  Only good for EQ/NE compares.
+instruct cmpUL_zero_flags_EQNE(flagsReg_ulong_EQNE flags, eRegL src, immL0 zero, rRegI tmp) %{
+  match(Set flags (CmpUL src zero));
+  effect(TEMP tmp);
+  ins_cost(200);
+  format %{ "MOV    $tmp,$src.lo\n\t"
+            "OR     $tmp,$src.hi\t! Unsigned long is EQ/NE 0?" %}
+  ins_encode(long_cmp_flags0(src, tmp));
+  ins_pipe(ialu_reg_reg_long);
+%}
+
+// Manifest a CmpUL result in the normal flags.  Only good for EQ/NE compares.
+instruct cmpUL_reg_flags_EQNE(flagsReg_ulong_EQNE flags, eRegL src1, eRegL src2) %{
+  match(Set flags (CmpUL src1 src2));
+  ins_cost(200+300);
+  format %{ "CMP    $src1.lo,$src2.lo\t! Unsigned long compare; set flags for low bits\n\t"
+            "JNE,s  skip\n\t"
+            "CMP    $src1.hi,$src2.hi\n\t"
+     "skip:\t" %}
+  ins_encode(long_cmp_flags1(src1, src2));
+  ins_pipe(ialu_cr_reg_reg);
+%}
+
+// Unsigned long compare reg == zero/reg OR reg != zero/reg
+// Just a wrapper for a normal branch, plus the predicate test.
+instruct cmpUL_EQNE(cmpOpU cmp, flagsReg_ulong_EQNE flags, label labl) %{
+  match(If cmp flags);
+  effect(USE labl);
+  predicate(_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::eq || _kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ne);
+  expand %{
+    jmpCon(cmp, flags, labl);    // JEQ or JNE...
+  %}
+%}
+
 // Compare 2 longs and CMOVE longs.
 instruct cmovLL_reg_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, eRegL dst, eRegL src) %{
   match(Set dst (CMoveL (Binary cmp flags) (Binary dst src)));
@@ -12897,6 +13007,46 @@
   %}
 %}
 
+//======
+// Manifest a CmpUL result in the normal flags.  Only good for LE or GT compares.
+// Same as cmpUL_reg_flags_LEGT except must negate src
+instruct cmpUL_zero_flags_LEGT(flagsReg_ulong_LEGT flags, eRegL src, immL0 zero, rRegI tmp) %{
+  match(Set flags (CmpUL src zero));
+  effect(TEMP tmp);
+  ins_cost(300);
+  format %{ "XOR    $tmp,$tmp\t# Unsigned long compare for -$src < 0, use commuted test\n\t"
+            "CMP    $tmp,$src.lo\n\t"
+            "SBB    $tmp,$src.hi\n\t" %}
+  ins_encode(long_cmp_flags3(src, tmp));
+  ins_pipe(ialu_reg_reg_long);
+%}
+
+// Manifest a CmpUL result in the normal flags.  Only good for LE or GT compares.
+// Same as cmpUL_reg_flags_LTGE except operands swapped.  Swapping operands
+// requires a commuted test to get the same result.
+instruct cmpUL_reg_flags_LEGT(flagsReg_ulong_LEGT flags, eRegL src1, eRegL src2, rRegI tmp) %{
+  match(Set flags (CmpUL src1 src2));
+  effect(TEMP tmp);
+  ins_cost(300);
+  format %{ "CMP    $src2.lo,$src1.lo\t! Unsigned long compare, swapped operands, use with commuted test\n\t"
+            "MOV    $tmp,$src2.hi\n\t"
+            "SBB    $tmp,$src1.hi\t! Compute flags for unsigned long compare" %}
+  ins_encode(long_cmp_flags2( src2, src1, tmp));
+  ins_pipe(ialu_cr_reg_reg);
+%}
+
+// Unsigned long compares reg < zero/req OR reg >= zero/req.
+// Just a wrapper for a normal branch, plus the predicate test
+instruct cmpUL_LEGT(cmpOpU_commute cmp, flagsReg_ulong_LEGT flags, label labl) %{
+  match(If cmp flags);
+  effect(USE labl);
+  predicate(_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::gt || _kids[0]->_leaf->as_Bool()->_test._test == BoolTest::le);
+  ins_cost(300);
+  expand %{
+    jmpCon(cmp, flags, labl);    // JGT or JLE...
+  %}
+%}
+
 // Compare 2 longs and CMOVE longs.
 instruct cmovLL_reg_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, eRegL dst, eRegL src) %{
   match(Set dst (CMoveL (Binary cmp flags) (Binary dst src)));
--- a/src/cpu/x86/vm/x86_64.ad	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/cpu/x86/vm/x86_64.ad	Wed Sep 20 23:55:35 2017 -0400
@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+// Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
 // DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 //
 // This code is free software; you can redistribute it and/or modify it
@@ -653,7 +653,7 @@
   if (rspec.reloc()->type() == relocInfo::oop_type &&
       d32 != 0 && d32 != (intptr_t) Universe::non_oop_word()) {
     assert(Universe::heap()->is_in_reserved((address)(intptr_t)d32), "should be real oop");
-    assert(cast_to_oop((intptr_t)d32)->is_oop() && (ScavengeRootsInCode || !cast_to_oop((intptr_t)d32)->is_scavengable()), "cannot embed scavengable oops in code");
+    assert(oopDesc::is_oop(cast_to_oop((intptr_t)d32)) && (ScavengeRootsInCode || !cast_to_oop((intptr_t)d32)->is_scavengable()), "cannot embed scavengable oops in code");
   }
 #endif
   cbuf.relocate(cbuf.insts_mark(), rspec, format);
@@ -680,7 +680,7 @@
   if (rspec.reloc()->type() == relocInfo::oop_type &&
       d64 != 0 && d64 != (int64_t) Universe::non_oop_word()) {
     assert(Universe::heap()->is_in_reserved((address)d64), "should be real oop");
-    assert(cast_to_oop(d64)->is_oop() && (ScavengeRootsInCode || !cast_to_oop(d64)->is_scavengable()),
+    assert(oopDesc::is_oop(cast_to_oop(d64)) && (ScavengeRootsInCode || !cast_to_oop(d64)->is_scavengable()),
            "cannot embed scavengable oops in code");
   }
 #endif
@@ -11515,6 +11515,48 @@
   ins_pipe(pipe_slow);
 %}
 
+// Unsigned long compare Instructions; really, same as signed long except they
+// produce an rFlagsRegU instead of rFlagsReg.
+instruct compUL_rReg(rFlagsRegU cr, rRegL op1, rRegL op2)
+%{
+  match(Set cr (CmpUL op1 op2));
+
+  format %{ "cmpq    $op1, $op2\t# unsigned" %}
+  opcode(0x3B);  /* Opcode 3B /r */
+  ins_encode(REX_reg_reg_wide(op1, op2), OpcP, reg_reg(op1, op2));
+  ins_pipe(ialu_cr_reg_reg);
+%}
+
+instruct compUL_rReg_imm(rFlagsRegU cr, rRegL op1, immL32 op2)
+%{
+  match(Set cr (CmpUL op1 op2));
+
+  format %{ "cmpq    $op1, $op2\t# unsigned" %}
+  opcode(0x81, 0x07); /* Opcode 81 /7 */
+  ins_encode(OpcSErm_wide(op1, op2), Con8or32(op2));
+  ins_pipe(ialu_cr_reg_imm);
+%}
+
+instruct compUL_rReg_mem(rFlagsRegU cr, rRegL op1, memory op2)
+%{
+  match(Set cr (CmpUL op1 (LoadL op2)));
+
+  format %{ "cmpq    $op1, $op2\t# unsigned" %}
+  opcode(0x3B); /* Opcode 3B /r */
+  ins_encode(REX_reg_mem_wide(op1, op2), OpcP, reg_mem(op1, op2));
+  ins_pipe(ialu_cr_reg_mem);
+%}
+
+instruct testUL_reg(rFlagsRegU cr, rRegL src, immL0 zero)
+%{
+  match(Set cr (CmpUL src zero));
+
+  format %{ "testq   $src, $src\t# unsigned" %}
+  opcode(0x85);
+  ins_encode(REX_reg_reg_wide(src, src), OpcP, reg_reg(src, src));
+  ins_pipe(ialu_cr_reg_imm);
+%}
+
 //----------Max and Min--------------------------------------------------------
 // Min Instructions
 
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/BinaryContainer.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/BinaryContainer.java	Wed Sep 20 23:55:35 2017 -0400
@@ -58,7 +58,7 @@
  * <p>
  * Methods to record and access code section contents, symbols and relocations are provided.
  */
-public class BinaryContainer implements SymbolTable {
+public final class BinaryContainer implements SymbolTable {
     private final OptionValues graalOptions;
 
     private final int codeSegmentSize;
@@ -71,19 +71,19 @@
     private final CodeContainer codeContainer;
 
     /**
-     * Container holding external hotspot linkage bits (PLT entries).
-     */
-    private final CodeContainer extLinkageContainer;
-
-    /**
      * Container holding global offset data for hotspot linkage.
      */
     private final ByteContainer extLinkageGOTContainer;
 
     /**
-     * Patched by HotSpot, contains metaspace pointers.
+     * Patched by HotSpot, contains Klass pointers.
      */
-    private final ByteContainer metaspaceGotContainer;
+    private final ByteContainer klassesGotContainer;
+
+    /**
+     * Patched by HotSpot, contains MethodCounters pointers.
+     */
+    private final ByteContainer countersGotContainer;
 
     /**
      * Patched lazily by hotspot, contains klass/method pointers.
@@ -268,33 +268,41 @@
         this.graalOptions = graalOptions;
 
         this.codeSegmentSize = graalHotSpotVMConfig.codeSegmentSize;
+        if (codeSegmentSize < 1 || codeSegmentSize > 1024) {
+            throw new InternalError("codeSegmentSize is not in range [1, 1024] bytes: (" + codeSegmentSize + "), update JPECoffRelocObject");
+        }
+        if ((codeSegmentSize & (codeSegmentSize - 1)) != 0) {
+            throw new InternalError("codeSegmentSize is not power of 2: (" + codeSegmentSize + "), update JPECoffRelocObject");
+        }
+
         this.codeEntryAlignment = graalHotSpotVMConfig.codeEntryAlignment;
 
+        // Section unique name is limited to 8 characters due to limitation on Windows.
+        // Name could be longer but only first 8 characters are stored on Windows.
+
         // read only, code
         codeContainer = new CodeContainer(".text", this);
-        extLinkageContainer = new CodeContainer(".hs.plt.linkage", this);
 
         // read only, info
+        headerContainer = new HeaderContainer(jvmVersion, new ReadOnlyDataContainer(".header", this));
         configContainer = new ReadOnlyDataContainer(".config", this);
         metaspaceNamesContainer = new ReadOnlyDataContainer(".meta.names", this);
-        methodsOffsetsContainer = new ReadOnlyDataContainer(".methods.offsets", this);
+        methodsOffsetsContainer = new ReadOnlyDataContainer(".meth.offsets", this);
         klassesOffsetsContainer = new ReadOnlyDataContainer(".kls.offsets", this);
         klassesDependenciesContainer = new ReadOnlyDataContainer(".kls.dependencies", this);
 
-        headerContainer = new HeaderContainer(jvmVersion, new ReadOnlyDataContainer(".header", this));
         stubsOffsetsContainer = new ReadOnlyDataContainer(".stubs.offsets", this);
         codeSegmentsContainer = new ReadOnlyDataContainer(".code.segments", this);
         constantDataContainer = new ReadOnlyDataContainer(".meth.constdata", this);
-
-        // needs relocation patching at load time by the loader
         methodMetadataContainer = new ReadOnlyDataContainer(".meth.metadata", this);
 
         // writable sections
-        metaspaceGotContainer = new ByteContainer(".meta.got", this);
-        metadataGotContainer = new ByteContainer(".metadata.got", this);
+        oopGotContainer = new ByteContainer(".oop.got", this);
+        klassesGotContainer = new ByteContainer(".kls.got", this);
+        countersGotContainer = new ByteContainer(".cnt.got", this);
+        metadataGotContainer = new ByteContainer(".meta.got", this);
         methodStateContainer = new ByteContainer(".meth.state", this);
-        oopGotContainer = new ByteContainer(".oop.got", this);
-        extLinkageGOTContainer = new ByteContainer(".hs.got.linkage", this);
+        extLinkageGOTContainer = new ByteContainer(".got.linkage", this);
 
         addGlobalSymbols();
 
@@ -368,51 +376,51 @@
      * in the named GOT cell.
      */
 
-    public String getCardTableAddressSymbolName() {
+    public static String getCardTableAddressSymbolName() {
         return "_aot_card_table_address";
     }
 
-    public String getHeapTopAddressSymbolName() {
+    public static String getHeapTopAddressSymbolName() {
         return "_aot_heap_top_address";
     }
 
-    public String getHeapEndAddressSymbolName() {
+    public static String getHeapEndAddressSymbolName() {
         return "_aot_heap_end_address";
     }
 
-    public String getCrcTableAddressSymbolName() {
+    public static String getCrcTableAddressSymbolName() {
         return "_aot_stub_routines_crc_table_adr";
     }
 
-    public String getPollingPageSymbolName() {
+    public static String getPollingPageSymbolName() {
         return "_aot_polling_page";
     }
 
-    public String getResolveStaticEntrySymbolName() {
+    public static String getResolveStaticEntrySymbolName() {
         return "_resolve_static_entry";
     }
 
-    public String getResolveVirtualEntrySymbolName() {
+    public static String getResolveVirtualEntrySymbolName() {
         return "_resolve_virtual_entry";
     }
 
-    public String getResolveOptVirtualEntrySymbolName() {
+    public static String getResolveOptVirtualEntrySymbolName() {
         return "_resolve_opt_virtual_entry";
     }
 
-    public String getNarrowKlassBaseAddressSymbolName() {
+    public static String getNarrowKlassBaseAddressSymbolName() {
         return "_aot_narrow_klass_base_address";
     }
 
-    public String getNarrowOopBaseAddressSymbolName() {
+    public static String getNarrowOopBaseAddressSymbolName() {
         return "_aot_narrow_oop_base_address";
     }
 
-    public String getLogOfHeapRegionGrainBytesSymbolName() {
+    public static String getLogOfHeapRegionGrainBytesSymbolName() {
         return "_aot_log_of_heap_region_grain_bytes";
     }
 
-    public String getInlineContiguousAllocationSupportedSymbolName() {
+    public static String getInlineContiguousAllocationSupportedSymbolName() {
         return "_aot_inline_contiguous_allocation_supported";
     }
 
@@ -430,7 +438,7 @@
      * @param functionName function name
      * @return AOT symbol for the given function name, or null if there is no mapping.
      */
-    public String getAOTSymbolForVMFunctionName(String functionName) {
+    public static String getAOTSymbolForVMFunctionName(String functionName) {
         return functionNamesToAOTSymbols.get(functionName);
     }
 
@@ -441,7 +449,8 @@
         createContainerSymbol(methodsOffsetsContainer);
         createContainerSymbol(klassesOffsetsContainer);
         createContainerSymbol(klassesDependenciesContainer);
-        createContainerSymbol(metaspaceGotContainer);
+        createContainerSymbol(klassesGotContainer);
+        createContainerSymbol(countersGotContainer);
         createContainerSymbol(metadataGotContainer);
         createContainerSymbol(methodStateContainer);
         createContainerSymbol(oopGotContainer);
@@ -469,12 +478,13 @@
     }
 
     /**
-     * Creates a global symbol of the form {@code "JVM" + container name}.
+     * Creates a global symbol of the form {@code "A" + container name}.
+     * Note, linker on Windows does not allow names which start with '.'
      *
      * @param container container to create a symbol for
      */
     private static void createContainerSymbol(ByteContainer container) {
-        container.createSymbol(0, Kind.OBJECT, Binding.GLOBAL, 0, "JVM" + container.getContainerName());
+        container.createSymbol(0, Kind.OBJECT, Binding.GLOBAL, 0, "A" + container.getContainerName());
     }
 
     /**
@@ -499,12 +509,12 @@
      *
      * @throws IOException in case of file creation failure
      */
-    public void createBinary(String outputFileName, String aotVersion) throws IOException {
+    public void createBinary(String outputFileName) throws IOException {
         String osName = System.getProperty("os.name");
         switch (osName) {
             case "Linux":
             case "SunOS":
-                JELFRelocObject elfobj = new JELFRelocObject(this, outputFileName, aotVersion);
+                JELFRelocObject elfobj = new JELFRelocObject(this, outputFileName);
                 elfobj.createELFRelocObject(relocationTable, symbolTable.values());
                 break;
             case "Mac OS X":
@@ -513,7 +523,7 @@
                 break;
             default:
                 if (osName.startsWith("Windows")) {
-                    JPECoffRelocObject pecoffobj = new JPECoffRelocObject(this, outputFileName, aotVersion);
+                    JPECoffRelocObject pecoffobj = new JPECoffRelocObject(this, outputFileName);
                     pecoffobj.createPECoffRelocObject(relocationTable, symbolTable.values());
                     break;
                 } else
@@ -626,12 +636,6 @@
         return startOffset;
     }
 
-    public int appendMetaspaceGotBytes(byte[] bytes, int offset, int size) {
-        int startOffset = metaspaceGotContainer.getByteStreamSize();
-        appendBytes(metaspaceGotContainer, bytes, offset, size);
-        return startOffset;
-    }
-
     public void addMetadataGotEntry(int offset) {
         metadataGotContainer.appendLong(offset);
     }
@@ -681,8 +685,7 @@
     }
 
     /**
-     * Add oop symbol by as follows. Extend the oop.got section with another slot for the VM to
-     * patch.
+     * Add oop symbol by as follows. Extend the oop.got section with another slot for the VM to patch.
      *
      * @param oopName name of the oop symbol
      */
@@ -708,13 +711,13 @@
         return relocationSymbol.getOffset();
     }
 
-    public int addMetaspaceSymbol(String metaspaceName) {
+    public int addCountersSymbol(String metaspaceName) {
         String gotName = "got." + metaspaceName;
         Symbol relocationSymbol = getGotSymbol(gotName);
         int metaspaceOffset = -1;
         if (relocationSymbol == null) {
             // Add slots when asked in the .metaspace.got section:
-            metaspaceGotContainer.createGotSymbol(gotName);
+            countersGotContainer.createGotSymbol(gotName);
         }
         return metaspaceOffset;
     }
@@ -725,29 +728,30 @@
     }
 
     /**
-     * Add metaspace symbol by as follows. - Adding the symbol name to the metaspace.names section -
-     * Add the offset of the name in metaspace.names to metaspace.offsets - Extend the metaspace.got
-     * section with another slot for the VM to patch
+     * Add klass symbol by as follows.
+     *   - Adding the symbol name to the metaspace.names section
+     *   - Add the offset of the name in metaspace.names to metaspace.offsets
+     *   - Extend the klasses.got section with another slot for the VM to patch
      *
-     * @param metaspaceName name of the metaspace symbol
-     * @return the got offset in the metaspace.got of the metaspace symbol
+     * @param klassName name of the metaspace symbol
+     * @return the got offset in the klasses.got of the metaspace symbol
      */
-    public int addTwoSlotMetaspaceSymbol(String metaspaceName) {
-        String gotName = "got." + metaspaceName;
+    public int addTwoSlotKlassSymbol(String klassName) {
+        String gotName = "got." + klassName;
         Symbol previous = getGotSymbol(gotName);
-        assert previous == null : "should be called only once for: " + metaspaceName;
+        assert previous == null : "should be called only once for: " + klassName;
         // Add slots when asked in the .metaspace.got section:
         // First slot
-        String gotInitName = "got.init." + metaspaceName;
-        GotSymbol slot1Symbol = metaspaceGotContainer.createGotSymbol(gotInitName);
-        GotSymbol slot2Symbol = metaspaceGotContainer.createGotSymbol(gotName);
+        String gotInitName = "got.init." + klassName;
+        GotSymbol slot1Symbol = klassesGotContainer.createGotSymbol(gotInitName);
+        GotSymbol slot2Symbol = klassesGotContainer.createGotSymbol(gotName);
 
         slot1Symbol.getIndex(); // check alignment and ignore result
         // Get the index (offset/8) to the got in the .metaspace.got section
         return slot2Symbol.getIndex();
     }
 
-    public int addMethodsCount(int count, ReadOnlyDataContainer container) {
+    public static int addMethodsCount(int count, ReadOnlyDataContainer container) {
         return appendInt(count, container);
     }
 
@@ -772,7 +776,7 @@
         return constantDataOffset;
     }
 
-    public int alignUp(ByteContainer container, int alignment) {
+    public static int alignUp(ByteContainer container, int alignment) {
         if (Integer.bitCount(alignment) != 1) {
             throw new IllegalArgumentException("Must be a power of 2");
         }
@@ -814,15 +818,11 @@
         appendBytes(codeSegmentsContainer, segments, 0, segmentsCount);
     }
 
-    public CodeContainer getExtLinkageContainer() {
-        return extLinkageContainer;
-    }
-
     public ByteContainer getExtLinkageGOTContainer() {
         return extLinkageGOTContainer;
     }
 
-    public ByteContainer getMethodMetadataContainer() {
+    public ReadOnlyDataContainer getMethodMetadataContainer() {
         return methodMetadataContainer;
     }
 
@@ -854,8 +854,12 @@
         return constantDataContainer;
     }
 
-    public ByteContainer getMetaspaceGotContainer() {
-        return metaspaceGotContainer;
+    public ByteContainer getKlassesGotContainer() {
+        return klassesGotContainer;
+    }
+
+    public ByteContainer getCountersGotContainer() {
+        return countersGotContainer;
     }
 
     public ByteContainer getMetadataGotContainer() {
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/CodeContainer.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/CodeContainer.java	Wed Sep 20 23:55:35 2017 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,7 @@
 /**
  * A container that holds information about code section. This is simply a ByteContainer.
  */
-public class CodeContainer extends ByteContainer {
+public final class CodeContainer extends ByteContainer {
 
     public CodeContainer(String containerName, SymbolTable symbolTable) {
         super(containerName, symbolTable);
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/Container.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/Container.java	Wed Sep 20 23:55:35 2017 -0400
@@ -23,7 +23,7 @@
 
 package jdk.tools.jaotc.binformat;
 
-public interface Container {
+interface Container {
 
     String getContainerName();
 
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/GotSymbol.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/GotSymbol.java	Wed Sep 20 23:55:35 2017 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 package jdk.tools.jaotc.binformat;
 
-public class GotSymbol extends Symbol {
+public final class GotSymbol extends Symbol {
 
     private static final int GOT_SIZE = 8;
 
@@ -33,18 +33,27 @@
         return offset / GOT_SIZE;
     }
 
+    /**
+     * Create GOT symbol info.
+     *
+     * @param type type of the symbol (UNDEFINED, FUNC, etc)
+     * @param binding binding of the symbol (LOCAL, GLOBAL, ...)
+     * @param container section in which this symbol is "defined"
+     * @param name name of the symbol
+     */
     public GotSymbol(Kind type, Binding binding, ByteContainer container, String name) {
         this(container.getByteStreamSize(), type, binding, container, name);
         container.appendBytes(new byte[GOT_SIZE], 0, GOT_SIZE);
     }
 
     /**
-     * Create symbol info.
+     * Create GOT symbol info.
      *
      * @param offset section offset for the defined symbol
      * @param type type of the symbol (UNDEFINED, FUNC, etc)
      * @param binding binding of the symbol (LOCAL, GLOBAL, ...)
      * @param sec section in which this symbol is "defined"
+     * @param name name of the symbol
      */
     public GotSymbol(int offset, Kind type, Binding binding, ByteContainer sec, String name) {
         super(offset, type, binding, sec, GOT_SIZE, name);
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/HeaderContainer.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/HeaderContainer.java	Wed Sep 20 23:55:35 2017 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,14 +27,15 @@
 import java.io.DataOutputStream;
 import java.io.IOException;
 
-public class HeaderContainer {
+public final class HeaderContainer {
 
     private static final int CURRENT_VERSION = 1;
     private final ReadOnlyDataContainer container;
+
     // int _version;
     // int _class_count;
     // int _method_count;
-    // int _metaspace_got_size;
+    // int _klasses_got_size;
     // int _metadata_got_size;
     // int _oop_got_size;
     // int _jvm_version_offset;
@@ -76,7 +77,7 @@
         this.container.putIntAt(2 * 4, count);
     }
 
-    public void setMetaspaceGotSize(int size) {
+    public void setKlassesGotSize(int size) {
         this.container.putIntAt(3 * 4, size);
     }
 
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/ReadOnlyDataContainer.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/ReadOnlyDataContainer.java	Wed Sep 20 23:55:35 2017 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,9 +23,9 @@
 
 package jdk.tools.jaotc.binformat;
 
-public class ReadOnlyDataContainer extends ByteContainer {
+public final class ReadOnlyDataContainer extends ByteContainer {
 
-    public ReadOnlyDataContainer(String containerName, SymbolTable symbolTable) {
+    ReadOnlyDataContainer(String containerName, SymbolTable symbolTable) {
         super(containerName, symbolTable);
     }
 }
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/Relocation.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/Relocation.java	Wed Sep 20 23:55:35 2017 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,25 +23,17 @@
 
 package jdk.tools.jaotc.binformat;
 
-public class Relocation {
+public final class Relocation {
 
     public enum RelocType {
         UNDEFINED,
         JAVA_CALL_INDIRECT,
         JAVA_CALL_DIRECT,
-        FOREIGN_CALL_INDIRECT,
         FOREIGN_CALL_INDIRECT_GOT, // Call to address in GOT cell
-        FOREIGN_CALL_DIRECT,
-        FOREIGN_CALL_DIRECT_FAR,
         STUB_CALL_DIRECT,
-        STUB_CALL_INDIRECT,
-        EXTERNAL_DATA_REFERENCE_FAR,
         METASPACE_GOT_REFERENCE,
         EXTERNAL_GOT_TO_PLT,
-        EXTERNAL_PLT_TO_GOT,
-        STATIC_STUB_TO_STATIC_METHOD,
-        STATIC_STUB_TO_HOTSPOT_LINKAGE_GOT,
-        LOADTIME_ADDRESS
+        EXTERNAL_PLT_TO_GOT
     }
 
     private final RelocType type;
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/Symbol.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/Symbol.java	Wed Sep 20 23:55:35 2017 -0400
@@ -39,7 +39,6 @@
         UNDEFINED,
         NATIVE_FUNCTION,
         JAVA_FUNCTION,
-        STATIC_STUB_CALL, // static call stub inside the text section
         OBJECT,
         NOTYPE
     }
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/Elf.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/Elf.java	Wed Sep 20 23:55:35 2017 -0400
@@ -25,17 +25,16 @@
 
 /**
  *
- * Support for the creation of Elf Object files.
- * Current support is limited to 64 bit x86_64.
+ * Support for the creation of Elf Object files. Current support is limited to 64 bit x86_64.
  *
  */
 
-public class Elf {
-
+final class Elf {
+    //@formatter:off
     /**
      * Elf64_Ehdr structure defines
      */
-    public enum Elf64_Ehdr {
+    enum Elf64_Ehdr {
                e_ident( 0,16),
                 e_type(16, 2),
              e_machine(18, 2),
@@ -51,15 +50,15 @@
                e_shnum(60, 2),
             e_shstrndx(62, 2);
 
-        public final int off;
-        public final int sz;
+        final int off;
+        final int sz;
 
         Elf64_Ehdr(int offset, int size) {
             this.off = offset;
             this.sz = size;
         }
 
-        public static int totalsize = 64;
+        static int totalsize = 64;
 
         /**
          * Elf64_Ehdr defines
@@ -68,50 +67,44 @@
         /**
          * e_ident
          */
-        public static final int  EI_MAG0             = 0;
-        public static final byte ELFMAG0             = 0x7f;
-        public static final int  EI_MAG1             = 1;
-        public static final byte ELFMAG1             = 0x45;
-        public static final int  EI_MAG2             = 2;
-        public static final byte ELFMAG2             = 0x4c;
-        public static final int  EI_MAG3             = 3;
-        public static final byte ELFMAG3             = 0x46;
+        static final int  EI_MAG0        = 0;
+        static final byte ELFMAG0        = 0x7f;
+        static final int  EI_MAG1        = 1;
+        static final byte ELFMAG1        = 0x45;
+        static final int  EI_MAG2        = 2;
+        static final byte ELFMAG2        = 0x4c;
+        static final int  EI_MAG3        = 3;
+        static final byte ELFMAG3        = 0x46;
+        static final int  EI_CLASS       = 4;
+        static final byte ELFCLASS64     = 0x2;
 
-        public static final int  EI_CLASS            = 4;
-        public static final byte ELFCLASS64          = 0x2;
+        static final int  EI_DATA        = 5;
+        static final byte ELFDATA2LSB    = 0x1;
 
-        public static final int  EI_DATA             = 5;
-        public static final byte ELFDATA2LSB         = 0x1;
+        static final int  EI_VERSION     = 6;
+        static final byte EV_CURRENT     = 0x1;
 
-        public static final int  EI_VERSION          = 6;
-        public static final byte EV_CURRENT          = 0x1;
-
-        public static final int  EI_OSABI            = 7;
-        public static final byte ELFOSABI_NONE       = 0x0;
+        static final int  EI_OSABI       = 7;
+        static final byte ELFOSABI_NONE  = 0x0;
 
         /**
          * e_type
          */
-        public static final char ET_REL              = 0x1;
+        static final char ET_REL         = 0x1;
 
         /**
          * e_machine
          */
-        public static final char EM_NONE             = 0;
-        public static final char EM_X86_64           = 62;
-        public static final char EM_AARCH64          = 183;
-
-        /**
-         * e_version
-         */
-        // public static final int EV_CURRENT           = 1;
+        static final char EM_NONE        = 0;
+        static final char EM_X86_64      = 62;
+        static final char EM_AARCH64     = 183;
 
     }
 
     /**
      * Elf64_Shdr structure defines
      */
-    public enum Elf64_Shdr {
+    enum Elf64_Shdr {
                sh_name( 0, 4),
                sh_type( 4, 4),
               sh_flags( 8, 8),
@@ -123,15 +116,15 @@
           sh_addralign(48, 8),
             sh_entsize(56, 8);
 
-        public final int off;
-        public final int sz;
+        final int off;
+        final int sz;
 
         Elf64_Shdr(int offset, int size) {
             this.off = offset;
             this.sz = size;
         }
 
-        public static int totalsize = 64;
+        static int totalsize = 64;
 
         /**
          * Elf64_Shdr defines
@@ -140,21 +133,21 @@
         /**
          * sh_type
          */
-        public static final int SHT_PROGBITS         = 0x1;
-        public static final int SHT_SYMTAB           = 0x2;
-        public static final int SHT_STRTAB           = 0x3;
-        public static final int SHT_RELA             = 0x4;
-        public static final int SHT_NOBITS           = 0x8;
-        public static final int SHT_REL              = 0x9;
+        static final int SHT_PROGBITS   = 0x1;
+        static final int SHT_SYMTAB     = 0x2;
+        static final int SHT_STRTAB     = 0x3;
+        static final int SHT_RELA       = 0x4;
+        static final int SHT_NOBITS     = 0x8;
+        static final int SHT_REL        = 0x9;
 
-        public static final byte SHN_UNDEF           = 0x0;
+        static final byte SHN_UNDEF     = 0x0;
 
         /**
          * sh_flag
          */
-        public static final int SHF_WRITE            = 0x1;
-        public static final int SHF_ALLOC            = 0x2;
-        public static final int SHF_EXECINSTR        = 0x4;
+        static final int SHF_WRITE      = 0x1;
+        static final int SHF_ALLOC      = 0x2;
+        static final int SHF_EXECINSTR  = 0x4;
 
     }
 
@@ -163,7 +156,7 @@
      *
      * Elf64_Sym structure defines
      */
-    public enum Elf64_Sym {
+    enum Elf64_Sym {
                st_name( 0, 4),
                st_info( 4, 1),
               st_other( 5, 1),
@@ -171,25 +164,25 @@
               st_value( 8, 8),
                st_size(16, 8);
 
-        public final int off;
-        public final int sz;
+        final int off;
+        final int sz;
 
         Elf64_Sym(int offset, int size) {
             this.off = offset;
             this.sz = size;
         }
 
-        public static int totalsize = 24;
+        static int totalsize = 24;
 
         /* ST_BIND is in bits 4-7 of st_info.  ST_TYPE is in low 4 bits */
-        public static final byte STB_LOCAL           = 0x0;
-        public static final byte STB_GLOBAL          = 0x1;
+        static final byte STB_LOCAL   = 0x0;
+        static final byte STB_GLOBAL  = 0x1;
 
-        public static final byte STT_NOTYPE          = 0x0;
-        public static final byte STT_OBJECT          = 0x1;
-        public static final byte STT_FUNC            = 0x2;
+        static final byte STT_NOTYPE  = 0x0;
+        static final byte STT_OBJECT  = 0x1;
+        static final byte STT_FUNC    = 0x2;
 
-        public static byte ELF64_ST_INFO(byte bind, byte type) {
+        static byte ELF64_ST_INFO(byte bind, byte type) {
             return (byte)(((bind) << 4) + ((type) & 0xf));
         }
 
@@ -198,59 +191,59 @@
     /**
      * Elf64_Rel structure defines
      */
-    public enum Elf64_Rel {
+    enum Elf64_Rel {
               r_offset( 0, 8),
                 r_info( 8, 8);
 
-        public final int off;
-        public final int sz;
+        final int off;
+        final int sz;
 
         Elf64_Rel(int offset, int size) {
             this.off = offset;
             this.sz = size;
         }
 
-        public static int totalsize = 16;
+        static int totalsize = 16;
 
         /**
          * Relocation types
          */
-        public static final int R_X86_64_NONE        = 0x0;
-        public static final int R_X86_64_64          = 0x1;
-        public static final int R_X86_64_PC32        = 0x2;
-        public static final int R_X86_64_PLT32       = 0x4;
-        public static final int R_X86_64_GOTPCREL    = 0x9;
+        static final int R_X86_64_NONE     = 0x0;
+        static final int R_X86_64_64       = 0x1;
+        static final int R_X86_64_PC32     = 0x2;
+        static final int R_X86_64_PLT32    = 0x4;
+        static final int R_X86_64_GOTPCREL = 0x9;
 
     }
 
     /**
      * Elf64_Rela structure defines
      */
-    public enum Elf64_Rela {
+    enum Elf64_Rela {
               r_offset( 0, 8),
                 r_info( 8, 8),
               r_addend(16, 8);
 
-        public final int off;
-        public final int sz;
+        final int off;
+        final int sz;
 
         Elf64_Rela(int offset, int size) {
             this.off = offset;
             this.sz = size;
         }
 
-        public static int totalsize = 24;
+        static int totalsize = 24;
 
-        public static final int R_X86_64_NONE        = 0x0;
-        public static final int R_X86_64_64          = 0x1;
-        public static final int R_X86_64_PC32        = 0x2;
-        public static final int R_X86_64_PLT32       = 0x4;
-        public static final int R_X86_64_GOTPCREL    = 0x9;
+        static final int R_X86_64_NONE     = 0x0;
+        static final int R_X86_64_64       = 0x1;
+        static final int R_X86_64_PC32     = 0x2;
+        static final int R_X86_64_PLT32    = 0x4;
+        static final int R_X86_64_GOTPCREL = 0x9;
 
-        public static long ELF64_R_INFO(int symidx, int type) {
-            return (((long)symidx << 32) + ((long)type));
+        static long ELF64_R_INFO(int symidx, int type) {
+            return (((long)symidx << 32) + type);
         }
 
     }
-
+    //@formatter:on
 }
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfByteBuffer.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfByteBuffer.java	Wed Sep 20 23:55:35 2017 -0400
@@ -23,20 +23,20 @@
 
 package jdk.tools.jaotc.binformat.elf;
 
-
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
 import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Ehdr;
 import jdk.tools.jaotc.binformat.elf.ElfTargetInfo;
 
-public class ElfByteBuffer {
+final class ElfByteBuffer {
 
-    public static ByteBuffer allocate(int size) {
+    static ByteBuffer allocate(int size) {
         ByteBuffer buf = ByteBuffer.allocate(size);
-        if (ElfTargetInfo.getElfEndian() == Elf64_Ehdr.ELFDATA2LSB)
+        if (ElfTargetInfo.getElfEndian() == Elf64_Ehdr.ELFDATA2LSB) {
             buf.order(ByteOrder.LITTLE_ENDIAN);
-        else
+        } else {
             buf.order(ByteOrder.BIG_ENDIAN);
+        }
         return (buf);
     }
 
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfContainer.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfContainer.java	Wed Sep 20 23:55:35 2017 -0400
@@ -26,14 +26,13 @@
 import java.io.File;
 import java.io.FileOutputStream;
 
-public class ElfContainer {
+final class ElfContainer {
 
-    File outputFile;
-    FileOutputStream outputStream;
-    long fileOffset;
+    private final File outputFile;
+    private FileOutputStream outputStream;
+    private long fileOffset;
 
-    public ElfContainer(String fileName, String aotVersion) {
-        String baseName;
+    ElfContainer(String fileName) {
 
         outputFile = new File(fileName);
         if (outputFile.exists()) {
@@ -48,7 +47,7 @@
         fileOffset = 0;
     }
 
-    public void close() {
+    void close() {
         try {
             outputStream.close();
         } catch (Exception e) {
@@ -56,8 +55,10 @@
         }
     }
 
-    public void writeBytes(byte [] bytes) {
-        if (bytes == null) return;
+    void writeBytes(byte[] bytes) {
+        if (bytes == null) {
+            return;
+        }
         try {
             outputStream.write(bytes);
         } catch (Exception e) {
@@ -67,11 +68,13 @@
     }
 
     // Write bytes to output file with up front alignment padding
-    public void writeBytes(byte [] bytes, int alignment) {
-        if (bytes == null) return;
+    void writeBytes(byte[] bytes, int alignment) {
+        if (bytes == null) {
+            return;
+        }
         try {
             // Pad to alignment
-            while ((fileOffset & (long)(alignment-1)) != 0) {
+            while ((fileOffset & (alignment - 1)) != 0) {
                 outputStream.write(0);
                 fileOffset++;
             }
@@ -82,4 +85,3 @@
         fileOffset += bytes.length;
     }
 }
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfHeader.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfHeader.java	Wed Sep 20 23:55:35 2017 -0400
@@ -24,55 +24,52 @@
 package jdk.tools.jaotc.binformat.elf;
 
 import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
 
-import jdk.tools.jaotc.binformat.elf.Elf;
 import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Ehdr;
 import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Shdr;
 import jdk.tools.jaotc.binformat.elf.ElfTargetInfo;
 import jdk.tools.jaotc.binformat.elf.ElfByteBuffer;
 
-public class ElfHeader {
-    ByteBuffer header;
+final class ElfHeader {
+    private final ByteBuffer header;
 
-    public ElfHeader() {
+    ElfHeader() {
         header = ElfByteBuffer.allocate(Elf64_Ehdr.totalsize);
 
-        header.put(Elf64_Ehdr.e_ident.off+Elf64_Ehdr.EI_MAG0, Elf64_Ehdr.ELFMAG0);
-        header.put(Elf64_Ehdr.e_ident.off+Elf64_Ehdr.EI_MAG1, Elf64_Ehdr.ELFMAG1);
-        header.put(Elf64_Ehdr.e_ident.off+Elf64_Ehdr.EI_MAG2, Elf64_Ehdr.ELFMAG2);
-        header.put(Elf64_Ehdr.e_ident.off+Elf64_Ehdr.EI_MAG3, Elf64_Ehdr.ELFMAG3);
-        header.put(Elf64_Ehdr.e_ident.off+Elf64_Ehdr.EI_CLASS, Elf64_Ehdr.ELFCLASS64);
-        header.put(Elf64_Ehdr.e_ident.off+Elf64_Ehdr.EI_DATA, Elf64_Ehdr.ELFDATA2LSB);
-        header.put(Elf64_Ehdr.e_ident.off+Elf64_Ehdr.EI_VERSION, Elf64_Ehdr.EV_CURRENT);
-        header.put(Elf64_Ehdr.e_ident.off+Elf64_Ehdr.EI_OSABI, Elf64_Ehdr.ELFOSABI_NONE);
+        header.put(Elf64_Ehdr.e_ident.off + Elf64_Ehdr.EI_MAG0, Elf64_Ehdr.ELFMAG0);
+        header.put(Elf64_Ehdr.e_ident.off + Elf64_Ehdr.EI_MAG1, Elf64_Ehdr.ELFMAG1);
+        header.put(Elf64_Ehdr.e_ident.off + Elf64_Ehdr.EI_MAG2, Elf64_Ehdr.ELFMAG2);
+        header.put(Elf64_Ehdr.e_ident.off + Elf64_Ehdr.EI_MAG3, Elf64_Ehdr.ELFMAG3);
+        header.put(Elf64_Ehdr.e_ident.off + Elf64_Ehdr.EI_CLASS, Elf64_Ehdr.ELFCLASS64);
+        header.put(Elf64_Ehdr.e_ident.off + Elf64_Ehdr.EI_DATA, Elf64_Ehdr.ELFDATA2LSB);
+        header.put(Elf64_Ehdr.e_ident.off + Elf64_Ehdr.EI_VERSION, Elf64_Ehdr.EV_CURRENT);
+        header.put(Elf64_Ehdr.e_ident.off + Elf64_Ehdr.EI_OSABI, Elf64_Ehdr.ELFOSABI_NONE);
 
         header.putChar(Elf64_Ehdr.e_type.off, Elf64_Ehdr.ET_REL);
         header.putChar(Elf64_Ehdr.e_machine.off, ElfTargetInfo.getElfArch());
         header.putInt(Elf64_Ehdr.e_version.off, Elf64_Ehdr.EV_CURRENT);
-        header.putChar(Elf64_Ehdr.e_ehsize.off, (char)Elf64_Ehdr.totalsize);
-        header.putChar(Elf64_Ehdr.e_shentsize.off, (char)Elf64_Shdr.totalsize);
+        header.putChar(Elf64_Ehdr.e_ehsize.off, (char) Elf64_Ehdr.totalsize);
+        header.putChar(Elf64_Ehdr.e_shentsize.off, (char) Elf64_Shdr.totalsize);
 
     }
 
     // Update header with file offset of first section
-    public void setSectionOff(int offset) {
+    void setSectionOff(int offset) {
         header.putLong(Elf64_Ehdr.e_shoff.off, offset);
     }
 
     // Update header with the number of total sections
-    public void setSectionNum(int count) {
-        header.putChar(Elf64_Ehdr.e_shnum.off, (char)count);
+    void setSectionNum(int count) {
+        header.putChar(Elf64_Ehdr.e_shnum.off, (char) count);
     }
 
     // Update header with the section index containing the
     // string table for section names
-    public void setSectionStrNdx(int index) {
-        header.putChar(Elf64_Ehdr.e_shstrndx.off, (char)index);
+    void setSectionStrNdx(int index) {
+        header.putChar(Elf64_Ehdr.e_shstrndx.off, (char) index);
     }
 
-    public byte[] getArray() {
+    byte[] getArray() {
         return header.array();
     }
 }
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfRelocEntry.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfRelocEntry.java	Wed Sep 20 23:55:35 2017 -0400
@@ -24,28 +24,23 @@
 package jdk.tools.jaotc.binformat.elf;
 
 import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
 
-import jdk.tools.jaotc.binformat.elf.Elf;
 import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Rela;
-import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Ehdr;
-import jdk.tools.jaotc.binformat.elf.ElfTargetInfo;
 import jdk.tools.jaotc.binformat.elf.ElfByteBuffer;
 
-public class ElfRelocEntry {
-    ByteBuffer entry;
+final class ElfRelocEntry {
+    private final ByteBuffer entry;
 
-    public ElfRelocEntry(int offset, int symno, int type, int addend) {
+    ElfRelocEntry(int offset, int symno, int type, int addend) {
 
         entry = ElfByteBuffer.allocate(Elf64_Rela.totalsize);
 
         entry.putLong(Elf64_Rela.r_offset.off, offset);
-        entry.putLong(Elf64_Rela.r_info.off, Elf64_Rela.ELF64_R_INFO(symno,type));
+        entry.putLong(Elf64_Rela.r_info.off, Elf64_Rela.ELF64_R_INFO(symno, type));
         entry.putLong(Elf64_Rela.r_addend.off, addend);
     }
 
-    public byte[] getArray() {
+    byte[] getArray() {
         return entry.array();
     }
 }
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfRelocTable.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfRelocTable.java	Wed Sep 20 23:55:35 2017 -0400
@@ -25,48 +25,38 @@
 
 import java.util.ArrayList;
 import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
 
 import jdk.tools.jaotc.binformat.elf.ElfRelocEntry;
-import jdk.tools.jaotc.binformat.elf.ElfTargetInfo;
 import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Rela;
-import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Ehdr;
 import jdk.tools.jaotc.binformat.elf.ElfByteBuffer;
 
-public class ElfRelocTable {
-    ArrayList<ArrayList<ElfRelocEntry>> relocEntries;
+final class ElfRelocTable {
+    private final ArrayList<ArrayList<ElfRelocEntry>> relocEntries;
 
-    public ElfRelocTable(int numsects) {
-        relocEntries = new ArrayList<ArrayList<ElfRelocEntry>>(numsects);
-        for (int i = 0; i < numsects; i++)
+    ElfRelocTable(int numsects) {
+        relocEntries = new ArrayList<>(numsects);
+        for (int i = 0; i < numsects; i++) {
             relocEntries.add(new ArrayList<ElfRelocEntry>());
+        }
     }
 
-    public void createRelocationEntry(int sectindex,
-                                      int offset,
-                                      int symno,
-                                      int type,
-                                      int addend) {
-
-        ElfRelocEntry entry = new ElfRelocEntry(offset,
-                                                symno,
-                                                type,
-                                                addend);
+    void createRelocationEntry(int sectindex, int offset, int symno, int type, int addend) {
+        ElfRelocEntry entry = new ElfRelocEntry(offset, symno, type, addend);
         relocEntries.get(sectindex).add(entry);
     }
 
-    public int getNumRelocs(int section_index) {
+    int getNumRelocs(int section_index) {
         return relocEntries.get(section_index).size();
     }
 
     // Return the relocation entries for a single section
-    //   or null if no entries added to section
-    public byte [] getRelocData(int section_index) {
+    // or null if no entries added to section
+    byte[] getRelocData(int section_index) {
         ArrayList<ElfRelocEntry> entryList = relocEntries.get(section_index);
 
-        if (entryList.size() == 0)
+        if (entryList.size() == 0) {
             return null;
-
+        }
         ByteBuffer relocData = ElfByteBuffer.allocate(entryList.size() * Elf64_Rela.totalsize);
 
         // Copy each entry to a single ByteBuffer
@@ -78,4 +68,3 @@
         return (relocData.array());
     }
 }
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfSection.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfSection.java	Wed Sep 20 23:55:35 2017 -0400
@@ -24,41 +24,36 @@
 package jdk.tools.jaotc.binformat.elf;
 
 import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
 
-import jdk.tools.jaotc.binformat.elf.Elf;
-import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Ehdr;
 import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Shdr;
 import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Rel;
 import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Rela;
 import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Sym;
 import jdk.tools.jaotc.binformat.elf.ElfByteBuffer;
 
-public class ElfSection {
-    String name;
-    ByteBuffer section;
-    byte [] data;
-    boolean hasrelocations;
-    int sectionIndex;
+final class ElfSection {
+    private final String name;
+    private final ByteBuffer section;
+    private final byte[] data;
+    private final boolean hasrelocations;
+    private final int sectionIndex;
 
     /**
      * String holding section name strings
      */
-    private static StringBuilder sectNameTab = new StringBuilder();
+    private final static StringBuilder sectNameTab = new StringBuilder();
 
     /**
-     * Keeps track of bytes in section string table since strTabContent.length()
-     * is number of chars, not bytes.
+     * Keeps track of bytes in section string table since strTabContent.length() is number of chars,
+     * not bytes.
      */
     private static int shStrTabNrOfBytes = 0;
 
-    public ElfSection(String sectName, byte [] sectData, int sectFlags,
-                      int sectType, boolean hasRelocations, int sectIndex) {
-
-        long align;
+    ElfSection(String sectName, byte[] sectData, int sectFlags, int sectType,
+               boolean hasRelocations, int align, int sectIndex) {
 
         section = ElfByteBuffer.allocate(Elf64_Shdr.totalsize);
-
+        name = sectName;
         // Return all 0's for NULL section
         if (sectIndex == 0) {
             sectNameTab.append('\0');
@@ -72,7 +67,6 @@
         section.putInt(Elf64_Shdr.sh_name.off, shStrTabNrOfBytes);
         sectNameTab.append(sectName).append('\0');
         shStrTabNrOfBytes += (sectName.getBytes().length + 1);
-        name = sectName;
 
         section.putInt(Elf64_Shdr.sh_type.off, sectType);
         section.putLong(Elf64_Shdr.sh_flags.off, sectFlags);
@@ -82,43 +76,26 @@
         if (sectName.equals(".shstrtab")) {
             section.putLong(Elf64_Shdr.sh_size.off, shStrTabNrOfBytes);
             data = sectNameTab.toString().getBytes();
-        }
-        else {
+        } else {
             data = sectData;
             section.putLong(Elf64_Shdr.sh_size.off, sectData.length);
         }
 
         section.putLong(Elf64_Shdr.sh_entsize.off, 0);
 
-        // Determine the alignment and entrysize
+        // Determine the entrysize
         // based on type of section
         switch (sectType) {
-            case Elf64_Shdr.SHT_PROGBITS:
-                if ((sectFlags & Elf64_Shdr.SHF_EXECINSTR) != 0)
-                    align = 16;
-                else
-                    align = 4;
-                break;
             case Elf64_Shdr.SHT_SYMTAB:
-                align = 8;
                 section.putLong(Elf64_Shdr.sh_entsize.off, Elf64_Sym.totalsize);
                 break;
-            case Elf64_Shdr.SHT_STRTAB:
-                align = 1;
-                break;
             case Elf64_Shdr.SHT_RELA:
-                align = 8;
                 section.putLong(Elf64_Shdr.sh_entsize.off, Elf64_Rela.totalsize);
                 break;
             case Elf64_Shdr.SHT_REL:
-                align = 8;
                 section.putLong(Elf64_Shdr.sh_entsize.off, Elf64_Rel.totalsize);
                 break;
-            case Elf64_Shdr.SHT_NOBITS:
-                align = 4;
-                break;
             default:
-                align = 8;
                 break;
         }
         section.putLong(Elf64_Shdr.sh_addralign.off, align);
@@ -127,55 +104,53 @@
         sectionIndex = sectIndex;
     }
 
-    public String getName() {
+    String getName() {
         return name;
     }
 
-    public long getSize() {
+    long getSize() {
         return section.getLong(Elf64_Shdr.sh_size.off);
     }
 
-    public int getDataAlign() {
-        return ((int)section.getLong(Elf64_Shdr.sh_addralign.off));
+    int getDataAlign() {
+        return ((int) section.getLong(Elf64_Shdr.sh_addralign.off));
     }
 
     // Alignment requirements for the Elf64_Shdr structures
-    public static int getShdrAlign() {
+    static int getShdrAlign() {
         return (4);
     }
 
-    public byte[] getArray() {
+    byte[] getArray() {
         return section.array();
     }
 
-    public byte[] getDataArray() {
+    byte[] getDataArray() {
         return data;
     }
 
-    public void setOffset(long offset) {
+    void setOffset(long offset) {
         section.putLong(Elf64_Shdr.sh_offset.off, offset);
     }
 
-    public void setLink(int link) {
+    void setLink(int link) {
         section.putInt(Elf64_Shdr.sh_link.off, link);
     }
 
-    public void setInfo(int info) {
+    void setInfo(int info) {
         section.putInt(Elf64_Shdr.sh_info.off, info);
     }
 
-    public long getOffset() {
+    long getOffset() {
         return (section.getLong(Elf64_Shdr.sh_offset.off));
     }
 
-    public boolean hasRelocations() {
+    boolean hasRelocations() {
         return hasrelocations;
     }
 
-    public int getSectionId() {
+    int getSectionId() {
         return sectionIndex;
     }
 
 }
-
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfSymbol.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfSymbol.java	Wed Sep 20 23:55:35 2017 -0400
@@ -24,34 +24,29 @@
 package jdk.tools.jaotc.binformat.elf;
 
 import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
 
 import jdk.tools.jaotc.binformat.NativeSymbol;
-import jdk.tools.jaotc.binformat.elf.Elf;
 import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Sym;
-import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Ehdr;
 import jdk.tools.jaotc.binformat.elf.ElfByteBuffer;
 
-public class ElfSymbol extends NativeSymbol {
-    ByteBuffer sym;
+final class ElfSymbol extends NativeSymbol {
+    private final ByteBuffer sym;
 
-    public ElfSymbol(int symbolindex, int strindex, byte type, byte bind,
-                     byte sectindex, long offset, long size) {
+    ElfSymbol(int symbolindex, int strindex, byte type, byte bind, byte sectindex, long offset, long size) {
         super(symbolindex);
         sym = ElfByteBuffer.allocate(Elf64_Sym.totalsize);
 
         sym.putInt(Elf64_Sym.st_name.off, strindex);
         sym.put(Elf64_Sym.st_info.off, Elf64_Sym.ELF64_ST_INFO(bind, type));
-        sym.put(Elf64_Sym.st_other.off, (byte)0);
+        sym.put(Elf64_Sym.st_other.off, (byte) 0);
         // Section indexes start at 1 but we manage the index internally
         // as 0 relative
-        sym.putChar(Elf64_Sym.st_shndx.off, (char)(sectindex));
+        sym.putChar(Elf64_Sym.st_shndx.off, (char) (sectindex));
         sym.putLong(Elf64_Sym.st_value.off, offset);
         sym.putLong(Elf64_Sym.st_size.off, size);
     }
 
-    public byte[] getArray() {
+    byte[] getArray() {
         return sym.array();
     }
 }
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfSymtab.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfSymtab.java	Wed Sep 20 23:55:35 2017 -0400
@@ -24,41 +24,38 @@
 package jdk.tools.jaotc.binformat.elf;
 
 import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
 import java.util.ArrayList;
 
-import jdk.tools.jaotc.binformat.elf.Elf;
 import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Sym;
 import jdk.tools.jaotc.binformat.elf.ElfSymbol;
 import jdk.tools.jaotc.binformat.elf.ElfByteBuffer;
 
-public class ElfSymtab {
+final class ElfSymtab {
 
-    ArrayList<ElfSymbol>localSymbols = new ArrayList<ElfSymbol>();
-    ArrayList<ElfSymbol>globalSymbols = new ArrayList<ElfSymbol>();
+    private final ArrayList<ElfSymbol> localSymbols = new ArrayList<>();
+    private final ArrayList<ElfSymbol> globalSymbols = new ArrayList<>();
 
     /**
      * number of symbols added
      */
-    int symbolCount;
+    private int symbolCount;
 
     /**
      * String holding symbol table strings
      */
-    private StringBuilder strTabContent = new StringBuilder();
+    private final StringBuilder strTabContent = new StringBuilder();
 
     /**
-     * Keeps track of bytes in string table since strTabContent.length()
-     * is number of chars, not bytes.
+     * Keeps track of bytes in string table since strTabContent.length() is number of chars, not
+     * bytes.
      */
     private int strTabNrOfBytes = 0;
 
-    public ElfSymtab() {
+    ElfSymtab() {
         symbolCount = 0;
     }
 
-    public ElfSymbol addSymbolEntry(String name, byte type, byte bind,
-                                    byte secHdrIndex, long offset, long size) {
+    ElfSymbol addSymbolEntry(String name, byte type, byte bind, byte secHdrIndex, long offset, long size) {
         // Get the current symbol index and append symbol name to string table.
         int index;
         ElfSymbol sym;
@@ -76,7 +73,7 @@
             // strTabContent.append("_").append(name).append('\0');
             strTabContent.append(name).append('\0');
             // + 1 for null, + 1 for "_"
-            //strTabNrOfBytes += (name.getBytes().length + 1 + 1);
+            // strTabNrOfBytes += (name.getBytes().length + 1 + 1);
             strTabNrOfBytes += (name.getBytes().length + 1);
 
             sym = new ElfSymbol(symbolCount, index, type, bind, secHdrIndex, offset, size);
@@ -92,44 +89,47 @@
     // Update the symbol indexes once all symbols have been added.
     // This is required since we'll be reordering the symbols in the
     // file to be in the order of Local then global.
-    public void updateIndexes() {
+    void updateIndexes() {
         int index = 0;
 
         // Update the local symbol indexes
-        for (int i = 0; i < localSymbols.size(); i++ ) {
+        for (int i = 0; i < localSymbols.size(); i++) {
             ElfSymbol sym = localSymbols.get(i);
             sym.setIndex(index++);
         }
 
         // Update the global symbol indexes
-        for (int i = 0; i < globalSymbols.size(); i++ ) {
+        for (int i = 0; i < globalSymbols.size(); i++) {
             ElfSymbol sym = globalSymbols.get(i);
             sym.setIndex(index++);
         }
     }
 
-    public int getNumLocalSyms()  { return localSymbols.size();  }
-    public int getNumGlobalSyms() { return globalSymbols.size(); }
+    int getNumLocalSyms() {
+        return localSymbols.size();
+    }
 
+    int getNumGlobalSyms() {
+        return globalSymbols.size();
+    }
 
     // Create a single byte array that contains the symbol table entries
-    public byte[] getSymtabArray() {
-        int index = 0;
-        ByteBuffer symtabData = ElfByteBuffer.allocate(symbolCount*Elf64_Sym.totalsize);
-        byte [] retarray;
+    byte[] getSymtabArray() {
+        ByteBuffer symtabData = ElfByteBuffer.allocate(symbolCount * Elf64_Sym.totalsize);
+        byte[] retarray;
 
         updateIndexes();
 
         // Add the local symbols
-        for (int i = 0; i < localSymbols.size(); i++ ) {
+        for (int i = 0; i < localSymbols.size(); i++) {
             ElfSymbol sym = localSymbols.get(i);
-            byte [] arr = sym.getArray();
+            byte[] arr = sym.getArray();
             symtabData.put(arr);
         }
         // Add the global symbols
-        for (int i = 0; i < globalSymbols.size(); i++ ) {
+        for (int i = 0; i < globalSymbols.size(); i++) {
             ElfSymbol sym = globalSymbols.get(i);
-            byte [] arr = sym.getArray();
+            byte[] arr = sym.getArray();
             symtabData.put(arr);
         }
         retarray = symtabData.array();
@@ -138,10 +138,8 @@
     }
 
     // Return the string table array
-    public byte[] getStrtabArray() {
-        byte [] strs = strTabContent.toString().getBytes();
+    byte[] getStrtabArray() {
+        byte[] strs = strTabContent.toString().getBytes();
         return (strs);
     }
 }
-
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfTargetInfo.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfTargetInfo.java	Wed Sep 20 23:55:35 2017 -0400
@@ -24,14 +24,13 @@
 package jdk.tools.jaotc.binformat.elf;
 
 import java.nio.ByteOrder;
-import jdk.tools.jaotc.binformat.elf.Elf;
 import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Ehdr;
 
 /**
  * Class that abstracts MACH-O target details.
  *
  */
-public class ElfTargetInfo {
+final class ElfTargetInfo {
     /**
      * Target architecture.
      */
@@ -68,16 +67,15 @@
         }
     }
 
-    public static char getElfArch() {
+    static char getElfArch() {
         return arch;
     }
 
-    public static int getElfEndian() {
+    static int getElfEndian() {
         return endian;
     }
 
-    public static String getOsName() {
+    static String getOsName() {
         return osName;
     }
 }
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/JELFRelocObject.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/JELFRelocObject.java	Wed Sep 20 23:55:35 2017 -0400
@@ -24,13 +24,11 @@
 package jdk.tools.jaotc.binformat.elf;
 
 import java.io.IOException;
-import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
-import jdk.tools.jaotc.binformat.Container;
 import jdk.tools.jaotc.binformat.BinaryContainer;
 import jdk.tools.jaotc.binformat.ByteContainer;
 import jdk.tools.jaotc.binformat.CodeContainer;
@@ -38,17 +36,14 @@
 import jdk.tools.jaotc.binformat.Relocation;
 import jdk.tools.jaotc.binformat.Relocation.RelocType;
 import jdk.tools.jaotc.binformat.Symbol;
-import jdk.tools.jaotc.binformat.NativeSymbol;
 import jdk.tools.jaotc.binformat.Symbol.Binding;
 import jdk.tools.jaotc.binformat.Symbol.Kind;
 
-import jdk.tools.jaotc.binformat.elf.Elf;
 import jdk.tools.jaotc.binformat.elf.ElfSymbol;
 import jdk.tools.jaotc.binformat.elf.ElfTargetInfo;
 import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Ehdr;
 import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Shdr;
 import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Sym;
-import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Rel;
 import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Rela;
 
 public class JELFRelocObject {
@@ -59,39 +54,36 @@
 
     private final int segmentSize;
 
-    public JELFRelocObject(BinaryContainer binContainer, String outputFileName, String aotVersion) {
+    public JELFRelocObject(BinaryContainer binContainer, String outputFileName) {
         this.binContainer = binContainer;
-        this.elfContainer = new ElfContainer(outputFileName, aotVersion);
+        this.elfContainer = new ElfContainer(outputFileName);
         this.segmentSize = binContainer.getCodeSegmentSize();
     }
 
-    private ElfSection createByteSection(ArrayList<ElfSection>sections,
-                                         String sectName,
-                                         byte [] scnData,
-                                         boolean hasRelocs,
-                                         int scnFlags,
-                                         int scnType) {
+    private static ElfSection createByteSection(ArrayList<ElfSection> sections,
+                                                String sectName,
+                                                byte[] scnData,
+                                                boolean hasRelocs,
+                                                int align,
+                                                int scnFlags,
+                                                int scnType) {
 
-        ElfSection sect = new ElfSection(sectName,
-                                         scnData,
-                                         scnFlags,
-                                         scnType,
-                                         hasRelocs,
-                                         sections.size());
+        ElfSection sect = new ElfSection(sectName, scnData, scnFlags, scnType,
+                                         hasRelocs, align, sections.size());
         // Add this section to our list
         sections.add(sect);
 
         return (sect);
     }
 
-    private void createByteSection(ArrayList<ElfSection>sections,
+    private void createByteSection(ArrayList<ElfSection> sections,
                                    ByteContainer c, int scnFlags) {
         ElfSection sect;
         boolean hasRelocs = c.hasRelocations();
         byte[] scnData = c.getByteArray();
 
         int scnType = Elf64_Shdr.SHT_PROGBITS;
-        boolean zeros = hasRelocs;
+        boolean zeros = !hasRelocs;
         if (zeros) {
             for (byte b : scnData) {
                 if (b != 0) {
@@ -105,20 +97,20 @@
         }
 
         sect = createByteSection(sections, c.getContainerName(),
-                                 scnData, hasRelocs,
+                                 scnData, hasRelocs, segmentSize,
                                  scnFlags, scnType);
         c.setSectionId(sect.getSectionId());
     }
 
-    private void createCodeSection(ArrayList<ElfSection>sections, CodeContainer c) {
+    private void createCodeSection(ArrayList<ElfSection> sections, CodeContainer c) {
         createByteSection(sections, c, Elf64_Shdr.SHF_ALLOC | Elf64_Shdr.SHF_EXECINSTR);
     }
 
-    private void createReadOnlySection(ArrayList<ElfSection>sections, ReadOnlyDataContainer c) {
+    private void createReadOnlySection(ArrayList<ElfSection> sections, ReadOnlyDataContainer c) {
         createByteSection(sections, c, Elf64_Shdr.SHF_ALLOC);
     }
 
-    private void createReadWriteSection(ArrayList<ElfSection>sections, ByteContainer c) {
+    private void createReadWriteSection(ArrayList<ElfSection> sections, ByteContainer c) {
         createByteSection(sections, c, Elf64_Shdr.SHF_ALLOC | Elf64_Shdr.SHF_WRITE);
     }
 
@@ -133,10 +125,10 @@
         // Allocate ELF Header
         ElfHeader eh = new ElfHeader();
 
-        ArrayList<ElfSection> sections = new ArrayList<ElfSection>();
+        ArrayList<ElfSection> sections = new ArrayList<>();
 
         // Create the null section
-        createByteSection(sections, null, null, false, 0, 0);
+        createByteSection(sections, null, null, false, 1, 0, 0);
 
         // Create text section
         createCodeSection(sections, binContainer.getCodeContainer());
@@ -144,60 +136,49 @@
         createReadOnlySection(sections, binContainer.getKlassesOffsetsContainer());
         createReadOnlySection(sections, binContainer.getMethodsOffsetsContainer());
         createReadOnlySection(sections, binContainer.getKlassesDependenciesContainer());
-        createReadWriteSection(sections, binContainer.getMetaspaceGotContainer());
-        createReadWriteSection(sections, binContainer.getMetadataGotContainer());
-        createReadWriteSection(sections, binContainer.getMethodStateContainer());
-        createReadWriteSection(sections, binContainer.getOopGotContainer());
-        createReadWriteSection(sections, binContainer.getMethodMetadataContainer());
+        createReadOnlySection(sections, binContainer.getMethodMetadataContainer());
         createReadOnlySection(sections, binContainer.getStubsOffsetsContainer());
         createReadOnlySection(sections, binContainer.getHeaderContainer().getContainer());
         createReadOnlySection(sections, binContainer.getCodeSegmentsContainer());
         createReadOnlySection(sections, binContainer.getConstantDataContainer());
         createReadOnlySection(sections, binContainer.getConfigContainer());
-
-        // createExternalLinkage();
-
-        createCodeSection(sections, binContainer.getExtLinkageContainer());
+        createReadWriteSection(sections, binContainer.getKlassesGotContainer());
+        createReadWriteSection(sections, binContainer.getCountersGotContainer());
+        createReadWriteSection(sections, binContainer.getMetadataGotContainer());
+        createReadWriteSection(sections, binContainer.getOopGotContainer());
+        createReadWriteSection(sections, binContainer.getMethodStateContainer());
         createReadWriteSection(sections, binContainer.getExtLinkageGOTContainer());
 
         // Get ELF symbol data from BinaryContainer object's symbol tables
-        ElfSymtab symtab = createELFSymbolTables(sections, symbols);
+        ElfSymtab symtab = createELFSymbolTables(symbols);
 
         // Create string table section and symbol table sections in
         // that order since symtab section needs to set the index of
         // strtab in sh_link field
-        ElfSection strTabSection = createByteSection(sections,
-                                                     ".strtab",
+        ElfSection strTabSection = createByteSection(sections, ".strtab",
                                                      symtab.getStrtabArray(),
-                                                     false,
-                                                     0,
+                                                     false, 1, 0,
                                                      Elf64_Shdr.SHT_STRTAB);
 
         // Now create .symtab section with the symtab data constructed.
         // On Linux, sh_link of symtab contains the index of string table
         // its symbols reference and sh_info contains the index of first
         // non-local symbol
-        ElfSection symTabSection = createByteSection(sections,
-                                                    ".symtab",
-                                                    symtab.getSymtabArray(),
-                                                    false,
-                                                    0,
-                                                    Elf64_Shdr.SHT_SYMTAB);
+        ElfSection symTabSection = createByteSection(sections, ".symtab",
+                                                     symtab.getSymtabArray(),
+                                                     false, 8, 0,
+                                                     Elf64_Shdr.SHT_SYMTAB);
         symTabSection.setLink(strTabSection.getSectionId());
         symTabSection.setInfo(symtab.getNumLocalSyms());
 
-        ElfRelocTable elfRelocTable = createElfRelocTable(sections,
-                                                          relocationTable);
+        ElfRelocTable elfRelocTable = createElfRelocTable(sections, relocationTable);
 
         createElfRelocSections(sections, elfRelocTable, symTabSection.getSectionId());
 
         // Now, finally, after creating all sections, create shstrtab section
-        ElfSection shStrTabSection = createByteSection(sections,
-                                                    ".shstrtab",
-                                                    null,
-                                                    false,
-                                                    0,
-                                                    Elf64_Shdr.SHT_STRTAB);
+        ElfSection shStrTabSection = createByteSection(sections, ".shstrtab",
+                                                       null, false, 1, 0,
+                                                       Elf64_Shdr.SHT_STRTAB);
         eh.setSectionStrNdx(shStrTabSection.getSectionId());
 
         // Update all section offsets and the Elf header section offset
@@ -206,21 +187,21 @@
         int file_offset = Elf64_Ehdr.totalsize;
 
         // and round it up
-        file_offset = (file_offset + (sections.get(1).getDataAlign()-1)) &
-                      ~((sections.get(1).getDataAlign()-1));
+        file_offset = (file_offset + (sections.get(1).getDataAlign() - 1)) &
+                      ~((sections.get(1).getDataAlign() - 1));
 
         // Calc file offsets for section data skipping null section
         for (int i = 1; i < sections.size(); i++) {
             ElfSection sect = sections.get(i);
-            file_offset = (file_offset + (sect.getDataAlign()-1)) &
-                           ~((sect.getDataAlign()-1));
+            file_offset = (file_offset + (sect.getDataAlign() - 1)) &
+                          ~((sect.getDataAlign() - 1));
             sect.setOffset(file_offset);
             file_offset += sect.getSize();
         }
 
         // Align the section table
-        file_offset = (file_offset + (ElfSection.getShdrAlign()-1)) &
-                      ~((ElfSection.getShdrAlign()-1));
+        file_offset = (file_offset + (ElfSection.getShdrAlign() - 1)) &
+                      ~((ElfSection.getShdrAlign() - 1));
 
         // Update the Elf Header with the offset of the first Elf64_Shdr
         // and the number of sections.
@@ -244,24 +225,25 @@
 
         elfContainer.close();
     }
+
     /**
-     * Construct ELF symbol data from BinaryContainer object's symbol tables. Both dynamic ELF
-     * symbol table and ELF symbol table are created from BinaryContainer's symbol info.
+     * Construct ELF symbol data from BinaryContainer object's symbol tables. Both dynamic ELF symbol
+     * table and ELF symbol table are created from BinaryContainer's symbol info.
      *
      * @param symbols
      */
-    private ElfSymtab createELFSymbolTables(ArrayList<ElfSection> sections, Collection<Symbol> symbols) {
+    private static ElfSymtab createELFSymbolTables(Collection<Symbol> symbols) {
         ElfSymtab symtab = new ElfSymtab();
 
         // First, create the initial null symbol. This is a local symbol.
-        symtab.addSymbolEntry("", (byte)0, (byte)0, Elf64_Shdr.SHN_UNDEF, 0, 0);
+        symtab.addSymbolEntry("", (byte) 0, (byte) 0, Elf64_Shdr.SHN_UNDEF, 0, 0);
 
         // Now create ELF symbol entries for all symbols.
         for (Symbol symbol : symbols) {
             // Get the index of section this symbol is defined in.
             int secHdrIndex = symbol.getSection().getSectionId();
-            ElfSymbol elfSymbol = symtab.addSymbolEntry(symbol.getName(), getELFTypeOf(symbol), getELFBindOf(symbol), (byte)secHdrIndex, symbol.getOffset(), symbol.getSize());
-            symbol.setNativeSymbol((NativeSymbol)elfSymbol);
+            ElfSymbol elfSymbol = symtab.addSymbolEntry(symbol.getName(), getELFTypeOf(symbol), getELFBindOf(symbol), (byte) secHdrIndex, symbol.getOffset(), symbol.getSize());
+            symbol.setNativeSymbol(elfSymbol);
         }
         return (symtab);
     }
@@ -295,8 +277,7 @@
 
         ElfRelocTable elfRelocTable = new ElfRelocTable(sections.size());
         /*
-         * For each of the symbols with associated relocation records, create a Elf relocation
-         * entry.
+         * For each of the symbols with associated relocation records, create a Elf relocation entry.
          */
         for (Map.Entry<Symbol, List<Relocation>> entry : relocationTable.entrySet()) {
             List<Relocation> relocs = entry.getValue();
@@ -314,69 +295,39 @@
         return (elfRelocTable);
     }
 
-    private void createRelocation(Symbol symbol, Relocation reloc, ElfRelocTable elfRelocTable) {
+    private static void createRelocation(Symbol symbol, Relocation reloc, ElfRelocTable elfRelocTable) {
         RelocType relocType = reloc.getType();
 
         int elfRelocType = getELFRelocationType(relocType);
-        ElfSymbol sym = (ElfSymbol)symbol.getNativeSymbol();
+        ElfSymbol sym = (ElfSymbol) symbol.getNativeSymbol();
         int symno = sym.getIndex();
         int sectindex = reloc.getSection().getSectionId();
         int offset = reloc.getOffset();
         int addend = 0;
 
         switch (relocType) {
-            case FOREIGN_CALL_DIRECT:
             case JAVA_CALL_DIRECT:
             case STUB_CALL_DIRECT:
             case FOREIGN_CALL_INDIRECT_GOT: {
                 // Create relocation entry
-                // System.out.println("getELFRelocationType: PLT relocation type using X86_64_RELOC_BRANCH");
                 addend = -4; // Size in bytes of the patch location
                 // Relocation should be applied at the location after call operand
                 offset = offset + reloc.getSize() + addend;
                 break;
             }
-            case FOREIGN_CALL_DIRECT_FAR: {
-                // Create relocation entry
-                addend = -8; // Size in bytes of the patch location
-                // Relocation should be applied at the location after call operand
-                // 10 = 2 (jmp [r]) + 8 (imm64)
-                offset = offset + reloc.getSize() + addend - 2;
-                break;
-            }
-            case FOREIGN_CALL_INDIRECT:
             case JAVA_CALL_INDIRECT:
-            case STUB_CALL_INDIRECT: {
-                // Do nothing.
-                return;
-            }
-            case EXTERNAL_DATA_REFERENCE_FAR: {
-                // Create relocation entry
+            case METASPACE_GOT_REFERENCE:
+            case EXTERNAL_PLT_TO_GOT: {
                 addend = -4; // Size of 32-bit address of the GOT
                 /*
                  * Relocation should be applied before the test instruction to the move instruction.
-                 * offset points to the test instruction after the instruction that loads
-                 * the address of polling page. So set the offset appropriately.
+                 * reloc.getOffset() points to the test instruction after the instruction that loads the address of
+                 * polling page. So set the offset appropriately.
                  */
                 offset = offset + addend;
                 break;
             }
-            case METASPACE_GOT_REFERENCE:
-            case EXTERNAL_PLT_TO_GOT:
-            case STATIC_STUB_TO_STATIC_METHOD:
-            case STATIC_STUB_TO_HOTSPOT_LINKAGE_GOT: {
-                addend = -4; // Size of 32-bit address of the GOT
-                /*
-                 * Relocation should be applied before the test instruction to
-                 * the move instruction. reloc.getOffset() points to the
-                 * test instruction after the instruction that loads the
-                 * address of polling page. So set the offset appropriately.
-                 */
-                offset = offset + addend;
-                break;
-            }
-            case EXTERNAL_GOT_TO_PLT:
-            case LOADTIME_ADDRESS: {
+            case EXTERNAL_GOT_TO_PLT: {
                 // this is load time relocations
                 break;
             }
@@ -391,27 +342,17 @@
         switch (ElfTargetInfo.getElfArch()) {
             case Elf64_Ehdr.EM_X86_64:
                 // Return R_X86_64_* entries based on relocType
-                if (relocType == RelocType.FOREIGN_CALL_DIRECT ||
-                    relocType == RelocType.JAVA_CALL_DIRECT ||
+                if (relocType == RelocType.JAVA_CALL_DIRECT ||
                     relocType == RelocType.FOREIGN_CALL_INDIRECT_GOT) {
                     elfRelocType = Elf64_Rela.R_X86_64_PLT32;
                 } else if (relocType == RelocType.STUB_CALL_DIRECT) {
                     elfRelocType = Elf64_Rela.R_X86_64_PC32;
-                } else if (relocType == RelocType.FOREIGN_CALL_DIRECT_FAR) {
-                    elfRelocType = Elf64_Rela.R_X86_64_64;
-                } else if (relocType == RelocType.FOREIGN_CALL_INDIRECT ||
-                           relocType == RelocType.JAVA_CALL_INDIRECT ||
-                           relocType == RelocType.STUB_CALL_INDIRECT) {
+                } else if (relocType == RelocType.JAVA_CALL_INDIRECT) {
                     elfRelocType = Elf64_Rela.R_X86_64_NONE;
-                } else if ((relocType == RelocType.EXTERNAL_DATA_REFERENCE_FAR)) {
-                    elfRelocType = Elf64_Rela.R_X86_64_GOTPCREL;
                 } else if (relocType == RelocType.METASPACE_GOT_REFERENCE ||
-                           relocType == RelocType.EXTERNAL_PLT_TO_GOT ||
-                           relocType == RelocType.STATIC_STUB_TO_STATIC_METHOD ||
-                           relocType == RelocType.STATIC_STUB_TO_HOTSPOT_LINKAGE_GOT) {
+                           relocType == RelocType.EXTERNAL_PLT_TO_GOT) {
                     elfRelocType = Elf64_Rela.R_X86_64_PC32;
-                } else if (relocType == RelocType.EXTERNAL_GOT_TO_PLT ||
-                           relocType == RelocType.LOADTIME_ADDRESS) {
+                } else if (relocType == RelocType.EXTERNAL_GOT_TO_PLT) {
                     elfRelocType = Elf64_Rela.R_X86_64_64;
                 } else {
                     assert false : "Unhandled relocation type: " + relocType;
@@ -423,9 +364,9 @@
         return elfRelocType;
     }
 
-    private void createElfRelocSections(ArrayList<ElfSection> sections,
-                                        ElfRelocTable elfRelocTable,
-                                        int symtabsectidx) {
+    private static void createElfRelocSections(ArrayList<ElfSection> sections,
+                                               ElfRelocTable elfRelocTable,
+                                               int symtabsectidx) {
 
         // Grab count before we create new sections
         int count = sections.size();
@@ -434,12 +375,9 @@
             if (elfRelocTable.getNumRelocs(i) > 0) {
                 ElfSection sect = sections.get(i);
                 String relname = ".rela" + sect.getName();
-                ElfSection relocSection = createByteSection(sections,
-                                                            relname,
+                ElfSection relocSection = createByteSection(sections, relname,
                                                             elfRelocTable.getRelocData(i),
-                                                            false,
-                                                            0,
-                                                            Elf64_Shdr.SHT_RELA);
+                                                            false, 8, 0, Elf64_Shdr.SHT_RELA);
                 relocSection.setLink(symtabsectidx);
                 relocSection.setInfo(sect.getSectionId());
             }
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/JMachORelocObject.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/JMachORelocObject.java	Wed Sep 20 23:55:35 2017 -0400
@@ -53,11 +53,8 @@
 import jdk.tools.jaotc.binformat.Relocation;
 import jdk.tools.jaotc.binformat.Relocation.RelocType;
 import jdk.tools.jaotc.binformat.Symbol;
-import jdk.tools.jaotc.binformat.NativeSymbol;
-import jdk.tools.jaotc.binformat.Symbol.Binding;
 import jdk.tools.jaotc.binformat.Symbol.Kind;
 
-import jdk.tools.jaotc.binformat.macho.MachO;
 import jdk.tools.jaotc.binformat.macho.MachO.section_64;
 import jdk.tools.jaotc.binformat.macho.MachO.mach_header_64;
 import jdk.tools.jaotc.binformat.macho.MachO.segment_command_64;
@@ -85,7 +82,7 @@
         this.segmentSize = binContainer.getCodeSegmentSize();
     }
 
-    private void createByteSection(ArrayList<MachOSection>sections,
+    private void createByteSection(ArrayList<MachOSection> sections,
                                    ByteContainer c, String sectName, String segName, int scnFlags) {
 
         if (c.getByteArray().length == 0) {
@@ -96,29 +93,30 @@
                                              segName,
                                              c.getByteArray(),
                                              scnFlags,
-                                             c.hasRelocations());
+                                             c.hasRelocations(),
+                                             segmentSize);
         // Add this section to our list
         sections.add(sect);
 
         // Record the section Id (0 relative)
-        c.setSectionId(sections.size()-1);
+        c.setSectionId(sections.size() - 1);
 
         // TODO: Clear out code section data to allow for GC
         // c.clear();
     }
 
-    private void createCodeSection(ArrayList<MachOSection>sections, CodeContainer c) {
-        createByteSection(sections, c, /*c.getContainerName()*/ "__text", "__TEXT",
-                          section_64.S_ATTR_PURE_INSTRUCTIONS|
+    private void createCodeSection(ArrayList<MachOSection> sections, CodeContainer c) {
+        createByteSection(sections, c, /* c.getContainerName() */ "__text", "__TEXT",
+                          section_64.S_ATTR_PURE_INSTRUCTIONS |
                           section_64.S_ATTR_SOME_INSTRUCTIONS);
     }
 
-    private void createReadOnlySection(ArrayList<MachOSection>sections, ReadOnlyDataContainer c) {
+    private void createReadOnlySection(ArrayList<MachOSection> sections, ReadOnlyDataContainer c) {
         createByteSection(sections, c, c.getContainerName(), "__TEXT",
                           section_64.S_ATTR_SOME_INSTRUCTIONS);
     }
 
-    private void createReadWriteSection(ArrayList<MachOSection>sections, ByteContainer c) {
+    private void createReadWriteSection(ArrayList<MachOSection> sections, ByteContainer c) {
         createByteSection(sections, c, c.getContainerName(), "__DATA", section_64.S_REGULAR);
     }
 
@@ -139,7 +137,7 @@
 
         MachOHeader mh = new MachOHeader();
 
-        ArrayList<MachOSection> sections = new ArrayList<MachOSection>();
+        ArrayList<MachOSection> sections = new ArrayList<>();
 
         // Create Sections contained in the main Segment LC_SEGMENT_64
 
@@ -148,21 +146,19 @@
         createReadOnlySection(sections, binContainer.getKlassesOffsetsContainer());
         createReadOnlySection(sections, binContainer.getMethodsOffsetsContainer());
         createReadOnlySection(sections, binContainer.getKlassesDependenciesContainer());
-        createReadWriteSection(sections, binContainer.getMetaspaceGotContainer());
-        createReadWriteSection(sections, binContainer.getMetadataGotContainer());
-        createReadWriteSection(sections, binContainer.getMethodStateContainer());
-        createReadWriteSection(sections, binContainer.getOopGotContainer());
-        createReadWriteSection(sections, binContainer.getMethodMetadataContainer());
+        createReadOnlySection(sections, binContainer.getMethodMetadataContainer());
         createReadOnlySection(sections, binContainer.getStubsOffsetsContainer());
         createReadOnlySection(sections, binContainer.getHeaderContainer().getContainer());
         createReadOnlySection(sections, binContainer.getCodeSegmentsContainer());
         createReadOnlySection(sections, binContainer.getConstantDataContainer());
         createReadOnlySection(sections, binContainer.getConfigContainer());
+        createReadWriteSection(sections, binContainer.getKlassesGotContainer());
+        createReadWriteSection(sections, binContainer.getCountersGotContainer());
+        createReadWriteSection(sections, binContainer.getMetadataGotContainer());
+        createReadWriteSection(sections, binContainer.getMethodStateContainer());
+        createReadWriteSection(sections, binContainer.getOopGotContainer());
+        createReadWriteSection(sections, binContainer.getExtLinkageGOTContainer());
 
-        // createExternalLinkage();
-
-        createCodeSection(sections, binContainer.getExtLinkageContainer());
-        createReadWriteSection(sections, binContainer.getExtLinkageGOTContainer());
         // Update the Header sizeofcmds size.
         // This doesn't include the Header struct size
         mh.setCmdSizes(4, segment_command_64.totalsize +
@@ -174,14 +170,14 @@
         // Initialize file offset for data past commands
         int file_offset = mach_header_64.totalsize + mh.getCmdSize();
         // and round it up
-        file_offset = (file_offset + (sections.get(0).getAlign()-1)) & ~((sections.get(0).getAlign()-1));
+        file_offset = (file_offset + (sections.get(0).getAlign() - 1)) & ~((sections.get(0).getAlign() - 1));
         long address = 0;
         int segment_offset = file_offset;
 
         for (int i = 0; i < sections.size(); i++) {
             MachOSection sect = sections.get(i);
-            file_offset = (file_offset + (sect.getAlign()-1)) & ~((sect.getAlign()-1));
-            address = (address + (sect.getAlign()-1)) & ~((sect.getAlign()-1));
+            file_offset = (file_offset + (sect.getAlign() - 1)) & ~((sect.getAlign() - 1));
+            address = (address + (sect.getAlign() - 1)) & ~((sect.getAlign() - 1));
             sect.setOffset(file_offset);
             sect.setAddr(address);
             file_offset += sect.getSize();
@@ -198,7 +194,6 @@
                                             segment_size,
                                             sections.size());
 
-
         MachOVersion vers = new MachOVersion();
 
         // Get symbol data from BinaryContainer object's symbol tables
@@ -212,7 +207,7 @@
         // Create the Relocation Tables
         MachORelocTable machORelocs = createMachORelocTable(sections, relocationTable, symtab);
         // Calculate file offset for relocation data
-        file_offset = (file_offset + (machORelocs.getAlign()-1)) & ~((machORelocs.getAlign()-1));
+        file_offset = (file_offset + (MachORelocTable.getAlign() - 1)) & ~((MachORelocTable.getAlign() - 1));
 
         // Update relocation sizing information in each section
         for (int i = 0; i < sections.size(); i++) {
@@ -226,10 +221,9 @@
         }
 
         // Calculate and set file offset for symbol table data
-        file_offset = (file_offset + (symtab.getAlign()-1)) & ~((symtab.getAlign()-1));
+        file_offset = (file_offset + (MachOSymtab.getAlign() - 1)) & ~((MachOSymtab.getAlign() - 1));
         symtab.setOffset(file_offset);
 
-
         // Write Out Header
         machoContainer.writeBytes(mh.getArray());
         // Write out first Segment
@@ -258,12 +252,13 @@
 
         // Write out the relocation tables for all sections
         for (int i = 0; i < sections.size(); i++) {
-            if (machORelocs.getNumRelocs(i) > 0)
-                machoContainer.writeBytes(machORelocs.getRelocData(i), machORelocs.getAlign());
+            if (machORelocs.getNumRelocs(i) > 0) {
+                machoContainer.writeBytes(machORelocs.getRelocData(i), MachORelocTable.getAlign());
+            }
         }
 
         // Write out data associated with LC_SYMTAB
-        machoContainer.writeBytes(symtab.getDataArray(), symtab.getAlign());
+        machoContainer.writeBytes(symtab.getDataArray(), MachOSymtab.getAlign());
 
         machoContainer.close();
     }
@@ -272,14 +267,14 @@
      * Construct MachO symbol data from BinaryContainer object's symbol tables. Both dynamic MachO
      * symbol table and MachO symbol table are created from BinaryContainer's symbol info.
      *
+     * @param sections
      * @param symbols
-     * @param symtab
      */
-    private MachOSymtab createMachOSymbolTables(ArrayList<MachOSection>sections,
-                                         Collection<Symbol> symbols) {
+    private static MachOSymtab createMachOSymbolTables(ArrayList<MachOSection> sections,
+                                                       Collection<Symbol> symbols) {
         MachOSymtab symtab = new MachOSymtab();
         // First, create the initial null symbol. This is a local symbol.
-        symtab.addSymbolEntry("", (byte)nlist_64.N_UNDF, (byte)0, (long)0);
+        symtab.addSymbolEntry("", (byte) nlist_64.N_UNDF, (byte) 0, 0);
 
         // Now create MachO symbol entries for all symbols.
         for (Symbol symbol : symbols) {
@@ -289,14 +284,14 @@
             long sectionAddr = sections.get(sectionId).getAddr();
 
             MachOSymbol machoSymbol = symtab.addSymbolEntry(symbol.getName(),
-                                         getMachOTypeOf(symbol),
-                                         (byte)sectionId,
-                                         symbol.getOffset() + sectionAddr);
-            symbol.setNativeSymbol((NativeSymbol)machoSymbol);
+                                                            getMachOTypeOf(symbol),
+                                                            (byte) sectionId,
+                                                            symbol.getOffset() + sectionAddr);
+            symbol.setNativeSymbol(machoSymbol);
         }
 
         // Now that all symbols are enterred, update the
-        // symbol indexes.  This is necessary since they will
+        // symbol indexes. This is necessary since they will
         // be reordered based on local, global and undefined.
         symtab.updateIndexes();
 
@@ -308,9 +303,9 @@
         byte type = nlist_64.N_UNDF;
 
         // Global or Local
-        if (sym.getBinding() == Symbol.Binding.GLOBAL)
+        if (sym.getBinding() == Symbol.Binding.GLOBAL) {
             type = nlist_64.N_EXT;
-
+        }
         // If Function or Data, add section type
         if (kind == Symbol.Kind.NATIVE_FUNCTION ||
             kind == Symbol.Kind.JAVA_FUNCTION   ||
@@ -334,8 +329,7 @@
 
         MachORelocTable machORelocTable = new MachORelocTable(sections.size());
         /*
-         * For each of the symbols with associated relocation records, create a MachO relocation
-         * entry.
+         * For each of the symbols with associated relocation records, create a MachO relocation entry.
          */
         for (Map.Entry<Symbol, List<Relocation>> entry : relocationTable.entrySet()) {
             List<Relocation> relocs = entry.getValue();
@@ -353,11 +347,11 @@
         return (machORelocTable);
     }
 
-    private void createRelocation(Symbol symbol, Relocation reloc, MachORelocTable machORelocTable) {
+    private static void createRelocation(Symbol symbol, Relocation reloc, MachORelocTable machORelocTable) {
         RelocType relocType = reloc.getType();
 
         int machORelocType = getMachORelocationType(relocType);
-        MachOSymbol sym = (MachOSymbol)symbol.getNativeSymbol();
+        MachOSymbol sym = (MachOSymbol) symbol.getNativeSymbol();
         int symno = sym.getIndex();
         int sectindex = reloc.getSection().getSectionId();
         int offset = reloc.getOffset();
@@ -365,73 +359,39 @@
         int length = 0;
         int isextern = 1;
 
-/*
-        System.out.println("reloctype: " + relocType + " size is " +
-                            reloc.getSize() + " offset is " + offset +
-                            " Section Index is " + (sectindex) +
-                            " Symbol Index is " + symno +
-                            " Symbol Name is " + symbol.getName() + "\n");
-*/
-
         switch (relocType) {
-            case FOREIGN_CALL_DIRECT:
             case JAVA_CALL_DIRECT:
             case STUB_CALL_DIRECT:
             case FOREIGN_CALL_INDIRECT_GOT: {
                 // Create relocation entry
-                // System.out.println("getMachORelocationType: PLT relocation type using X86_64_RELOC_BRANCH");
                 int addend = -4; // Size in bytes of the patch location
                 // Relocation should be applied at the location after call operand
                 offset = offset + reloc.getSize() + addend;
-                pcrel = 1; length = 2;
+                pcrel = 1;
+                length = 2;
                 break;
             }
-            case FOREIGN_CALL_DIRECT_FAR: {
-                // Create relocation entry
-                int addend = -8; // Size in bytes of the patch location
-                // Relocation should be applied at the location after call operand
-                // 10 = 2 (jmp [r]) + 8 (imm64)
-                offset = offset + reloc.getSize() + addend - 2;
-                pcrel = 0; length = 3;
-                break;
-            }
-            case FOREIGN_CALL_INDIRECT:
-            case JAVA_CALL_INDIRECT:
-            case STUB_CALL_INDIRECT: {
+            case JAVA_CALL_INDIRECT: {
                 // Do nothing.
                 return;
             }
-            case EXTERNAL_DATA_REFERENCE_FAR: {
-                // Create relocation entry
+            case METASPACE_GOT_REFERENCE:
+            case EXTERNAL_PLT_TO_GOT: {
                 int addend = -4; // Size of 32-bit address of the GOT
                 /*
                  * Relocation should be applied before the test instruction to the move instruction.
-                 * offset points to the test instruction after the instruction that loads
-                 * the address of polling page. So set the offset appropriately.
+                 * reloc.getOffset() points to the test instruction after the instruction that loads the address of
+                 * polling page. So set the offset appropriately.
                  */
                 offset = offset + addend;
-                pcrel = 0; length = 2;
+                pcrel = 1;
+                length = 2;
                 break;
             }
-            case METASPACE_GOT_REFERENCE:
-            case EXTERNAL_PLT_TO_GOT:
-            case STATIC_STUB_TO_STATIC_METHOD:
-            case STATIC_STUB_TO_HOTSPOT_LINKAGE_GOT: {
-                int addend = -4; // Size of 32-bit address of the GOT
-                /*
-                 * Relocation should be applied before the test instruction to
-                 * the move instruction. reloc.getOffset() points to the
-                 * test instruction after the instruction that loads the
-                 * address of polling page. So set the offset appropriately.
-                 */
-                offset = offset + addend;
-                pcrel = 1; length = 2;
-                break;
-            }
-            case EXTERNAL_GOT_TO_PLT:
-            case LOADTIME_ADDRESS: {
+            case EXTERNAL_GOT_TO_PLT: {
                 // this is load time relocations
-                pcrel = 0; length = 3;
+                pcrel = 0;
+                length = 3;
                 break;
             }
             default:
@@ -447,20 +407,17 @@
         switch (MachOTargetInfo.getMachOArch()) {
             case mach_header_64.CPU_TYPE_X86_64:
                 // Return X86_64_RELOC_* entries based on relocType
-                if (relocType == RelocType.FOREIGN_CALL_DIRECT || relocType == RelocType.JAVA_CALL_DIRECT || relocType == RelocType.FOREIGN_CALL_INDIRECT_GOT) {
+                if (relocType == RelocType.JAVA_CALL_DIRECT ||
+                    relocType == RelocType.FOREIGN_CALL_INDIRECT_GOT) {
                     machORelocType = reloc_info.X86_64_RELOC_BRANCH;
                 } else if (relocType == RelocType.STUB_CALL_DIRECT) {
                     machORelocType = reloc_info.X86_64_RELOC_BRANCH;
-                } else if (relocType == RelocType.FOREIGN_CALL_DIRECT_FAR) {
-                    machORelocType = reloc_info.X86_64_RELOC_UNSIGNED;
-                } else if (relocType == RelocType.FOREIGN_CALL_INDIRECT || relocType == RelocType.JAVA_CALL_INDIRECT || relocType == RelocType.STUB_CALL_INDIRECT) {
+                } else if (relocType == RelocType.JAVA_CALL_INDIRECT) {
                     machORelocType = reloc_info.X86_64_RELOC_NONE;
-                } else if ((relocType == RelocType.EXTERNAL_DATA_REFERENCE_FAR)) {
-                    machORelocType = reloc_info.X86_64_RELOC_GOT;
-                } else if (relocType == RelocType.METASPACE_GOT_REFERENCE || relocType == RelocType.EXTERNAL_PLT_TO_GOT || relocType == RelocType.STATIC_STUB_TO_STATIC_METHOD ||
-                                relocType == RelocType.STATIC_STUB_TO_HOTSPOT_LINKAGE_GOT) {
+                } else if (relocType == RelocType.METASPACE_GOT_REFERENCE ||
+                           relocType == RelocType.EXTERNAL_PLT_TO_GOT) {
                     machORelocType = reloc_info.X86_64_RELOC_BRANCH;
-                } else if (relocType == RelocType.EXTERNAL_GOT_TO_PLT || relocType == RelocType.LOADTIME_ADDRESS) {
+                } else if (relocType == RelocType.EXTERNAL_GOT_TO_PLT) {
                     machORelocType = reloc_info.X86_64_RELOC_UNSIGNED;
                 } else {
                     assert false : "Unhandled relocation type: " + relocType;
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachO.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachO.java	Wed Sep 20 23:55:35 2017 -0400
@@ -23,10 +23,10 @@
 
 package jdk.tools.jaotc.binformat.macho;
 
+//@formatter:off
 /**
  *
- * Support for the creation of Mach-o Object files.
- * Current support is limited to 64 bit x86_64.
+ * Support for the creation of Mach-o Object files. Current support is limited to 64 bit x86_64.
  *
  * File Format Overview:
  *
@@ -38,12 +38,12 @@
  *      (which each include multiple Sections)
  */
 
-public class MachO {
+final class MachO {
 
     /**
      * mach_header_64 structure defines
      */
-    public enum mach_header_64 {
+    enum mach_header_64 {
                  magic( 0, 4),
                cputype( 4, 4),
             cpusubtype( 8, 4),
@@ -53,49 +53,49 @@
                  flags(24, 4),
               reserved(28, 4);
 
-        public final int off;
-        public final int sz;
+        final int off;
+        final int sz;
 
         mach_header_64(int offset, int size) {
             this.off = offset;
             this.sz = size;
         }
 
-        public static int totalsize = 32;
+        static int totalsize = 32;
 
         /**
          * mach_header_64 defines
          */
-        public static final int MH_MAGIC                   = 0xfeedface;
-        public static final int MH_MAGIC_64                = 0xfeedfacf;
-        public static final int MH_SUBSECTIONS_VIA_SYMBOLS = 0x2000;
+        static final int MH_MAGIC                   = 0xfeedface;
+        static final int MH_MAGIC_64                = 0xfeedfacf;
+        static final int MH_SUBSECTIONS_VIA_SYMBOLS = 0x2000;
 
         /**
          * filetype
          */
-        public static final int MH_OBJECT = 0x1;
+        static final int MH_OBJECT = 0x1;
 
         /**
          * cputype
          */
-        public static final int CPU_TYPE_ANY              = -1;
-        public static final int CPU_ARCH_ABI64            = 0x1000000;
-        public static final int CPU_TYPE_X86_64           = 0x1000007;
-        public static final int CPU_TYPE_ARM64            = 0x100000c;
+        static final int CPU_TYPE_ANY              = -1;
+        static final int CPU_ARCH_ABI64            = 0x1000000;
+        static final int CPU_TYPE_X86_64           = 0x1000007;
+        static final int CPU_TYPE_ARM64            = 0x100000c;
         /**
          * cpusubtype
          */
-        public static final int CPU_SUBTYPE_I386_ALL      = 3;
-        public static final int CPU_SUBTYPE_ARM64_ALL     = 0;
-        public static final int CPU_SUBTYPE_LITTLE_ENDIAN = 0;
-        public static final int CPU_SUBTYPE_BIG_ENDIAN    = 1;
+        static final int CPU_SUBTYPE_I386_ALL      = 3;
+        static final int CPU_SUBTYPE_ARM64_ALL     = 0;
+        static final int CPU_SUBTYPE_LITTLE_ENDIAN = 0;
+        static final int CPU_SUBTYPE_BIG_ENDIAN    = 1;
 
     }
 
     /**
      * segment_command_64 structure defines
      */
-    public enum segment_command_64 {
+    enum segment_command_64 {
                    cmd( 0, 4),
                cmdsize( 4, 4),
                segname( 8,16),
@@ -108,23 +108,23 @@
                 nsects(64, 4),
                  flags(68, 4);
 
-        public final int off;
-        public final int sz;
+        final int off;
+        final int sz;
 
         segment_command_64(int offset, int size) {
             this.off = offset;
             this.sz = size;
         }
 
-        public static int totalsize = 72;
+        static int totalsize = 72;
 
-        public static final int LC_SEGMENT_64           = 0x19;
+        static final int LC_SEGMENT_64           = 0x19;
     }
 
     /**
      * section_64 structure defines
      */
-    public enum section_64 {
+    enum section_64 {
               sectname( 0,16),
                segname(16,16),
                   addr(32, 8),
@@ -138,49 +138,49 @@
              reserved2(72, 4),
              reserved3(76, 4);
 
-        public final int off;
-        public final int sz;
+        final int off;
+        final int sz;
 
         section_64(int offset, int size) {
             this.off = offset;
             this.sz = size;
         }
 
-        public static int totalsize = 80;
+        static int totalsize = 80;
 
-        public static int S_REGULAR                = 0x0;
-        public static int S_CSTRING_LITERALS       = 0x2;
-        public static int S_ATTR_PURE_INSTRUCTIONS = 0x80000000;
-        public static int S_ATTR_SOME_INSTRUCTIONS = 0x400;
+        static int S_REGULAR                = 0x0;
+        static int S_CSTRING_LITERALS       = 0x2;
+        static int S_ATTR_PURE_INSTRUCTIONS = 0x80000000;
+        static int S_ATTR_SOME_INSTRUCTIONS = 0x400;
     }
 
     /**
      * version_min_command structure defines
      */
-    public enum version_min_command {
+    enum version_min_command {
                    cmd( 0, 4),
                cmdsize( 4, 4),
                version( 8, 4),
                    sdk(12, 4);
 
-        public final int off;
-        public final int sz;
+        final int off;
+        final int sz;
 
         version_min_command(int offset, int size) {
             this.off = offset;
             this.sz = size;
         }
 
-        public static int totalsize = 16;
+        static int totalsize = 16;
 
-        public static final int LC_VERSION_MIN_MACOSX   = 0x24;
-        public static final int LC_VERSION_MIN_IPHONEOS = 0x25;
+        static final int LC_VERSION_MIN_MACOSX   = 0x24;
+        static final int LC_VERSION_MIN_IPHONEOS = 0x25;
     }
 
     /**
      * symtab_command structure defines
      */
-    public enum symtab_command {
+    enum symtab_command {
                    cmd( 0, 4),
                cmdsize( 4, 4),
                 symoff( 8, 4),
@@ -188,17 +188,17 @@
                 stroff(16, 4),
                strsize(20, 4);
 
-        public final int off;
-        public final int sz;
+        final int off;
+        final int sz;
 
         symtab_command(int offset, int size) {
             this.off = offset;
             this.sz = size;
         }
 
-        public static int totalsize = 24;
+        static int totalsize = 24;
 
-        public static final int LC_SYMTAB               = 0x2;
+        static final int LC_SYMTAB               = 0x2;
     }
 
     /**
@@ -206,33 +206,33 @@
      *
      * nlist_64 structure defines
      */
-    public enum nlist_64 {
+    enum nlist_64 {
                 n_strx( 0, 4),
                 n_type( 4, 1),
                 n_sect( 5, 1),
                 n_desc( 6, 2),
                n_value( 8, 8);
 
-        public final int off;
-        public final int sz;
+        final int off;
+        final int sz;
 
         nlist_64(int offset, int size) {
             this.off = offset;
             this.sz = size;
         }
 
-        public static int totalsize = 16;
+        static int totalsize = 16;
 
-        public static final int N_EXT                = 0x1;
-        public static final int N_TYPE               = 0xe;
-        public static final int N_UNDF               = 0x0;
-        public static final int N_SECT               = 0xe;
+        static final int N_EXT                = 0x1;
+        static final int N_TYPE               = 0xe;
+        static final int N_UNDF               = 0x0;
+        static final int N_SECT               = 0xe;
     }
 
     /**
      * dysymtab_command structure defines
      */
-    public enum dysymtab_command {
+    enum dysymtab_command {
                    cmd( 0, 4),
                cmdsize( 4, 4),
              ilocalsym( 8, 4),
@@ -254,54 +254,55 @@
              locreloff(72, 4),
                nlocrel(76, 4);
 
-        public final int off;
-        public final int sz;
+        final int off;
+        final int sz;
 
         dysymtab_command(int offset, int size) {
             this.off = offset;
             this.sz = size;
         }
 
-        public static int totalsize = 80;
+        static int totalsize = 80;
 
-        public static final int LC_DYSYMTAB             = 0xb;
+        static final int LC_DYSYMTAB             = 0xb;
     }
 
     /**
      * relocation_info structure defines
      */
-    public enum reloc_info {
+    enum reloc_info {
              r_address( 0, 4),
            r_relocinfo( 4, 4);
 
-        public final int off;
-        public final int sz;
+        final int off;
+        final int sz;
 
         reloc_info(int offset, int size) {
             this.off = offset;
             this.sz = size;
         }
 
-        public static int totalsize = 8;
+        static int totalsize = 8;
 
-        public static final int REL_SYMNUM_MASK         = 0xffffff;
-        public static final int REL_SYMNUM_SHIFT        = 0x0;
-        public static final int REL_PCREL_MASK          = 0x1;
-        public static final int REL_PCREL_SHIFT         = 0x18;
-        public static final int REL_LENGTH_MASK         = 0x3;
-        public static final int REL_LENGTH_SHIFT        = 0x19;
-        public static final int REL_EXTERN_MASK         = 0x1;
-        public static final int REL_EXTERN_SHIFT        = 0x1b;
-        public static final int REL_TYPE_MASK           = 0xf;
-        public static final int REL_TYPE_SHIFT          = 0x1c;
+        static final int REL_SYMNUM_MASK         = 0xffffff;
+        static final int REL_SYMNUM_SHIFT        = 0x0;
+        static final int REL_PCREL_MASK          = 0x1;
+        static final int REL_PCREL_SHIFT         = 0x18;
+        static final int REL_LENGTH_MASK         = 0x3;
+        static final int REL_LENGTH_SHIFT        = 0x19;
+        static final int REL_EXTERN_MASK         = 0x1;
+        static final int REL_EXTERN_SHIFT        = 0x1b;
+        static final int REL_TYPE_MASK           = 0xf;
+        static final int REL_TYPE_SHIFT          = 0x1c;
 
         /* reloc_type_x86_64 defines */
 
-        public static final int X86_64_RELOC_NONE      = 0x0;
-        public static final int X86_64_RELOC_BRANCH    = 0x2;
-        public static final int X86_64_RELOC_GOT       = 0x4;
-        public static final int X86_64_RELOC_GOT_LOAD  = 0x3;
-        public static final int X86_64_RELOC_SIGNED    = 0x1;
-        public static final int X86_64_RELOC_UNSIGNED  = 0x0;
+        static final int X86_64_RELOC_NONE      = 0x0;
+        static final int X86_64_RELOC_BRANCH    = 0x2;
+        static final int X86_64_RELOC_GOT       = 0x4;
+        static final int X86_64_RELOC_GOT_LOAD  = 0x3;
+        static final int X86_64_RELOC_SIGNED    = 0x1;
+        static final int X86_64_RELOC_UNSIGNED  = 0x0;
     }
 }
+//@formatter:on
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOByteBuffer.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOByteBuffer.java	Wed Sep 20 23:55:35 2017 -0400
@@ -23,21 +23,19 @@
 
 package jdk.tools.jaotc.binformat.macho;
 
-
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
 import jdk.tools.jaotc.binformat.macho.MachOTargetInfo;
-import jdk.tools.jaotc.binformat.macho.MachO.mach_header_64;
 
-public class MachOByteBuffer {
+final class MachOByteBuffer {
 
-    public static ByteBuffer allocate(int size) {
+    static ByteBuffer allocate(int size) {
         ByteBuffer buf = ByteBuffer.allocate(size);
-        if (MachOTargetInfo.getMachOEndian() ==
-            MachO.mach_header_64.CPU_SUBTYPE_LITTLE_ENDIAN)
+        if (MachOTargetInfo.getMachOEndian() == MachO.mach_header_64.CPU_SUBTYPE_LITTLE_ENDIAN) {
             buf.order(ByteOrder.LITTLE_ENDIAN);
-        else
+        } else {
             buf.order(ByteOrder.BIG_ENDIAN);
+        }
         return (buf);
     }
 
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOContainer.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOContainer.java	Wed Sep 20 23:55:35 2017 -0400
@@ -26,14 +26,13 @@
 import java.io.File;
 import java.io.FileOutputStream;
 
-public class MachOContainer {
+final class MachOContainer {
 
-    File outputFile;
-    FileOutputStream outputStream;
-    long fileOffset;
+    private final File outputFile;
+    private FileOutputStream outputStream;
+    private long fileOffset;
 
-    public MachOContainer(String fileName) {
-        String baseName;
+    MachOContainer(String fileName) {
 
         outputFile = new File(fileName);
         if (outputFile.exists()) {
@@ -48,7 +47,7 @@
         fileOffset = 0;
     }
 
-    public void close() {
+    void close() {
         try {
             outputStream.close();
         } catch (Exception e) {
@@ -56,7 +55,7 @@
         }
     }
 
-    public void writeBytes(byte [] bytes) {
+    void writeBytes(byte[] bytes) {
         try {
             outputStream.write(bytes);
         } catch (Exception e) {
@@ -66,10 +65,10 @@
     }
 
     // Write bytes to output file with up front alignment padding
-    public void writeBytes(byte [] bytes, int alignment) {
+    void writeBytes(byte[] bytes, int alignment) {
         try {
             // Pad to alignment
-            while ((fileOffset & (long)(alignment-1)) != 0) {
+            while ((fileOffset & (alignment - 1)) != 0) {
                 outputStream.write(0);
                 fileOffset++;
             }
@@ -80,4 +79,3 @@
         fileOffset += bytes.length;
     }
 }
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachODySymtab.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachODySymtab.java	Wed Sep 20 23:55:35 2017 -0400
@@ -24,16 +24,14 @@
 package jdk.tools.jaotc.binformat.macho;
 
 import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
 
-import jdk.tools.jaotc.binformat.macho.MachO;
 import jdk.tools.jaotc.binformat.macho.MachO.dysymtab_command;
 import jdk.tools.jaotc.binformat.macho.MachOByteBuffer;
 
-public class MachODySymtab {
-    ByteBuffer dysymtab;
+final class MachODySymtab {
+    private final ByteBuffer dysymtab;
 
-    public MachODySymtab(int nlocal, int nglobal, int nundef) {
+    MachODySymtab(int nlocal, int nglobal, int nundef) {
         dysymtab = MachOByteBuffer.allocate(dysymtab_command.totalsize);
 
         dysymtab.putInt(dysymtab_command.cmd.off, dysymtab_command.LC_DYSYMTAB);
@@ -42,13 +40,11 @@
         dysymtab.putInt(dysymtab_command.nlocalsym.off, nlocal);
         dysymtab.putInt(dysymtab_command.iextdefsym.off, nlocal);
         dysymtab.putInt(dysymtab_command.nextdefsym.off, nglobal);
-        dysymtab.putInt(dysymtab_command.iundefsym.off, nlocal+nglobal);
+        dysymtab.putInt(dysymtab_command.iundefsym.off, nlocal + nglobal);
         dysymtab.putInt(dysymtab_command.nundefsym.off, nundef);
     }
 
-    public byte[] getArray() {
+    byte[] getArray() {
         return dysymtab.array();
     }
 }
-
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOHeader.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOHeader.java	Wed Sep 20 23:55:35 2017 -0400
@@ -24,17 +24,15 @@
 package jdk.tools.jaotc.binformat.macho;
 
 import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
 
-import jdk.tools.jaotc.binformat.macho.MachO;
 import jdk.tools.jaotc.binformat.macho.MachO.mach_header_64;
 import jdk.tools.jaotc.binformat.macho.MachOTargetInfo;
 import jdk.tools.jaotc.binformat.macho.MachOByteBuffer;
 
-public class MachOHeader {
-    ByteBuffer header;
+final class MachOHeader {
+    private final ByteBuffer header;
 
-    public MachOHeader() {
+    MachOHeader() {
         header = MachOByteBuffer.allocate(mach_header_64.totalsize);
 
         header.putInt(mach_header_64.magic.off, mach_header_64.MH_MAGIC_64);
@@ -44,17 +42,16 @@
         header.putInt(mach_header_64.filetype.off, mach_header_64.MH_OBJECT);
     }
 
-    public void setCmdSizes(int ncmds, int sizeofcmds) {
+    void setCmdSizes(int ncmds, int sizeofcmds) {
         header.putInt(mach_header_64.ncmds.off, ncmds);
         header.putInt(mach_header_64.sizeofcmds.off, sizeofcmds);
     }
 
-    public int getCmdSize() {
+    int getCmdSize() {
         return (header.getInt(mach_header_64.sizeofcmds.off));
     }
 
-    public byte[] getArray() {
+    byte[] getArray() {
         return header.array();
     }
 }
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachORelocEntry.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachORelocEntry.java	Wed Sep 20 23:55:35 2017 -0400
@@ -24,42 +24,31 @@
 package jdk.tools.jaotc.binformat.macho;
 
 import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
 
-import jdk.tools.jaotc.binformat.macho.MachO;
 import jdk.tools.jaotc.binformat.macho.MachO.reloc_info;
 import jdk.tools.jaotc.binformat.macho.MachOByteBuffer;
 
-public class MachORelocEntry {
-    ByteBuffer entry;
+final class MachORelocEntry {
+    private final ByteBuffer entry;
 
-    public MachORelocEntry(int offset,
-                           int symno,
-                           int pcrel,
-                           int length,
-                           int isextern,
-                           int type) {
+    MachORelocEntry(int offset, int symno, int pcrel, int length, int isextern, int type) {
 
         entry = MachOByteBuffer.allocate(reloc_info.totalsize);
 
         entry.putInt(reloc_info.r_address.off, offset);
 
         // Encode and store the relocation entry bitfields
+        // @formatter:off
         entry.putInt(reloc_info.r_relocinfo.off,
-            ((symno & reloc_info.REL_SYMNUM_MASK)
-             << reloc_info.REL_SYMNUM_SHIFT) |
-            ((pcrel & reloc_info.REL_PCREL_MASK)
-             << reloc_info.REL_PCREL_SHIFT) |
-            ((length & reloc_info.REL_LENGTH_MASK)
-             << reloc_info.REL_LENGTH_SHIFT) |
-            ((isextern & reloc_info.REL_EXTERN_MASK)
-             << reloc_info.REL_EXTERN_SHIFT) |
-            ((type & reloc_info.REL_TYPE_MASK)
-             << reloc_info.REL_TYPE_SHIFT));
+            ((symno    & reloc_info.REL_SYMNUM_MASK) << reloc_info.REL_SYMNUM_SHIFT) |
+            ((pcrel    & reloc_info.REL_PCREL_MASK)  << reloc_info.REL_PCREL_SHIFT)  |
+            ((length   & reloc_info.REL_LENGTH_MASK) << reloc_info.REL_LENGTH_SHIFT) |
+            ((isextern & reloc_info.REL_EXTERN_MASK) << reloc_info.REL_EXTERN_SHIFT) |
+            ((type     & reloc_info.REL_TYPE_MASK)   << reloc_info.REL_TYPE_SHIFT));
+        // @formatter:on
     }
 
-    public byte[] getArray() {
+    byte[] getArray() {
         return entry.array();
     }
 }
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachORelocTable.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachORelocTable.java	Wed Sep 20 23:55:35 2017 -0400
@@ -25,56 +25,43 @@
 
 import java.util.ArrayList;
 import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
 
 import jdk.tools.jaotc.binformat.macho.MachORelocEntry;
-import jdk.tools.jaotc.binformat.macho.MachOTargetInfo;
 import jdk.tools.jaotc.binformat.macho.MachO.reloc_info;
 import jdk.tools.jaotc.binformat.macho.MachOByteBuffer;
 
-public class MachORelocTable {
-    ArrayList<ArrayList<MachORelocEntry>> relocEntries;
+final class MachORelocTable {
+    private final ArrayList<ArrayList<MachORelocEntry>> relocEntries;
     int fileOffset;
 
-    public MachORelocTable(int numsects) {
-        relocEntries = new ArrayList<ArrayList<MachORelocEntry>>(numsects);
-        for (int i = 0; i < numsects; i++)
+    MachORelocTable(int numsects) {
+        relocEntries = new ArrayList<>(numsects);
+        for (int i = 0; i < numsects; i++) {
             relocEntries.add(new ArrayList<MachORelocEntry>());
+        }
     }
 
-    public void createRelocationEntry(int sectindex,
-                                 int offset,
-                                 int symno,
-                                 int pcrel,
-                                 int length,
-                                 int isextern,
-                                 int type) {
-
-        MachORelocEntry entry = new MachORelocEntry(offset,
-                                                    symno,
-                                                    pcrel,
-                                                    length,
-                                                    isextern,
-                                                    type);
+    void createRelocationEntry(int sectindex, int offset, int symno, int pcrel, int length, int isextern, int type) {
+        MachORelocEntry entry = new MachORelocEntry(offset, symno, pcrel, length, isextern, type);
         relocEntries.get(sectindex).add(entry);
     }
 
-    public int getAlign() {
+    static int getAlign() {
         return (4);
     }
 
-    public int getNumRelocs(int section_index) {
+    int getNumRelocs(int section_index) {
         return relocEntries.get(section_index).size();
     }
 
     // Return the relocation entries for a single section
-    //   or null if no entries added to section
-    public byte [] getRelocData(int section_index) {
+    // or null if no entries added to section
+    byte[] getRelocData(int section_index) {
         ArrayList<MachORelocEntry> entryList = relocEntries.get(section_index);
 
-        if (entryList.size() == 0)
+        if (entryList.size() == 0) {
             return null;
-
+        }
         ByteBuffer relocData = MachOByteBuffer.allocate(entryList.size() * reloc_info.totalsize);
 
         // Copy each entry to a single ByteBuffer
@@ -86,4 +73,3 @@
         return (relocData.array());
     }
 }
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOSection.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOSection.java	Wed Sep 20 23:55:35 2017 -0400
@@ -24,41 +24,36 @@
 package jdk.tools.jaotc.binformat.macho;
 
 import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
 
-import jdk.tools.jaotc.binformat.macho.MachO;
 import jdk.tools.jaotc.binformat.macho.MachO.section_64;
 import jdk.tools.jaotc.binformat.macho.MachOByteBuffer;
 
-public class MachOSection {
-    ByteBuffer section;
-    byte [] data;
-    boolean hasrelocations;
+final class MachOSection {
+    private final ByteBuffer section;
+    private final byte[] data;
+    private final boolean hasrelocations;
 
-    public MachOSection(String sectName, String segName, byte [] sectData, int sectFlags, boolean hasRelocations) {
+    MachOSection(String sectName, String segName, byte[] sectData, int sectFlags, boolean hasRelocations, int align) {
         section = MachOByteBuffer.allocate(section_64.totalsize);
 
         // TODO: Hotspot uses long section names.
-        //       They are getting truncated.
-        //       Is this a problem??
+        // They are getting truncated.
+        // Is this a problem??
         byte[] sectNameBytes = sectName.getBytes();
-        int sectNameMax = section_64.sectname.sz < sectNameBytes.length ?
-                         section_64.sectname.sz : sectNameBytes.length;
+        int sectNameMax = section_64.sectname.sz < sectNameBytes.length ? section_64.sectname.sz : sectNameBytes.length;
 
-        for (int i = 0; i < sectNameMax; i++)
-            section.put(section_64.sectname.off+i, sectNameBytes[i]);
+        for (int i = 0; i < sectNameMax; i++) {
+            section.put(section_64.sectname.off + i, sectNameBytes[i]);
+        }
+        byte[] segNameBytes = segName.getBytes();
+        int segNameMax = section_64.segname.sz < segNameBytes.length ? section_64.segname.sz : segNameBytes.length;
 
-        byte[] segNameBytes = segName.getBytes();
-        int segNameMax = section_64.segname.sz < segNameBytes.length ?
-                         section_64.segname.sz : segNameBytes.length;
-
-        for (int i = 0; i < segNameMax; i++)
-            section.put(section_64.segname.off+i, segNameBytes[i]);
-
+        for (int i = 0; i < segNameMax; i++) {
+            section.put(section_64.segname.off + i, segNameBytes[i]);
+        }
         section.putLong(section_64.size.off, sectData.length);
 
-        // For now use 8 byte alignment
-        section.putInt(section_64.align.off, 3);
+        section.putInt(section_64.align.off, 31 - Integer.numberOfLeadingZeros(align));
 
         section.putInt(section_64.flags.off, sectFlags);
 
@@ -67,49 +62,47 @@
         hasrelocations = hasRelocations;
     }
 
-    public long getSize() {
+    long getSize() {
         return section.getLong(section_64.size.off);
     }
 
-    public int getAlign() {
+    int getAlign() {
         return (1 << section.getInt(section_64.align.off));
     }
 
-    public byte[] getArray() {
+    byte[] getArray() {
         return section.array();
     }
 
-    public byte[] getDataArray() {
+    byte[] getDataArray() {
         return data;
     }
 
-    public void setAddr(long addr) {
+    void setAddr(long addr) {
         section.putLong(section_64.addr.off, addr);
     }
 
-    public long getAddr() {
+    long getAddr() {
         return (section.getLong(section_64.addr.off));
     }
 
-    public void setOffset(int offset) {
+    void setOffset(int offset) {
         section.putInt(section_64.offset.off, offset);
     }
 
-    public int getOffset() {
+    int getOffset() {
         return (section.getInt(section_64.offset.off));
     }
 
-    public void setReloff(int offset) {
+    void setReloff(int offset) {
         section.putInt(section_64.reloff.off, offset);
     }
 
-    public void setRelcount(int count) {
+    void setRelcount(int count) {
         section.putInt(section_64.nreloc.off, count);
     }
 
-    public boolean hasRelocations() {
+    boolean hasRelocations() {
         return hasrelocations;
     }
 }
-
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOSegment.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOSegment.java	Wed Sep 20 23:55:35 2017 -0400
@@ -24,9 +24,7 @@
 package jdk.tools.jaotc.binformat.macho;
 
 import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
 
-import jdk.tools.jaotc.binformat.macho.MachO;
 import jdk.tools.jaotc.binformat.macho.MachO.segment_command_64;
 import jdk.tools.jaotc.binformat.macho.MachOByteBuffer;
 
@@ -52,5 +50,3 @@
         return segment.array();
     }
 }
-
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOSymbol.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOSymbol.java	Wed Sep 20 23:55:35 2017 -0400
@@ -24,17 +24,15 @@
 package jdk.tools.jaotc.binformat.macho;
 
 import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
 
 import jdk.tools.jaotc.binformat.NativeSymbol;
-import jdk.tools.jaotc.binformat.macho.MachO;
 import jdk.tools.jaotc.binformat.macho.MachO.nlist_64;
 import jdk.tools.jaotc.binformat.macho.MachOByteBuffer;
 
-public class MachOSymbol extends NativeSymbol {
-    ByteBuffer sym;
+final class MachOSymbol extends NativeSymbol {
+    private final ByteBuffer sym;
 
-    public MachOSymbol(int symbolindex, int strindex, byte type, byte sectindex, long offset) {
+    MachOSymbol(int symbolindex, int strindex, byte type, byte sectindex, long offset) {
         super(symbolindex);
         sym = MachOByteBuffer.allocate(nlist_64.totalsize);
 
@@ -42,13 +40,12 @@
         sym.put(nlist_64.n_type.off, type);
         // Section indexes start at 1 but we manage the index internally
         // as 0 relative
-        sym.put(nlist_64.n_sect.off, (byte)(sectindex+1));
-        sym.putChar(nlist_64.n_desc.off, (char )0);
+        sym.put(nlist_64.n_sect.off, (byte) (sectindex + 1));
+        sym.putChar(nlist_64.n_desc.off, (char) 0);
         sym.putLong(nlist_64.n_value.off, offset);
     }
 
-    public byte[] getArray() {
+    byte[] getArray() {
         return sym.array();
     }
 }
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOSymtab.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOSymtab.java	Wed Sep 20 23:55:35 2017 -0400
@@ -24,50 +24,42 @@
 package jdk.tools.jaotc.binformat.macho;
 
 import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
 import java.util.ArrayList;
 
-import jdk.tools.jaotc.binformat.macho.MachO;
 import jdk.tools.jaotc.binformat.macho.MachO.symtab_command;
 import jdk.tools.jaotc.binformat.macho.MachO.nlist_64;
 import jdk.tools.jaotc.binformat.macho.MachOSymbol;
 import jdk.tools.jaotc.binformat.macho.MachOByteBuffer;
 
-public class MachOSymtab {
+final class MachOSymtab {
 
     /**
      * ByteBuffer holding the LC_SYMTAB command contents
      */
-    ByteBuffer symtabCmd;
+    private final ByteBuffer symtabCmd;
 
-    /**
-     * ByteBuffer holding the symbol table entries and strings
-     */
-    ByteBuffer symtabData;
+    private int symtabDataSize;
 
-    int symtabDataSize;
-
-    ArrayList<MachOSymbol>localSymbols = new ArrayList<MachOSymbol>();
-    ArrayList<MachOSymbol>globalSymbols = new ArrayList<MachOSymbol>();
-    ArrayList<MachOSymbol>undefSymbols = new ArrayList<MachOSymbol>();
+    private final ArrayList<MachOSymbol> localSymbols = new ArrayList<>();
+    private final ArrayList<MachOSymbol> globalSymbols = new ArrayList<>();
+    private final ArrayList<MachOSymbol> undefSymbols = new ArrayList<>();
 
     /**
      * number of symbols added
      */
-    int symbolCount;
+    private int symbolCount;
 
     /**
      * String holding symbol table strings
      */
-    private StringBuilder strTabContent = new StringBuilder();
+    private final StringBuilder strTabContent = new StringBuilder();
 
     /**
-     * Keeps track of bytes in string table since strTabContent.length()
-     * is number of chars, not bytes.
+     * Keeps track of bytes in string table since strTabContent.length() is number of chars, not bytes.
      */
     private int strTabNrOfBytes = 0;
 
-    public MachOSymtab() {
+    MachOSymtab() {
         symtabCmd = MachOByteBuffer.allocate(symtab_command.totalsize);
 
         symtabCmd.putInt(symtab_command.cmd.off, symtab_command.LC_SYMTAB);
@@ -77,11 +69,11 @@
 
     }
 
-    public int getAlign() {
+    static int getAlign() {
         return (4);
     }
 
-    public MachOSymbol addSymbolEntry(String name, byte type, byte secHdrIndex, long offset) {
+    MachOSymbol addSymbolEntry(String name, byte type, byte secHdrIndex, long offset) {
         // Get the current symbol index and append symbol name to string table.
         int index;
         MachOSymbol sym;
@@ -109,7 +101,7 @@
                 case nlist_64.N_UNDF:  // null symbol
                     localSymbols.add(sym);
                     break;
-                case nlist_64.N_SECT|nlist_64.N_EXT:
+                case nlist_64.N_SECT | nlist_64.N_EXT:
                     globalSymbols.add(sym);
                     break;
                 default:
@@ -121,30 +113,30 @@
         return (sym);
     }
 
-    public void setOffset(int symoff) {
+    void setOffset(int symoff) {
         symtabCmd.putInt(symtab_command.symoff.off, symoff);
     }
 
     // Update the symbol indexes once all symbols have been added.
     // This is required since we'll be reordering the symbols in the
     // file to be in the order of Local, global and Undefined.
-    public void updateIndexes() {
+    void updateIndexes() {
         int index = 0;
 
         // Update the local symbol indexes
-        for (int i = 0; i < localSymbols.size(); i++ ) {
+        for (int i = 0; i < localSymbols.size(); i++) {
             MachOSymbol sym = localSymbols.get(i);
             sym.setIndex(index++);
         }
 
         // Update the global symbol indexes
-        for (int i = 0; i < globalSymbols.size(); i++ ) {
+        for (int i = 0; i < globalSymbols.size(); i++) {
             MachOSymbol sym = globalSymbols.get(i);
             sym.setIndex(index++);
         }
 
         // Update the undefined symbol indexes
-        for (int i = index; i < undefSymbols.size(); i++ ) {
+        for (int i = index; i < undefSymbols.size(); i++) {
             MachOSymbol sym = undefSymbols.get(i);
             sym.setIndex(index++);
         }
@@ -152,7 +144,7 @@
 
     // Update LC_SYMTAB command fields based on the number of symbols added
     // return the file size taken up by symbol table entries and strings
-    public int calcSizes() {
+    int calcSizes() {
         int stroff;
 
         stroff = symtabCmd.getInt(symtab_command.symoff.off) + (nlist_64.totalsize * symbolCount);
@@ -164,42 +156,49 @@
         return (symtabDataSize);
     }
 
-    public int getNumLocalSyms()  { return localSymbols.size();  }
-    public int getNumGlobalSyms() { return globalSymbols.size(); }
-    public int getNumUndefSyms()  { return undefSymbols.size();  }
+    int getNumLocalSyms() {
+        return localSymbols.size();
+    }
 
-    public byte[] getCmdArray() {
+    int getNumGlobalSyms() {
+        return globalSymbols.size();
+    }
+
+    int getNumUndefSyms() {
+        return undefSymbols.size();
+    }
+
+    byte[] getCmdArray() {
         return symtabCmd.array();
     }
 
     // Create a single byte array that contains the symbol table entries
     // and string table
-    public byte[] getDataArray() {
-        int index = 0;
-        symtabData = MachOByteBuffer.allocate(symtabDataSize);
-        byte [] retarray;
+    byte[] getDataArray() {
+        ByteBuffer symtabData = MachOByteBuffer.allocate(symtabDataSize);
+        byte[] retarray;
 
         // Add the local symbols
-        for (int i = 0; i < localSymbols.size(); i++ ) {
+        for (int i = 0; i < localSymbols.size(); i++) {
             MachOSymbol sym = localSymbols.get(i);
-            byte [] arr = sym.getArray();
+            byte[] arr = sym.getArray();
             symtabData.put(arr);
         }
         // Add the global symbols
-        for (int i = 0; i < globalSymbols.size(); i++ ) {
+        for (int i = 0; i < globalSymbols.size(); i++) {
             MachOSymbol sym = globalSymbols.get(i);
-            byte [] arr = sym.getArray();
+            byte[] arr = sym.getArray();
             symtabData.put(arr);
         }
         // Add the undefined symbols
-        for (int i = 0; i < undefSymbols.size(); i++ ) {
+        for (int i = 0; i < undefSymbols.size(); i++) {
             MachOSymbol sym = undefSymbols.get(i);
-            byte [] arr = sym.getArray();
+            byte[] arr = sym.getArray();
             symtabData.put(arr);
         }
 
         // Add the stringtable
-        byte [] strs = strTabContent.toString().getBytes();
+        byte[] strs = strTabContent.toString().getBytes();
         symtabData.put(strs);
 
         retarray = symtabData.array();
@@ -207,5 +206,3 @@
         return (retarray);
     }
 }
-
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOTargetInfo.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOTargetInfo.java	Wed Sep 20 23:55:35 2017 -0400
@@ -24,14 +24,13 @@
 package jdk.tools.jaotc.binformat.macho;
 
 import java.nio.ByteOrder;
-import jdk.tools.jaotc.binformat.macho.MachO;
 import jdk.tools.jaotc.binformat.macho.MachO.mach_header_64;
 
 /**
  * Class that abstracts MACH-O target details.
  *
  */
-public class MachOTargetInfo {
+final class MachOTargetInfo {
     /**
      * Target architecture and subtype.
      */
@@ -68,20 +67,19 @@
         osName = System.getProperty("os.name").toLowerCase();
     }
 
-    public static int getMachOArch() {
+    static int getMachOArch() {
         return arch;
     }
 
-    public static int getMachOSubArch() {
+    static int getMachOSubArch() {
         return subarch;
     }
 
-    public static int getMachOEndian() {
+    static int getMachOEndian() {
         return endian;
     }
 
-    public static String getOsName() {
+    static String getOsName() {
         return osName;
     }
 }
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOVersion.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOVersion.java	Wed Sep 20 23:55:35 2017 -0400
@@ -24,16 +24,14 @@
 package jdk.tools.jaotc.binformat.macho;
 
 import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
 
-import jdk.tools.jaotc.binformat.macho.MachO;
 import jdk.tools.jaotc.binformat.macho.MachO.version_min_command;
 import jdk.tools.jaotc.binformat.macho.MachOByteBuffer;
 
-public class MachOVersion {
-    ByteBuffer version;
+final class MachOVersion {
+    private final ByteBuffer version;
 
-    public MachOVersion() {
+    MachOVersion() {
         version = MachOByteBuffer.allocate(version_min_command.totalsize);
 
         version.putInt(version_min_command.cmd.off, version_min_command.LC_VERSION_MIN_MACOSX);
@@ -42,8 +40,7 @@
         version.putInt(version_min_command.sdk.off, 0); /* N/A SDK */
     }
 
-    public byte[] getArray() {
+    byte[] getArray() {
         return version.array();
     }
 }
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/JPECoffRelocObject.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/JPECoffRelocObject.java	Wed Sep 20 23:55:35 2017 -0400
@@ -24,13 +24,11 @@
 package jdk.tools.jaotc.binformat.pecoff;
 
 import java.io.IOException;
-import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
-import jdk.tools.jaotc.binformat.Container;
 import jdk.tools.jaotc.binformat.BinaryContainer;
 import jdk.tools.jaotc.binformat.ByteContainer;
 import jdk.tools.jaotc.binformat.CodeContainer;
@@ -38,11 +36,9 @@
 import jdk.tools.jaotc.binformat.Relocation;
 import jdk.tools.jaotc.binformat.Relocation.RelocType;
 import jdk.tools.jaotc.binformat.Symbol;
-import jdk.tools.jaotc.binformat.NativeSymbol;
 import jdk.tools.jaotc.binformat.Symbol.Binding;
 import jdk.tools.jaotc.binformat.Symbol.Kind;
 
-import jdk.tools.jaotc.binformat.pecoff.PECoff;
 import jdk.tools.jaotc.binformat.pecoff.PECoffSymbol;
 import jdk.tools.jaotc.binformat.pecoff.PECoffTargetInfo;
 import jdk.tools.jaotc.binformat.pecoff.PECoff.IMAGE_FILE_HEADER;
@@ -56,68 +52,53 @@
 
     private final PECoffContainer pecoffContainer;
 
-    private final int segmentSize;
+    private final int sectionAlignment;
 
-    public JPECoffRelocObject(BinaryContainer binContainer, String outputFileName, String aotVersion) {
+    public JPECoffRelocObject(BinaryContainer binContainer, String outputFileName) {
         this.binContainer = binContainer;
-        this.pecoffContainer = new PECoffContainer(outputFileName, aotVersion);
-        this.segmentSize = binContainer.getCodeSegmentSize();
+        this.pecoffContainer = new PECoffContainer(outputFileName);
+        this.sectionAlignment = binContainer.getCodeSegmentSize();
     }
 
-    private PECoffSection createByteSection(ArrayList<PECoffSection>sections,
-                                         String sectName,
-                                         byte [] scnData,
-                                         boolean hasRelocs,
-                                         int scnFlags) {
+    private static PECoffSection createByteSection(ArrayList<PECoffSection> sections, String sectName, byte[] scnData,
+                    boolean hasRelocs, int scnFlags, int sectAlign) {
 
-        PECoffSection sect = new PECoffSection(sectName,
-                                         scnData,
-                                         scnFlags,
-                                         hasRelocs,
-                                         sections.size());
+        PECoffSection sect = new PECoffSection(sectName, scnData, scnFlags, sectAlign, hasRelocs, sections.size());
         // Add this section to our list
         sections.add(sect);
 
         return (sect);
     }
 
-    private void createByteSection(ArrayList<PECoffSection>sections,
-                                   ByteContainer c, int scnFlags) {
+    private static void createByteSection(ArrayList<PECoffSection> sections, ByteContainer c, int scnFlags, int sectAlign) {
         PECoffSection sect;
         boolean hasRelocs = c.hasRelocations();
         byte[] scnData = c.getByteArray();
 
-        sect = createByteSection(sections, c.getContainerName(),
-                                 scnData, hasRelocs,
-                                 scnFlags);
+        sect = createByteSection(sections, c.getContainerName(), scnData, hasRelocs, scnFlags, sectAlign);
 
         c.setSectionId(sect.getSectionId());
     }
 
-    private void createCodeSection(ArrayList<PECoffSection>sections, CodeContainer c) {
-        createByteSection(sections, c, IMAGE_SECTION_HEADER.IMAGE_SCN_MEM_READ |
-                                       IMAGE_SECTION_HEADER.IMAGE_SCN_MEM_EXECUTE |
-                                       IMAGE_SECTION_HEADER.IMAGE_SCN_ALIGN_16BYTES |
-                                       IMAGE_SECTION_HEADER.IMAGE_SCN_CNT_CODE);
+    private void createCodeSection(ArrayList<PECoffSection> sections, CodeContainer c) {
+        int scnFlags = IMAGE_SECTION_HEADER.IMAGE_SCN_MEM_READ | IMAGE_SECTION_HEADER.IMAGE_SCN_MEM_EXECUTE | IMAGE_SECTION_HEADER.IMAGE_SCN_CNT_CODE;
+        createByteSection(sections, c, scnFlags, sectionAlignment);
     }
 
-    private void createReadOnlySection(ArrayList<PECoffSection>sections, ReadOnlyDataContainer c) {
-        createByteSection(sections, c, IMAGE_SECTION_HEADER.IMAGE_SCN_MEM_READ |
-                                       IMAGE_SECTION_HEADER.IMAGE_SCN_ALIGN_16BYTES |
-                                       IMAGE_SECTION_HEADER.IMAGE_SCN_CNT_INITIALIZED_DATA);
+    private void createReadOnlySection(ArrayList<PECoffSection> sections, ReadOnlyDataContainer c) {
+        int scnFlags = IMAGE_SECTION_HEADER.IMAGE_SCN_MEM_READ | IMAGE_SECTION_HEADER.IMAGE_SCN_CNT_INITIALIZED_DATA;
+        createByteSection(sections, c, scnFlags, sectionAlignment);
     }
 
-    private void createReadWriteSection(ArrayList<PECoffSection>sections, ByteContainer c) {
-        int scnFlags = IMAGE_SECTION_HEADER.IMAGE_SCN_MEM_READ |
-                       IMAGE_SECTION_HEADER.IMAGE_SCN_MEM_WRITE |
-                       IMAGE_SECTION_HEADER.IMAGE_SCN_ALIGN_8BYTES;
+    private void createReadWriteSection(ArrayList<PECoffSection> sections, ByteContainer c) {
+        int scnFlags = IMAGE_SECTION_HEADER.IMAGE_SCN_MEM_READ | IMAGE_SECTION_HEADER.IMAGE_SCN_MEM_WRITE;
 
-        if (c.getByteArray().length > 0)
+        if (c.getByteArray().length > 0) {
             scnFlags |= IMAGE_SECTION_HEADER.IMAGE_SCN_CNT_INITIALIZED_DATA;
-        else
+        } else {
             scnFlags |= IMAGE_SECTION_HEADER.IMAGE_SCN_CNT_UNINITIALIZED_DATA;
-
-        createByteSection(sections, c, scnFlags);
+        }
+        createByteSection(sections, c, scnFlags, sectionAlignment);
     }
 
     /**
@@ -128,7 +109,7 @@
      * @throws IOException throws {@code IOException} as a result of file system access failures.
      */
     public void createPECoffRelocObject(Map<Symbol, List<Relocation>> relocationTable, Collection<Symbol> symbols) throws IOException {
-        ArrayList<PECoffSection> sections = new ArrayList<PECoffSection>();
+        ArrayList<PECoffSection> sections = new ArrayList<>();
 
         // Create text section
         createCodeSection(sections, binContainer.getCodeContainer());
@@ -136,51 +117,45 @@
         createReadOnlySection(sections, binContainer.getKlassesOffsetsContainer());
         createReadOnlySection(sections, binContainer.getMethodsOffsetsContainer());
         createReadOnlySection(sections, binContainer.getKlassesDependenciesContainer());
-        createReadWriteSection(sections, binContainer.getMetaspaceGotContainer());
-        createReadWriteSection(sections, binContainer.getMetadataGotContainer());
-        createReadWriteSection(sections, binContainer.getMethodStateContainer());
-        createReadWriteSection(sections, binContainer.getOopGotContainer());
-        createReadWriteSection(sections, binContainer.getMethodMetadataContainer());
+        createReadOnlySection(sections, binContainer.getMethodMetadataContainer());
         createReadOnlySection(sections, binContainer.getStubsOffsetsContainer());
         createReadOnlySection(sections, binContainer.getHeaderContainer().getContainer());
         createReadOnlySection(sections, binContainer.getCodeSegmentsContainer());
         createReadOnlySection(sections, binContainer.getConstantDataContainer());
         createReadOnlySection(sections, binContainer.getConfigContainer());
-
-        // createExternalLinkage();
-
-        createCodeSection(sections, binContainer.getExtLinkageContainer());
+        createReadWriteSection(sections, binContainer.getKlassesGotContainer());
+        createReadWriteSection(sections, binContainer.getCountersGotContainer());
+        createReadWriteSection(sections, binContainer.getMetadataGotContainer());
+        createReadWriteSection(sections, binContainer.getMethodStateContainer());
+        createReadWriteSection(sections, binContainer.getOopGotContainer());
         createReadWriteSection(sections, binContainer.getExtLinkageGOTContainer());
 
         // Allocate PECoff Header
         PECoffHeader header = new PECoffHeader();
 
         // Get PECoff symbol data from BinaryContainer object's symbol tables
-        PECoffSymtab symtab = createPECoffSymbolTables(sections, symbols);
+        PECoffSymtab symtab = createPECoffSymbolTables(symbols);
 
         // Add Linker Directives Section
-        createByteSection(sections, ".drectve",
-                          symtab.getDirectiveArray(), false,
-                          IMAGE_SECTION_HEADER.IMAGE_SCN_LNK_INFO |
-                          IMAGE_SECTION_HEADER.IMAGE_SCN_LNK_REMOVE |
-                          IMAGE_SECTION_HEADER.IMAGE_SCN_ALIGN_1BYTES);
+        int scnFlags = IMAGE_SECTION_HEADER.IMAGE_SCN_LNK_INFO | IMAGE_SECTION_HEADER.IMAGE_SCN_LNK_REMOVE;
+        createByteSection(sections, ".drectve", symtab.getDirectiveArray(), false, scnFlags, 1 /* 1 byte alignment */);
 
         // Create the Relocation Tables
         PECoffRelocTable pecoffRelocs = createPECoffRelocTable(sections, relocationTable);
 
         // File Output Order
         //
-        //   HEADER           (Need address of Symbol Table + symbol count)
-        //   SECTIONS         (Need pointer to Section Data, Relocation Table)
-        //   DIRECTIVES
-        //   SYMBOL TABLE
-        //   SYMBOLS
-        //   SECTION DATA
-        //   RELOCATION TABLE
+        // HEADER (Need address of Symbol Table + symbol count)
+        // SECTIONS (Need pointer to Section Data, Relocation Table)
+        // DIRECTIVES
+        // SYMBOL TABLE
+        // SYMBOLS
+        // SECTION DATA
+        // RELOCATION TABLE
 
         // Calculate Offset for Symbol table
         int file_offset = IMAGE_FILE_HEADER.totalsize +
-                          (IMAGE_SECTION_HEADER.totalsize*sections.size());
+                        (IMAGE_SECTION_HEADER.totalsize * sections.size());
 
         // Update Header fields
         header.setSectionCount(sections.size());
@@ -191,14 +166,14 @@
         file_offset += ((symtab.getSymtabCount() * IMAGE_SYMBOL.totalsize) +
                         symtab.getStrtabSize());
         // And round it up
-        file_offset = (file_offset + (sections.get(0).getDataAlign()-1)) &
-                      ~((sections.get(0).getDataAlign()-1));
+        file_offset = (file_offset + (sections.get(0).getDataAlign() - 1)) &
+                        ~((sections.get(0).getDataAlign() - 1));
 
         // Calc file offsets for section data
         for (int i = 0; i < sections.size(); i++) {
             PECoffSection sect = sections.get(i);
-            file_offset = (file_offset + (sect.getDataAlign()-1)) &
-                           ~((sect.getDataAlign()-1));
+            file_offset = (file_offset + (sect.getDataAlign() - 1)) &
+                            ~((sect.getDataAlign() - 1));
             sect.setOffset(file_offset);
             file_offset += sect.getSize();
         }
@@ -211,7 +186,9 @@
                 sect.setReloff(file_offset);
                 sect.setRelcount(nreloc);
                 // extended relocations add an addition entry
-                if (nreloc > 0xFFFF) nreloc++;
+                if (nreloc > 0xFFFF) {
+                    nreloc++;
+                }
                 file_offset += (nreloc * IMAGE_RELOCATION.totalsize);
             }
         }
@@ -250,7 +227,7 @@
      *
      * @param symbols
      */
-    private PECoffSymtab createPECoffSymbolTables(ArrayList<PECoffSection> sections, Collection<Symbol> symbols) {
+    private static PECoffSymtab createPECoffSymbolTables(Collection<Symbol> symbols) {
         PECoffSymtab symtab = new PECoffSymtab();
 
         // First, create the initial null symbol. This is a local symbol.
@@ -260,8 +237,8 @@
         for (Symbol symbol : symbols) {
             // Get the index of section this symbol is defined in.
             int secHdrIndex = symbol.getSection().getSectionId();
-            PECoffSymbol pecoffSymbol = symtab.addSymbolEntry(symbol.getName(), getPECoffTypeOf(symbol), getPECoffClassOf(symbol), (byte)secHdrIndex, symbol.getOffset(), symbol.getSize());
-            symbol.setNativeSymbol((NativeSymbol)pecoffSymbol);
+            PECoffSymbol pecoffSymbol = symtab.addSymbolEntry(symbol.getName(), getPECoffTypeOf(symbol), getPECoffClassOf(symbol), (byte) secHdrIndex, symbol.getOffset());
+            symbol.setNativeSymbol(pecoffSymbol);
         }
         return (symtab);
     }
@@ -288,13 +265,11 @@
      * @param sections
      * @param relocationTable
      */
-    private PECoffRelocTable createPECoffRelocTable(ArrayList<PECoffSection> sections,
-                                              Map<Symbol, List<Relocation>> relocationTable) {
+    private PECoffRelocTable createPECoffRelocTable(ArrayList<PECoffSection> sections, Map<Symbol, List<Relocation>> relocationTable) {
 
         PECoffRelocTable pecoffRelocTable = new PECoffRelocTable(sections.size());
         /*
-         * For each of the symbols with associated relocation records, create a PECoff relocation
-         * entry.
+         * For each of the symbols with associated relocation records, create a PECoff relocation entry.
          */
         for (Map.Entry<Symbol, List<Relocation>> entry : relocationTable.entrySet()) {
             List<Relocation> relocs = entry.getValue();
@@ -312,18 +287,17 @@
         return (pecoffRelocTable);
     }
 
-    private void createRelocation(Symbol symbol, Relocation reloc, PECoffRelocTable pecoffRelocTable) {
+    private static void createRelocation(Symbol symbol, Relocation reloc, PECoffRelocTable pecoffRelocTable) {
         RelocType relocType = reloc.getType();
 
         int pecoffRelocType = getPECoffRelocationType(relocType);
-        PECoffSymbol sym = (PECoffSymbol)symbol.getNativeSymbol();
+        PECoffSymbol sym = (PECoffSymbol) symbol.getNativeSymbol();
         int symno = sym.getIndex();
         int sectindex = reloc.getSection().getSectionId();
         int offset = reloc.getOffset();
         int addend = 0;
 
         switch (relocType) {
-            case FOREIGN_CALL_DIRECT:
             case JAVA_CALL_DIRECT:
             case STUB_CALL_DIRECT:
             case FOREIGN_CALL_INDIRECT_GOT: {
@@ -333,47 +307,22 @@
                 offset = offset + reloc.getSize() + addend;
                 break;
             }
-            case FOREIGN_CALL_DIRECT_FAR: {
-                // Create relocation entry
-                addend = -8; // Size in bytes of the patch location
-                // Relocation should be applied at the location after call operand
-                // 10 = 2 (jmp [r]) + 8 (imm64)
-                offset = offset + reloc.getSize() + addend - 2;
-                break;
-            }
-            case FOREIGN_CALL_INDIRECT:
-            case JAVA_CALL_INDIRECT:
-            case STUB_CALL_INDIRECT: {
+            case JAVA_CALL_INDIRECT: {
                 // Do nothing.
                 return;
             }
-            case EXTERNAL_DATA_REFERENCE_FAR: {
-                // Create relocation entry
+            case METASPACE_GOT_REFERENCE:
+            case EXTERNAL_PLT_TO_GOT: {
                 addend = -4; // Size of 32-bit address of the GOT
                 /*
                  * Relocation should be applied before the test instruction to the move instruction.
-                 * offset points to the test instruction after the instruction that loads
-                 * the address of polling page. So set the offset appropriately.
+                 * reloc.getOffset() points to the test instruction after the instruction that loads the address of
+                 * polling page. So set the offset appropriately.
                  */
                 offset = offset + addend;
                 break;
             }
-            case METASPACE_GOT_REFERENCE:
-            case EXTERNAL_PLT_TO_GOT:
-            case STATIC_STUB_TO_STATIC_METHOD:
-            case STATIC_STUB_TO_HOTSPOT_LINKAGE_GOT: {
-                addend = -4; // Size of 32-bit address of the GOT
-                /*
-                 * Relocation should be applied before the test instruction to
-                 * the move instruction. reloc.getOffset() points to the
-                 * test instruction after the instruction that loads the
-                 * address of polling page. So set the offset appropriately.
-                 */
-                offset = offset + addend;
-                break;
-            }
-            case EXTERNAL_GOT_TO_PLT:
-            case LOADTIME_ADDRESS: {
+            case EXTERNAL_GOT_TO_PLT: {
                 // this is load time relocations
                 break;
             }
@@ -388,27 +337,17 @@
         int pecoffRelocType = 0; // R_<ARCH>_NONE if #define'd to 0 for all values of ARCH
         switch (PECoffTargetInfo.getPECoffArch()) {
             case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_AMD64:
-                if (relocType == RelocType.FOREIGN_CALL_DIRECT ||
-                    relocType == RelocType.JAVA_CALL_DIRECT ||
+                if (relocType == RelocType.JAVA_CALL_DIRECT ||
                     relocType == RelocType.FOREIGN_CALL_INDIRECT_GOT) {
                     pecoffRelocType = IMAGE_RELOCATION.IMAGE_REL_AMD64_REL32;
                 } else if (relocType == RelocType.STUB_CALL_DIRECT) {
                     pecoffRelocType = IMAGE_RELOCATION.IMAGE_REL_AMD64_REL32;
-                } else if (relocType == RelocType.FOREIGN_CALL_DIRECT_FAR) {
-                    pecoffRelocType = IMAGE_RELOCATION.IMAGE_REL_AMD64_ADDR64;
-                } else if (relocType == RelocType.FOREIGN_CALL_INDIRECT ||
-                           relocType == RelocType.JAVA_CALL_INDIRECT ||
-                           relocType == RelocType.STUB_CALL_INDIRECT) {
+                } else if (relocType == RelocType.JAVA_CALL_INDIRECT) {
                     pecoffRelocType = IMAGE_RELOCATION.IMAGE_REL_AMD64_ABSOLUTE;
-                } else if ((relocType == RelocType.EXTERNAL_DATA_REFERENCE_FAR)) {
+                } else if (relocType == RelocType.METASPACE_GOT_REFERENCE ||
+                           relocType == RelocType.EXTERNAL_PLT_TO_GOT) {
                     pecoffRelocType = IMAGE_RELOCATION.IMAGE_REL_AMD64_REL32;
-                } else if (relocType == RelocType.METASPACE_GOT_REFERENCE ||
-                           relocType == RelocType.EXTERNAL_PLT_TO_GOT ||
-                           relocType == RelocType.STATIC_STUB_TO_STATIC_METHOD ||
-                           relocType == RelocType.STATIC_STUB_TO_HOTSPOT_LINKAGE_GOT) {
-                    pecoffRelocType = IMAGE_RELOCATION.IMAGE_REL_AMD64_REL32;
-                } else if (relocType == RelocType.EXTERNAL_GOT_TO_PLT ||
-                           relocType == RelocType.LOADTIME_ADDRESS) {
+                } else if (relocType == RelocType.EXTERNAL_GOT_TO_PLT) {
                     pecoffRelocType = IMAGE_RELOCATION.IMAGE_REL_AMD64_ADDR64;
                 } else {
                     assert false : "Unhandled relocation type: " + relocType;
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoff.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoff.java	Wed Sep 20 23:55:35 2017 -0400
@@ -25,17 +25,16 @@
 
 /**
  *
- * Support for the creation of Coff files.
- * Current support is limited to 64 bit x86_64.
+ * Support for the creation of Coff files. Current support is limited to 64 bit x86_64.
  *
  */
 
-public class PECoff {
-
+final class PECoff {
+    //@formatter:off
     /**
      * IMAGE_FILE_HEADER structure defines
      */
-    public enum IMAGE_FILE_HEADER {
+    enum IMAGE_FILE_HEADER {
                      Machine( 0, 2),
             NumberOfSections( 2, 2),
                TimeDateStamp( 4, 4),
@@ -44,15 +43,15 @@
         SizeOfOptionalHeader(16, 2),
              Characteristics(18, 2);
 
-        public final int off;
-        public final int sz;
+        final int off;
+        final int sz;
 
         IMAGE_FILE_HEADER(int offset, int size) {
             this.off = offset;
             this.sz = size;
         }
 
-        public static int totalsize = 20;
+        static int totalsize = 20;
 
         /**
          * IMAGE_FILE_HEADER defines
@@ -61,15 +60,15 @@
         /**
          * Machine
          */
-        public static final char IMAGE_FILE_MACHINE_UNKNOWN = 0x0;
-        public static final char IMAGE_FILE_MACHINE_AMD64   = 0x8664;
+        static final char IMAGE_FILE_MACHINE_UNKNOWN = 0x0;
+        static final char IMAGE_FILE_MACHINE_AMD64   = 0x8664;
 
     }
 
     /**
      * IMAGE_SECTION_HEADER structure defines
      */
-    public enum IMAGE_SECTION_HEADER {
+    enum IMAGE_SECTION_HEADER {
                         Name( 0, 8),
              PhysicalAddress( 8, 4),
                  VirtualSize( 8, 4),
@@ -82,15 +81,15 @@
          NumberOfLinenumbers(34, 2),
              Characteristics(36, 4);
 
-        public final int off;
-        public final int sz;
+        final int off;
+        final int sz;
 
         IMAGE_SECTION_HEADER(int offset, int size) {
             this.off = offset;
             this.sz = size;
         }
 
-        public static int totalsize = 40;
+        static int totalsize = 40;
 
         /**
          * IMAGE_SECTION_HEADER defines
@@ -99,27 +98,33 @@
         /**
          * Characteristics
          */
-        public static final int IMAGE_SCN_CNT_CODE               = 0x20;
-        public static final int IMAGE_SCN_CNT_INITIALIZED_DATA   = 0x40;
-        public static final int IMAGE_SCN_CNT_UNINITIALIZED_DATA = 0x80;
-        public static final int IMAGE_SCN_LNK_COMDAT             = 0x1000;
-        public static final int IMAGE_SCN_LNK_INFO               = 0x200;
-        public static final int IMAGE_SCN_LNK_REMOVE             = 0x800;
+        static final int IMAGE_SCN_CNT_CODE               = 0x20;
+        static final int IMAGE_SCN_CNT_INITIALIZED_DATA   = 0x40;
+        static final int IMAGE_SCN_CNT_UNINITIALIZED_DATA = 0x80;
+        static final int IMAGE_SCN_LNK_COMDAT             = 0x1000;
+        static final int IMAGE_SCN_LNK_INFO               = 0x200;
+        static final int IMAGE_SCN_LNK_REMOVE             = 0x800;
 
-        public static final int IMAGE_SCN_ALIGN_1BYTES           = 0x100000;
-        public static final int IMAGE_SCN_ALIGN_2BYTES           = 0x200000;
-        public static final int IMAGE_SCN_ALIGN_4BYTES           = 0x300000;
-        public static final int IMAGE_SCN_ALIGN_8BYTES           = 0x400000;
-        public static final int IMAGE_SCN_ALIGN_16BYTES          = 0x500000;
-        public static final int IMAGE_SCN_ALIGN_MASK             = 0xf00000;
-        public static final int IMAGE_SCN_ALIGN_SHIFT            = 20;
+        static final int IMAGE_SCN_ALIGN_1BYTES           = 0x100000;
+        static final int IMAGE_SCN_ALIGN_2BYTES           = 0x200000;
+        static final int IMAGE_SCN_ALIGN_4BYTES           = 0x300000;
+        static final int IMAGE_SCN_ALIGN_8BYTES           = 0x400000;
+        static final int IMAGE_SCN_ALIGN_16BYTES          = 0x500000;
+        static final int IMAGE_SCN_ALIGN_32BYTES          = 0x600000;
+        static final int IMAGE_SCN_ALIGN_64BYTES          = 0x700000;
+        static final int IMAGE_SCN_ALIGN_128BYTES         = 0x800000;
+        static final int IMAGE_SCN_ALIGN_256BYTES         = 0x900000;
+        static final int IMAGE_SCN_ALIGN_512BYTES         = 0xa00000;
+        static final int IMAGE_SCN_ALIGN_1024BYTES        = 0xb00000;
+        static final int IMAGE_SCN_ALIGN_MASK             = 0xf00000;
+        static final int IMAGE_SCN_ALIGN_SHIFT            = 20;
 
-        public static final int IMAGE_SCN_LNK_NRELOC_OVFL        = 0x01000000;
+        static final int IMAGE_SCN_LNK_NRELOC_OVFL        = 0x01000000;
 
-        public static final int IMAGE_SCN_MEM_SHARED             = 0x10000000;
-        public static final int IMAGE_SCN_MEM_EXECUTE            = 0x20000000;
-        public static final int IMAGE_SCN_MEM_READ               = 0x40000000;
-        public static final int IMAGE_SCN_MEM_WRITE              = 0x80000000;
+        static final int IMAGE_SCN_MEM_SHARED             = 0x10000000;
+        static final int IMAGE_SCN_MEM_EXECUTE            = 0x20000000;
+        static final int IMAGE_SCN_MEM_READ               = 0x40000000;
+        static final int IMAGE_SCN_MEM_WRITE              = 0x80000000;
 
     }
 
@@ -128,7 +133,7 @@
      *
      * IMAGE_SYMBOL structure defines
      */
-    public enum IMAGE_SYMBOL {
+    enum IMAGE_SYMBOL {
                    ShortName( 0, 8),
                        Short( 0, 4),
                         Long( 4, 4),
@@ -138,63 +143,63 @@
                 StorageClass(16, 1),
           NumberOfAuxSymbols(17, 1);
 
-        public final int off;
-        public final int sz;
+        final int off;
+        final int sz;
 
         IMAGE_SYMBOL(int offset, int size) {
             this.off = offset;
             this.sz = size;
         }
 
-        public static int totalsize = 18;
+        static int totalsize = 18;
 
         /**
          * Type
          */
-        public static final int IMAGE_SYM_DTYPE_NONE     = 0x0;
-        public static final int IMAGE_SYM_DTYPE_FUNCTION = 0x20;
+        static final int IMAGE_SYM_DTYPE_NONE     = 0x0;
+        static final int IMAGE_SYM_DTYPE_FUNCTION = 0x20;
 
         /**
          * StorageClass
          */
-        public static final int IMAGE_SYM_CLASS_NULL     = 0x0;
-        public static final int IMAGE_SYM_CLASS_EXTERNAL = 0x2;
-        public static final int IMAGE_SYM_CLASS_STATIC   = 0x3;
-        public static final int IMAGE_SYM_CLASS_LABEL    = 0x6;
+        static final int IMAGE_SYM_CLASS_NULL     = 0x0;
+        static final int IMAGE_SYM_CLASS_EXTERNAL = 0x2;
+        static final int IMAGE_SYM_CLASS_STATIC   = 0x3;
+        static final int IMAGE_SYM_CLASS_LABEL    = 0x6;
 
     }
 
     /**
      * IMAGE_RELOCATION structure defines
      */
-    public enum IMAGE_RELOCATION {
+    enum IMAGE_RELOCATION {
               VirtualAddress( 0, 4),
             SymbolTableIndex( 4, 4),
                         Type( 8, 2);
 
-        public final int off;
-        public final int sz;
+        final int off;
+        final int sz;
 
         IMAGE_RELOCATION(int offset, int size) {
             this.off = offset;
             this.sz = size;
         }
 
-        public static int totalsize = 10;
+        static int totalsize = 10;
 
         /**
          * Relocation types
          */
-        public static final int IMAGE_REL_AMD64_ABSOLUTE = 0x0;
-        public static final int IMAGE_REL_AMD64_ADDR32   = 0x2;
-        public static final int IMAGE_REL_AMD64_ADDR64   = 0x1;
-        public static final int IMAGE_REL_AMD64_REL32    = 0x4;
-        public static final int IMAGE_REL_AMD64_REL32_1  = 0x5;
-        public static final int IMAGE_REL_AMD64_REL32_2  = 0x6;
-        public static final int IMAGE_REL_AMD64_REL32_3  = 0x7;
-        public static final int IMAGE_REL_AMD64_REL32_4  = 0x8;
-        public static final int IMAGE_REL_AMD64_REL32_5  = 0x9;
+        static final int IMAGE_REL_AMD64_ABSOLUTE = 0x0;
+        static final int IMAGE_REL_AMD64_ADDR32   = 0x2;
+        static final int IMAGE_REL_AMD64_ADDR64   = 0x1;
+        static final int IMAGE_REL_AMD64_REL32    = 0x4;
+        static final int IMAGE_REL_AMD64_REL32_1  = 0x5;
+        static final int IMAGE_REL_AMD64_REL32_2  = 0x6;
+        static final int IMAGE_REL_AMD64_REL32_3  = 0x7;
+        static final int IMAGE_REL_AMD64_REL32_4  = 0x8;
+        static final int IMAGE_REL_AMD64_REL32_5  = 0x9;
 
     }
-
+    //@formatter:on
 }
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffByteBuffer.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffByteBuffer.java	Wed Sep 20 23:55:35 2017 -0400
@@ -26,9 +26,9 @@
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
 
-public class PECoffByteBuffer {
+final class PECoffByteBuffer {
 
-    public static ByteBuffer allocate(int size) {
+    static ByteBuffer allocate(int size) {
         ByteBuffer buf = ByteBuffer.allocate(size);
         // Only support Little Endian on Windows
         buf.order(ByteOrder.LITTLE_ENDIAN);
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffContainer.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffContainer.java	Wed Sep 20 23:55:35 2017 -0400
@@ -26,14 +26,13 @@
 import java.io.File;
 import java.io.FileOutputStream;
 
-public class PECoffContainer {
+final class PECoffContainer {
 
-    File outputFile;
-    FileOutputStream outputStream;
-    long fileOffset;
+    private final File outputFile;
+    private FileOutputStream outputStream;
+    private long fileOffset;
 
-    public PECoffContainer(String fileName, String aotVersion) {
-        String baseName;
+    PECoffContainer(String fileName) {
 
         outputFile = new File(fileName);
         if (outputFile.exists()) {
@@ -48,7 +47,7 @@
         fileOffset = 0;
     }
 
-    public void close() {
+    void close() {
         try {
             outputStream.close();
         } catch (Exception e) {
@@ -56,8 +55,10 @@
         }
     }
 
-    public void writeBytes(byte [] bytes) {
-        if (bytes == null) return;
+    void writeBytes(byte[] bytes) {
+        if (bytes == null) {
+            return;
+        }
         try {
             outputStream.write(bytes);
         } catch (Exception e) {
@@ -67,11 +68,13 @@
     }
 
     // Write bytes to output file with up front alignment padding
-    public void writeBytes(byte [] bytes, int alignment) {
-        if (bytes == null) return;
+    void writeBytes(byte[] bytes, int alignment) {
+        if (bytes == null) {
+            return;
+        }
         try {
             // Pad to alignment
-            while ((fileOffset & (long)(alignment-1)) != 0) {
+            while ((fileOffset & (alignment - 1)) != 0) {
                 outputStream.write(0);
                 fileOffset++;
             }
@@ -82,4 +85,3 @@
         fileOffset += bytes.length;
     }
 }
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffHeader.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffHeader.java	Wed Sep 20 23:55:35 2017 -0400
@@ -24,45 +24,41 @@
 package jdk.tools.jaotc.binformat.pecoff;
 
 import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
 
-import jdk.tools.jaotc.binformat.pecoff.PECoff;
 import jdk.tools.jaotc.binformat.pecoff.PECoff.IMAGE_FILE_HEADER;
-import jdk.tools.jaotc.binformat.pecoff.PECoffTargetInfo;
 import jdk.tools.jaotc.binformat.pecoff.PECoffByteBuffer;
 
-public class PECoffHeader {
-    ByteBuffer header;
+final class PECoffHeader {
+    private final ByteBuffer header;
 
-    public PECoffHeader() {
+    PECoffHeader() {
         header = PECoffByteBuffer.allocate(IMAGE_FILE_HEADER.totalsize);
 
         header.putChar(IMAGE_FILE_HEADER.Machine.off, IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_AMD64);
-        header.putInt(IMAGE_FILE_HEADER.TimeDateStamp.off, (int)(System.currentTimeMillis()/1000));
+        header.putInt(IMAGE_FILE_HEADER.TimeDateStamp.off, (int) (System.currentTimeMillis() / 1000));
         header.putInt(IMAGE_FILE_HEADER.PointerToSymbolTable.off, 0);
         header.putInt(IMAGE_FILE_HEADER.NumberOfSymbols.off, 0);
-        header.putChar(IMAGE_FILE_HEADER.SizeOfOptionalHeader.off, (char)0);
-        header.putChar(IMAGE_FILE_HEADER.Characteristics.off, (char)0);
+        header.putChar(IMAGE_FILE_HEADER.SizeOfOptionalHeader.off, (char) 0);
+        header.putChar(IMAGE_FILE_HEADER.Characteristics.off, (char) 0);
 
     }
 
     // Update header with the number of total sections
-    public void setSectionCount(int count) {
-        header.putChar(IMAGE_FILE_HEADER.NumberOfSections.off, (char)count);
+    void setSectionCount(int count) {
+        header.putChar(IMAGE_FILE_HEADER.NumberOfSections.off, (char) count);
     }
 
     // Update header with the number of total symbols
-    public void setSymbolCount(int count) {
+    void setSymbolCount(int count) {
         header.putInt(IMAGE_FILE_HEADER.NumberOfSymbols.off, count);
     }
 
     // Update header with the offset of symbol table
-    public void setSymbolOff(int offset) {
+    void setSymbolOff(int offset) {
         header.putInt(IMAGE_FILE_HEADER.PointerToSymbolTable.off, offset);
     }
 
-    public byte[] getArray() {
+    byte[] getArray() {
         return header.array();
     }
 }
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffRelocEntry.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffRelocEntry.java	Wed Sep 20 23:55:35 2017 -0400
@@ -24,26 +24,23 @@
 package jdk.tools.jaotc.binformat.pecoff;
 
 import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
 
-import jdk.tools.jaotc.binformat.pecoff.PECoff;
 import jdk.tools.jaotc.binformat.pecoff.PECoff.IMAGE_RELOCATION;
 import jdk.tools.jaotc.binformat.pecoff.PECoffByteBuffer;
 
-public class PECoffRelocEntry {
-    ByteBuffer entry;
+final class PECoffRelocEntry {
+    private final ByteBuffer entry;
 
-    public PECoffRelocEntry(int offset, int symno, int type) {
+    PECoffRelocEntry(int offset, int symno, int type) {
 
         entry = PECoffByteBuffer.allocate(IMAGE_RELOCATION.totalsize);
 
         entry.putInt(IMAGE_RELOCATION.VirtualAddress.off, offset);
         entry.putInt(IMAGE_RELOCATION.SymbolTableIndex.off, symno);
-        entry.putChar(IMAGE_RELOCATION.Type.off, (char)type);
+        entry.putChar(IMAGE_RELOCATION.Type.off, (char) type);
     }
 
-    public byte[] getArray() {
+    byte[] getArray() {
         return entry.array();
     }
 }
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffRelocTable.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffRelocTable.java	Wed Sep 20 23:55:35 2017 -0400
@@ -25,52 +25,47 @@
 
 import java.util.ArrayList;
 import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
 
-import jdk.tools.jaotc.binformat.pecoff.PECoff;
 import jdk.tools.jaotc.binformat.pecoff.PECoff.IMAGE_RELOCATION;
 import jdk.tools.jaotc.binformat.pecoff.PECoffRelocEntry;
 import jdk.tools.jaotc.binformat.pecoff.PECoffByteBuffer;
 
-public class PECoffRelocTable {
+final class PECoffRelocTable {
     ArrayList<ArrayList<PECoffRelocEntry>> relocEntries;
 
-    public PECoffRelocTable(int numsects) {
-        relocEntries = new ArrayList<ArrayList<PECoffRelocEntry>>(numsects);
-        for (int i = 0; i < numsects; i++)
+    PECoffRelocTable(int numsects) {
+        relocEntries = new ArrayList<>(numsects);
+        for (int i = 0; i < numsects; i++) {
             relocEntries.add(new ArrayList<PECoffRelocEntry>());
+        }
     }
 
-    public void createRelocationEntry(int sectindex,
-                                      int offset,
-                                      int symno,
-                                      int type) {
-
-        PECoffRelocEntry entry = new PECoffRelocEntry(offset,
-                                                symno,
-                                                type);
+    void createRelocationEntry(int sectindex, int offset, int symno, int type) {
+        PECoffRelocEntry entry = new PECoffRelocEntry(offset, symno, type);
         relocEntries.get(sectindex).add(entry);
     }
 
-    public int getAlign() { return (4); }
+    static int getAlign() {
+        return (4);
+    }
 
-    public int getNumRelocs(int section_index) {
+    int getNumRelocs(int section_index) {
         return relocEntries.get(section_index).size();
     }
 
     // Return the relocation entries for a single section
-    //   or null if no entries added to section
-    public byte [] getRelocData(int section_index) {
+    // or null if no entries added to section
+    byte[] getRelocData(int section_index) {
         ArrayList<PECoffRelocEntry> entryList = relocEntries.get(section_index);
         int entryCount = entryList.size();
         int allocCount = entryCount;
 
-        if (entryCount == 0)
+        if (entryCount == 0) {
             return null;
-
-        if (entryCount > 0xFFFF)
+        }
+        if (entryCount > 0xFFFF) {
             allocCount++;
-
+        }
         ByteBuffer relocData = PECoffByteBuffer.allocate(allocCount * IMAGE_RELOCATION.totalsize);
 
         // If number of relocs exceeds 65K, add the real size
@@ -89,4 +84,3 @@
         return (relocData.array());
     }
 }
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffSection.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffSection.java	Wed Sep 20 23:55:35 2017 -0400
@@ -24,32 +24,39 @@
 package jdk.tools.jaotc.binformat.pecoff;
 
 import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
 
-import jdk.tools.jaotc.binformat.pecoff.PECoff;
 import jdk.tools.jaotc.binformat.pecoff.PECoff.IMAGE_SECTION_HEADER;
 import jdk.tools.jaotc.binformat.pecoff.PECoffByteBuffer;
 
-public class PECoffSection {
-    ByteBuffer section;
-    byte [] data;
-    boolean hasrelocations;
-    int sectionIndex;
-    int align;
+final class PECoffSection {
+    private final ByteBuffer section;
+    private final byte[] data;
+    private final boolean hasrelocations;
+    private final int sectionIndex;
+    private final int align;
 
-    public PECoffSection(String sectName, byte [] sectData, int sectFlags,
-                         boolean hasRelocations, int sectIndex) {
+    PECoffSection(String sectName, byte[] sectData0, int sectFlags0, int sectAlign, boolean hasRelocations, int sectIndex) {
 
         section = PECoffByteBuffer.allocate(IMAGE_SECTION_HEADER.totalsize);
 
-        // bug: If JVM.oop.got section is empty, VM exits since JVM.oop.got
-        //      symbol ends up as external forwarded reference.
-        if (sectData.length == 0) sectData = new byte[8];
+        // If .oop.got section is empty, VM exits since .oop.got
+        // symbol ends up as external forwarded reference.
+        byte[] sectData = sectData0;
+        if (sectData0.length == 0) {
+            sectData = new byte[8];
+        }
 
         // Copy only Max allowed bytes to Section Entry
-        byte [] Name = sectName.getBytes();
-        int max = Name.length <= IMAGE_SECTION_HEADER.Name.sz ?
-                  Name.length : IMAGE_SECTION_HEADER.Name.sz;
+        byte[] Name = sectName.getBytes();
+        int max = Name.length <= IMAGE_SECTION_HEADER.Name.sz ? Name.length : IMAGE_SECTION_HEADER.Name.sz;
+
+        assert (sectAlign < 1 || sectAlign > 1024 || (sectAlign & (sectAlign - 1)) != 0) : "section alignment is not valid: " + sectAlign;
+        align = sectAlign;
+
+        // Using 32 because IMAGE_SCN_ALIGN_*BYTES is value + 1
+        int sectAlignBits = (32 - Integer.numberOfLeadingZeros(align)) << IMAGE_SECTION_HEADER.IMAGE_SCN_ALIGN_SHIFT;
+        // Clear and set alignment bits
+        int sectFlags = (sectFlags0 & ~IMAGE_SECTION_HEADER.IMAGE_SCN_ALIGN_MASK) | (sectAlignBits & IMAGE_SECTION_HEADER.IMAGE_SCN_ALIGN_MASK);
 
         section.put(Name, IMAGE_SECTION_HEADER.Name.off, max);
 
@@ -57,84 +64,69 @@
         section.putInt(IMAGE_SECTION_HEADER.VirtualAddress.off, 0);
         section.putInt(IMAGE_SECTION_HEADER.SizeOfRawData.off, sectData.length);
         section.putInt(IMAGE_SECTION_HEADER.PointerToLinenumbers.off, 0);
-        section.putChar(IMAGE_SECTION_HEADER.NumberOfLinenumbers.off, (char)0);
+        section.putChar(IMAGE_SECTION_HEADER.NumberOfLinenumbers.off, (char) 0);
 
         section.putInt(IMAGE_SECTION_HEADER.Characteristics.off, sectFlags);
 
-        // Extract alignment from Characteristics field
-        int alignshift = (sectFlags & IMAGE_SECTION_HEADER.IMAGE_SCN_ALIGN_MASK) >>
-                                       IMAGE_SECTION_HEADER.IMAGE_SCN_ALIGN_SHIFT;
-
-        // Use 8 byte alignment if not specified
-        if (alignshift == 0)
-            alignshift = 3;
-        else
-            --alignshift;
-
-        align = 1 << alignshift;
-
         data = sectData;
         hasrelocations = hasRelocations;
         sectionIndex = sectIndex;
     }
 
-    public long getSize() {
+    long getSize() {
         return section.getInt(IMAGE_SECTION_HEADER.SizeOfRawData.off);
     }
 
-    public int getDataAlign() {
+    int getDataAlign() {
         return (align);
     }
 
     // Alignment requirements for the IMAGE_SECTION_HEADER structures
-    public static int getShdrAlign() {
+    static int getShdrAlign() {
         return (4);
     }
 
-    public byte[] getArray() {
+    byte[] getArray() {
         return section.array();
     }
 
-    public byte[] getDataArray() {
+    byte[] getDataArray() {
         return data;
     }
 
-    public void setOffset(long offset) {
-        section.putInt(IMAGE_SECTION_HEADER.PointerToRawData.off, (int)offset);
+    void setOffset(long offset) {
+        section.putInt(IMAGE_SECTION_HEADER.PointerToRawData.off, (int) offset);
     }
 
-    public long getOffset() {
+    long getOffset() {
         return (section.getInt(IMAGE_SECTION_HEADER.PointerToRawData.off));
     }
 
-    public void setReloff(int offset) {
+    void setReloff(int offset) {
         section.putInt(IMAGE_SECTION_HEADER.PointerToRelocations.off, offset);
     }
 
-    public void setRelcount(int count) {
+    void setRelcount(int count) {
         // If the number of relocs is larger than 65K, then set
-        // the overflow bit.  The real count will be written to
+        // the overflow bit. The real count will be written to
         // the first reloc entry for this section.
         if (count > 0xFFFF) {
             int flags;
-            section.putChar(IMAGE_SECTION_HEADER.NumberOfRelocations.off, (char)0xFFFF);
+            section.putChar(IMAGE_SECTION_HEADER.NumberOfRelocations.off, (char) 0xFFFF);
             flags = section.getInt(IMAGE_SECTION_HEADER.Characteristics.off);
             flags |= IMAGE_SECTION_HEADER.IMAGE_SCN_LNK_NRELOC_OVFL;
             section.putInt(IMAGE_SECTION_HEADER.Characteristics.off, flags);
-        }
-        else {
-            section.putChar(IMAGE_SECTION_HEADER.NumberOfRelocations.off, (char)count);
+        } else {
+            section.putChar(IMAGE_SECTION_HEADER.NumberOfRelocations.off, (char) count);
         }
     }
 
-    public boolean hasRelocations() {
+    boolean hasRelocations() {
         return hasrelocations;
     }
 
-    public int getSectionId() {
+    int getSectionId() {
         return sectionIndex;
     }
 
 }
-
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffSymbol.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffSymbol.java	Wed Sep 20 23:55:35 2017 -0400
@@ -24,18 +24,15 @@
 package jdk.tools.jaotc.binformat.pecoff;
 
 import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
 
 import jdk.tools.jaotc.binformat.NativeSymbol;
-import jdk.tools.jaotc.binformat.pecoff.PECoff;
 import jdk.tools.jaotc.binformat.pecoff.PECoff.IMAGE_SYMBOL;
 import jdk.tools.jaotc.binformat.pecoff.PECoffByteBuffer;
 
-public class PECoffSymbol extends NativeSymbol {
-    ByteBuffer sym;
+final class PECoffSymbol extends NativeSymbol {
+    private final ByteBuffer sym;
 
-    public PECoffSymbol(int symbolindex, int strindex, byte type, byte storageclass,
-                        byte sectindex, long offset, long size) {
+    PECoffSymbol(int symbolindex, int strindex, byte type, byte storageclass, byte sectindex, long offset) {
         super(symbolindex);
         sym = PECoffByteBuffer.allocate(IMAGE_SYMBOL.totalsize);
 
@@ -43,19 +40,18 @@
         sym.putInt(IMAGE_SYMBOL.Short.off, 0);
 
         sym.putInt(IMAGE_SYMBOL.Long.off, strindex);
-        sym.putInt(IMAGE_SYMBOL.Value.off, (int)offset);
+        sym.putInt(IMAGE_SYMBOL.Value.off, (int) offset);
 
         // Section indexes start at 1 but we manage the index internally
         // as 0 relative except in this structure
-        sym.putChar(IMAGE_SYMBOL.SectionNumber.off, (char)(sectindex+1));
+        sym.putChar(IMAGE_SYMBOL.SectionNumber.off, (char) (sectindex + 1));
 
-        sym.putChar(IMAGE_SYMBOL.Type.off, (char)type);
+        sym.putChar(IMAGE_SYMBOL.Type.off, (char) type);
         sym.put(IMAGE_SYMBOL.StorageClass.off, storageclass);
-        sym.put(IMAGE_SYMBOL.NumberOfAuxSymbols.off, (byte)0);
+        sym.put(IMAGE_SYMBOL.NumberOfAuxSymbols.off, (byte) 0);
     }
 
-    public byte[] getArray() {
+    byte[] getArray() {
         return sym.array();
     }
 }
-
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffSymtab.java	Mon Sep 11 23:44:23 2017 -0400
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffSymtab.java	Wed Sep 20 23:55:35 2017 -0400
@@ -27,36 +27,35 @@
 import java.nio.ByteOrder;
 import java.util.ArrayList;
 
-import jdk.tools.jaotc.binformat.pecoff.PECoff;
 import jdk.tools.jaotc.binformat.pecoff.PECoff.IMAGE_SYMBOL;
 import jdk.tools.jaotc.binformat.pecoff.PECoffSymbol;
 import jdk.tools.jaotc.binformat.pecoff.PECoffByteBuffer;
 
-public class PECoffSymtab {
-    ArrayList<PECoffSymbol>symbols = new ArrayList<PECoffSymbol>();
+final class PECoffSymtab {
+    ArrayList<PECoffSymbol> symbols = new ArrayList<>();
 
     /**
      * number of symbols added
      */
-    int symbolCount;
+    private int symbolCount;
 
     /**
      * String holding symbol table strings
      */
-    private StringBuilder strTabContent;
+    private final StringBuilder strTabContent;
 
     /**
-     * Keeps track of bytes in string table since strTabContent.length()
-     * is number of chars, not bytes.
+     * Keeps track of bytes in string table since strTabContent.length() is number of chars, not
+     * bytes.
      */
     private int strTabNrOfBytes;
 
     /**
      * String holding Linker Directives
      */
-    private StringBuilder directives;
+    private final StringBuilder directives;
 
-    public PECoffSymtab() {
+    PECoffSymtab() {
         symbolCount = 0;
         strTabContent = new StringBuilder();
         directives = new StringBuilder();
@@ -72,8 +71,7 @@
         directives.append("   ");
     }
 
-    public PECoffSymbol addSymbolEntry(String name, byte type, byte storageclass,
-                                    byte secHdrIndex, long offset, long size) {
+    PECoffSymbol addSymbolEntry(String name, byte type, byte storageclass, byte secHdrIndex, long offset) {
         // Get the current symbol index and append symbol name to string table.
         int index;
         PECoffSymbol sym;
@@ -82,7 +80,7 @@
             index = 0;
             strTabContent.append('\0');
             strTabNrOfBytes += 1;
-            sym = new PECoffSymbol(symbolCount, index, type, storageclass, secHdrIndex, offset, size);
+            sym = new PECoffSymbol(symbolCount, index, type, storageclass, secHdrIndex, offset);
             symbols.add(sym);
         } else {
             int nameSize = name.getBytes().length;
@@ -94,10 +92,11 @@
             strTabContent.append(name).append('\0');
             strTabNrOfBytes += (nameSize + 1);
 
-            sym = new PECoffSymbol(symbolCount, index, type, storageclass, secHdrIndex, offset