Merge
authorlana
Fri, 16 Oct 2009 18:02:31 -0700
changeset 4247 8112127c60be
parent 4246 e2b24661047a (current diff)
parent 4037 a2f5f4bdcd5b (diff)
child 4248 73d530928788
Merge
jdk/src/share/native/sun/security/ec/ec.h
jdk/src/share/native/sun/security/ec/ec2.h
jdk/src/share/native/sun/security/ec/ec2_163.c
jdk/src/share/native/sun/security/ec/ec2_193.c
jdk/src/share/native/sun/security/ec/ec2_233.c
jdk/src/share/native/sun/security/ec/ec2_aff.c
jdk/src/share/native/sun/security/ec/ec2_mont.c
jdk/src/share/native/sun/security/ec/ec_naf.c
jdk/src/share/native/sun/security/ec/ecc_impl.h
jdk/src/share/native/sun/security/ec/ecdecode.c
jdk/src/share/native/sun/security/ec/ecl-curve.h
jdk/src/share/native/sun/security/ec/ecl-exp.h
jdk/src/share/native/sun/security/ec/ecl-priv.h
jdk/src/share/native/sun/security/ec/ecl.c
jdk/src/share/native/sun/security/ec/ecl.h
jdk/src/share/native/sun/security/ec/ecl_curve.c
jdk/src/share/native/sun/security/ec/ecl_gf.c
jdk/src/share/native/sun/security/ec/ecl_mult.c
jdk/src/share/native/sun/security/ec/ecp.h
jdk/src/share/native/sun/security/ec/ecp_192.c
jdk/src/share/native/sun/security/ec/ecp_224.c
jdk/src/share/native/sun/security/ec/ecp_256.c
jdk/src/share/native/sun/security/ec/ecp_384.c
jdk/src/share/native/sun/security/ec/ecp_521.c
jdk/src/share/native/sun/security/ec/ecp_aff.c
jdk/src/share/native/sun/security/ec/ecp_jac.c
jdk/src/share/native/sun/security/ec/ecp_jm.c
jdk/src/share/native/sun/security/ec/ecp_mont.c
jdk/src/share/native/sun/security/ec/logtab.h
jdk/src/share/native/sun/security/ec/mp_gf2m-priv.h
jdk/src/share/native/sun/security/ec/mp_gf2m.c
jdk/src/share/native/sun/security/ec/mp_gf2m.h
jdk/src/share/native/sun/security/ec/mpi-config.h
jdk/src/share/native/sun/security/ec/mpi-priv.h
jdk/src/share/native/sun/security/ec/mpi.c
jdk/src/share/native/sun/security/ec/mpi.h
jdk/src/share/native/sun/security/ec/mplogic.c
jdk/src/share/native/sun/security/ec/mplogic.h
jdk/src/share/native/sun/security/ec/mpmontg.c
jdk/src/share/native/sun/security/ec/mpprime.h
jdk/src/share/native/sun/security/ec/oid.c
jdk/src/share/native/sun/security/ec/secitem.c
jdk/src/share/native/sun/security/ec/secoidt.h
langtools/src/share/classes/com/sun/tools/javac/file/Old199.java
langtools/src/share/classes/com/sun/tools/javah/MainDoclet.java
langtools/src/share/classes/com/sun/tools/javah/resources/Linux_ppc.properties
langtools/src/share/classes/com/sun/tools/javah/resources/Linux_sparc.properties
langtools/src/share/classes/com/sun/tools/javah/resources/SunOS_sparc.properties
langtools/src/share/classes/com/sun/tools/javah/resources/SunOS_sparcv9.properties
langtools/src/share/classes/com/sun/tools/javah/resources/win32_x86.properties
--- a/.hgtags	Fri Oct 16 09:32:29 2009 -0700
+++ b/.hgtags	Fri Oct 16 18:02:31 2009 -0700
@@ -47,3 +47,4 @@
 207f694795c448c17753eff1a2f50363106960c2 jdk7-b70
 c5d39b6be65cba0effb5f466ea48fe43764d0e0c jdk7-b71
 df4bcd06e1d0ab306efa5a44f24a409dc0c0c742 jdk7-b72
+ce74bd35ce948d629a356e168797f44b593b1578 jdk7-b73
--- a/.hgtags-top-repo	Fri Oct 16 09:32:29 2009 -0700
+++ b/.hgtags-top-repo	Fri Oct 16 18:02:31 2009 -0700
@@ -47,3 +47,4 @@
 175cb3fe615998d1004c6d3fd96e6d2e86b6772d jdk7-b70
 4c36e9853dda27bdac5ef4839a610509fbe31d34 jdk7-b71
 0d7e03b426df27c21dcc44ffb9178eacd1b04f10 jdk7-b72
+3ac6dcf7823205546fbbc3d4ea59f37358d0b0d4 jdk7-b73
--- a/corba/.hgtags	Fri Oct 16 09:32:29 2009 -0700
+++ b/corba/.hgtags	Fri Oct 16 18:02:31 2009 -0700
@@ -47,3 +47,4 @@
 175bd68779546078dbdb6dacd7f0aced79ed22b1 jdk7-b70
 3f1ef7f899ea2aec189c4fb67e5c8fa374437c50 jdk7-b71
 c793a31209263fbb867c23c752599d85c21abb73 jdk7-b72
+b751c528c55560cf2adeaeef24b39ca1f4d1cbf7 jdk7-b73
--- a/hotspot/.hgtags	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/.hgtags	Fri Oct 16 18:02:31 2009 -0700
@@ -47,3 +47,4 @@
 0632c3e615a315ff11e2ab1d64f4d82ff9853461 jdk7-b70
 50a95aa4a247f0cbbf66df285a8b1d78ffb153d9 jdk7-b71
 a94714c550658fd6741793ef036cb9625dc2ab1a jdk7-b72
+faf94d94786b621f8e13cbcc941ca69c6d967c3f jdk7-b73
--- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/code/CodeCache.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/code/CodeCache.java	Fri Oct 16 18:02:31 2009 -0700
@@ -33,6 +33,7 @@
 
 public class CodeCache {
   private static AddressField       heapField;
+  private static AddressField       scavengeRootNMethodsField;
   private static VirtualConstructor virtualConstructor;
 
   private CodeHeap heap;
@@ -49,6 +50,7 @@
     Type type = db.lookupType("CodeCache");
 
     heapField = type.getAddressField("_heap");
+    scavengeRootNMethodsField = type.getAddressField("_scavenge_root_nmethods");
 
     virtualConstructor = new VirtualConstructor(db);
     // Add mappings for all possible CodeBlob subclasses
@@ -67,6 +69,10 @@
     heap = (CodeHeap) VMObjectFactory.newObject(CodeHeap.class, heapField.getValue());
   }
 
+  public NMethod scavengeRootMethods() {
+    return (NMethod) VMObjectFactory.newObject(NMethod.class, scavengeRootNMethodsField.getValue());
+  }
+
   public boolean contains(Address p) {
     return getHeap().contains(p);
   }
--- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/code/NMethod.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/code/NMethod.java	Fri Oct 16 18:02:31 2009 -0700
@@ -40,7 +40,10 @@
   /** != InvocationEntryBci if this nmethod is an on-stack replacement method */
   private static CIntegerField entryBCIField;
   /** To support simple linked-list chaining of nmethods */
-  private static AddressField  linkField;
+  private static AddressField  osrLinkField;
+  private static AddressField  scavengeRootLinkField;
+  private static CIntegerField scavengeRootStateField;
+
   /** Offsets for different nmethod parts */
   private static CIntegerField exceptionOffsetField;
   private static CIntegerField deoptOffsetField;
@@ -87,7 +90,10 @@
     zombieInstructionSizeField  = type.getCIntegerField("_zombie_instruction_size");
     methodField                 = type.getOopField("_method");
     entryBCIField               = type.getCIntegerField("_entry_bci");
-    linkField                   = type.getAddressField("_link");
+    osrLinkField                = type.getAddressField("_osr_link");
+    scavengeRootLinkField       = type.getAddressField("_scavenge_root_link");
+    scavengeRootStateField      = type.getCIntegerField("_scavenge_root_state");
+
     exceptionOffsetField        = type.getCIntegerField("_exception_offset");
     deoptOffsetField            = type.getCIntegerField("_deoptimize_offset");
     origPCOffsetField           = type.getCIntegerField("_orig_pc_offset");
@@ -219,10 +225,19 @@
     return getEntryBCI();
   }
 
-  public NMethod getLink() {
-    return (NMethod) VMObjectFactory.newObject(NMethod.class, linkField.getValue(addr));
+  public NMethod getOSRLink() {
+    return (NMethod) VMObjectFactory.newObject(NMethod.class, osrLinkField.getValue(addr));
   }
 
+  public NMethod getScavengeRootLink() {
+    return (NMethod) VMObjectFactory.newObject(NMethod.class, scavengeRootLinkField.getValue(addr));
+  }
+
+  public int getScavengeRootState() {
+    return (int) scavengeRootStateField.getValue(addr);
+  }
+
+
   /** Tells whether frames described by this nmethod can be
       deoptimized. Note: native wrappers cannot be deoptimized. */
   public boolean canBeDeoptimized() { return isJavaMethod(); }
--- a/hotspot/make/hotspot_version	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/make/hotspot_version	Fri Oct 16 18:02:31 2009 -0700
@@ -35,7 +35,7 @@
 
 HS_MAJOR_VER=17
 HS_MINOR_VER=0
-HS_BUILD_NUMBER=02
+HS_BUILD_NUMBER=03
 
 JDK_MAJOR_VER=1
 JDK_MINOR_VER=7
--- a/hotspot/src/cpu/sparc/vm/assembler_sparc.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/cpu/sparc/vm/assembler_sparc.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -4676,3 +4676,50 @@
     load_ptr_contents(base, G6_heapbase);
   }
 }
+
+// Compare char[] arrays aligned to 4 bytes.
+void MacroAssembler::char_arrays_equals(Register ary1, Register ary2,
+                                        Register limit, Register result,
+                                        Register chr1, Register chr2, Label& Ldone) {
+  Label Lvector, Lloop;
+  assert(chr1 == result, "should be the same");
+
+  // Note: limit contains number of bytes (2*char_elements) != 0.
+  andcc(limit, 0x2, chr1); // trailing character ?
+  br(Assembler::zero, false, Assembler::pt, Lvector);
+  delayed()->nop();
+
+  // compare the trailing char
+  sub(limit, sizeof(jchar), limit);
+  lduh(ary1, limit, chr1);
+  lduh(ary2, limit, chr2);
+  cmp(chr1, chr2);
+  br(Assembler::notEqual, true, Assembler::pt, Ldone);
+  delayed()->mov(G0, result);     // not equal
+
+  // only one char ?
+  br_on_reg_cond(rc_z, true, Assembler::pn, limit, Ldone);
+  delayed()->add(G0, 1, result); // zero-length arrays are equal
+
+  // word by word compare, dont't need alignment check
+  bind(Lvector);
+  // Shift ary1 and ary2 to the end of the arrays, negate limit
+  add(ary1, limit, ary1);
+  add(ary2, limit, ary2);
+  neg(limit, limit);
+
+  lduw(ary1, limit, chr1);
+  bind(Lloop);
+  lduw(ary2, limit, chr2);
+  cmp(chr1, chr2);
+  br(Assembler::notEqual, true, Assembler::pt, Ldone);
+  delayed()->mov(G0, result);     // not equal
+  inccc(limit, 2*sizeof(jchar));
+  // annul LDUW if branch is not taken to prevent access past end of array
+  br(Assembler::notZero, true, Assembler::pt, Lloop);
+  delayed()->lduw(ary1, limit, chr1); // hoisted
+
+  // Caller should set it:
+  // add(G0, 1, result); // equals
+}
+
--- a/hotspot/src/cpu/sparc/vm/assembler_sparc.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/cpu/sparc/vm/assembler_sparc.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -2455,6 +2455,11 @@
   void inc_counter(address counter_addr, Register Rtmp1, Register Rtmp2);
   void inc_counter(int*    counter_addr, Register Rtmp1, Register Rtmp2);
 
+  // Compare char[] arrays aligned to 4 bytes.
+  void char_arrays_equals(Register ary1, Register ary2,
+                          Register limit, Register result,
+                          Register chr1, Register chr2, Label& Ldone);
+
 #undef VIRTUAL
 
 };
--- a/hotspot/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -2171,7 +2171,7 @@
     // subtype which we can't check or src is the same array as dst
     // but not necessarily exactly of type default_type.
     Label known_ok, halt;
-    jobject2reg(op->expected_type()->encoding(), tmp);
+    jobject2reg(op->expected_type()->constant_encoding(), tmp);
     __ ld_ptr(dst, oopDesc::klass_offset_in_bytes(), tmp2);
     if (basic_type != T_OBJECT) {
       __ cmp(tmp, tmp2);
@@ -2429,7 +2429,7 @@
       assert(data->is_BitData(), "need BitData for checkcast");
       Register mdo      = k_RInfo;
       Register data_val = Rtmp1;
-      jobject2reg(md->encoding(), mdo);
+      jobject2reg(md->constant_encoding(), mdo);
 
       int mdo_offset_bias = 0;
       if (!Assembler::is_simm13(md->byte_offset_of_slot(data, DataLayout::header_offset()) + data->size_in_bytes())) {
@@ -2452,7 +2452,7 @@
     // patching may screw with our temporaries on sparc,
     // so let's do it before loading the class
     if (k->is_loaded()) {
-      jobject2reg(k->encoding(), k_RInfo);
+      jobject2reg(k->constant_encoding(), k_RInfo);
     } else {
       jobject2reg_with_patching(k_RInfo, op->info_for_patch());
     }
@@ -2513,7 +2513,7 @@
     // patching may screw with our temporaries on sparc,
     // so let's do it before loading the class
     if (k->is_loaded()) {
-      jobject2reg(k->encoding(), k_RInfo);
+      jobject2reg(k->constant_encoding(), k_RInfo);
     } else {
       jobject2reg_with_patching(k_RInfo, op->info_for_patch());
     }
@@ -2717,7 +2717,7 @@
   assert(op->tmp1()->is_single_cpu(), "tmp1 must be allocated");
   Register mdo  = op->mdo()->as_register();
   Register tmp1 = op->tmp1()->as_register();
-  jobject2reg(md->encoding(), mdo);
+  jobject2reg(md->constant_encoding(), mdo);
   int mdo_offset_bias = 0;
   if (!Assembler::is_simm13(md->byte_offset_of_slot(data, CounterData::count_offset()) +
                             data->size_in_bytes())) {
@@ -2774,7 +2774,7 @@
         if (receiver == NULL) {
           Address recv_addr(mdo, md->byte_offset_of_slot(data, VirtualCallData::receiver_offset(i)) -
                             mdo_offset_bias);
-          jobject2reg(known_klass->encoding(), tmp1);
+          jobject2reg(known_klass->constant_encoding(), tmp1);
           __ st_ptr(tmp1, recv_addr);
           Address data_addr(mdo, md->byte_offset_of_slot(data, VirtualCallData::receiver_count_offset(i)) -
                             mdo_offset_bias);
--- a/hotspot/src/cpu/sparc/vm/c1_LIRGenerator_sparc.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/cpu/sparc/vm/c1_LIRGenerator_sparc.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -668,7 +668,7 @@
   __ add(obj.result(), offset.result(), addr);
 
   if (type == objectType) {  // Write-barrier needed for Object fields.
-    pre_barrier(obj.result(), false, NULL);
+    pre_barrier(addr, false, NULL);
   }
 
   if (type == objectType)
@@ -896,7 +896,7 @@
   LIR_Opr len = length.result();
   BasicType elem_type = x->elt_type();
 
-  __ oop2reg(ciTypeArrayKlass::make(elem_type)->encoding(), klass_reg);
+  __ oop2reg(ciTypeArrayKlass::make(elem_type)->constant_encoding(), klass_reg);
 
   CodeStub* slow_path = new NewTypeArrayStub(klass_reg, len, reg, info);
   __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, elem_type, klass_reg, slow_path);
--- a/hotspot/src/cpu/sparc/vm/sparc.ad	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/cpu/sparc/vm/sparc.ad	Fri Oct 16 18:02:31 2009 -0700
@@ -2838,63 +2838,41 @@
   %}
 
 
-  enc_class enc_String_Compare(o0RegP str1, o1RegP str2, g3RegP tmp1, g4RegP tmp2, notemp_iRegI result) %{
+  enc_class enc_String_Compare(o0RegP str1, o1RegP str2, g3RegI cnt1, g4RegI cnt2, notemp_iRegI result) %{
     Label Ldone, Lloop;
     MacroAssembler _masm(&cbuf);
 
     Register   str1_reg = reg_to_register_object($str1$$reg);
     Register   str2_reg = reg_to_register_object($str2$$reg);
-    Register   tmp1_reg = reg_to_register_object($tmp1$$reg);
-    Register   tmp2_reg = reg_to_register_object($tmp2$$reg);
+    Register   cnt1_reg = reg_to_register_object($cnt1$$reg);
+    Register   cnt2_reg = reg_to_register_object($cnt2$$reg);
     Register result_reg = reg_to_register_object($result$$reg);
 
-    // Get the first character position in both strings
-    //         [8] char array, [12] offset, [16] count
-    int  value_offset = java_lang_String:: value_offset_in_bytes();
-    int offset_offset = java_lang_String::offset_offset_in_bytes();
-    int  count_offset = java_lang_String:: count_offset_in_bytes();
-
-    // load str1 (jchar*) base address into tmp1_reg
-    __ load_heap_oop(str1_reg, value_offset, tmp1_reg);
-    __ ld(str1_reg, offset_offset, result_reg);
-    __ add(tmp1_reg, arrayOopDesc::base_offset_in_bytes(T_CHAR), tmp1_reg);
-    __   ld(str1_reg, count_offset, str1_reg); // hoisted
-    __ sll(result_reg, exact_log2(sizeof(jchar)), result_reg);
-    __   load_heap_oop(str2_reg, value_offset, tmp2_reg); // hoisted
-    __ add(result_reg, tmp1_reg, tmp1_reg);
-
-    // load str2 (jchar*) base address into tmp2_reg
-    // __ ld_ptr(str2_reg, value_offset, tmp2_reg); // hoisted
-    __ ld(str2_reg, offset_offset, result_reg);
-    __ add(tmp2_reg, arrayOopDesc::base_offset_in_bytes(T_CHAR), tmp2_reg);
-    __   ld(str2_reg, count_offset, str2_reg); // hoisted
-    __ sll(result_reg, exact_log2(sizeof(jchar)), result_reg);
-    __   subcc(str1_reg, str2_reg, O7); // hoisted
-    __ add(result_reg, tmp2_reg, tmp2_reg);
+    assert(result_reg != str1_reg &&
+           result_reg != str2_reg &&
+           result_reg != cnt1_reg &&
+           result_reg != cnt2_reg ,
+           "need different registers");
 
     // Compute the minimum of the string lengths(str1_reg) and the
     // difference of the string lengths (stack)
 
-    // discard string base pointers, after loading up the lengths
-    // __ ld(str1_reg, count_offset, str1_reg); // hoisted
-    // __ ld(str2_reg, count_offset, str2_reg); // hoisted
-
     // See if the lengths are different, and calculate min in str1_reg.
     // Stash diff in O7 in case we need it for a tie-breaker.
     Label Lskip;
-    // __ subcc(str1_reg, str2_reg, O7); // hoisted
-    __ sll(str1_reg, exact_log2(sizeof(jchar)), str1_reg); // scale the limit
+    __ subcc(cnt1_reg, cnt2_reg, O7);
+    __ sll(cnt1_reg, exact_log2(sizeof(jchar)), cnt1_reg); // scale the limit
     __ br(Assembler::greater, true, Assembler::pt, Lskip);
-    // str2 is shorter, so use its count:
-    __ delayed()->sll(str2_reg, exact_log2(sizeof(jchar)), str1_reg); // scale the limit
+    // cnt2 is shorter, so use its count:
+    __ delayed()->sll(cnt2_reg, exact_log2(sizeof(jchar)), cnt1_reg); // scale the limit
     __ bind(Lskip);
 
-    // reallocate str1_reg, str2_reg, result_reg
+    // reallocate cnt1_reg, cnt2_reg, result_reg
     // Note:  limit_reg holds the string length pre-scaled by 2
-    Register limit_reg =   str1_reg;
-    Register  chr2_reg =   str2_reg;
+    Register limit_reg =   cnt1_reg;
+    Register  chr2_reg =   cnt2_reg;
     Register  chr1_reg = result_reg;
-    // tmp{12} are the base pointers
+    // str{12} are the base pointers
 
     // Is the minimum length zero?
     __ cmp(limit_reg, (int)(0 * sizeof(jchar))); // use cast to resolve overloading ambiguity
@@ -2902,8 +2880,8 @@
     __ delayed()->mov(O7, result_reg);  // result is difference in lengths
 
     // Load first characters
-    __ lduh(tmp1_reg, 0, chr1_reg);
-    __ lduh(tmp2_reg, 0, chr2_reg);
+    __ lduh(str1_reg, 0, chr1_reg);
+    __ lduh(str2_reg, 0, chr2_reg);
 
     // Compare first characters
     __ subcc(chr1_reg, chr2_reg, chr1_reg);
@@ -2915,7 +2893,7 @@
       // Check after comparing first character to see if strings are equivalent
       Label LSkip2;
       // Check if the strings start at same location
-      __ cmp(tmp1_reg, tmp2_reg);
+      __ cmp(str1_reg, str2_reg);
       __ brx(Assembler::notEqual, true, Assembler::pt, LSkip2);
       __ delayed()->nop();
 
@@ -2932,23 +2910,23 @@
     __ br(Assembler::equal, true, Assembler::pn, Ldone);
     __ delayed()->mov(O7, result_reg);  // result is difference in lengths
 
-    // Shift tmp1_reg and tmp2_reg to the end of the arrays, negate limit
-    __ add(tmp1_reg, limit_reg, tmp1_reg);
-    __ add(tmp2_reg, limit_reg, tmp2_reg);
+    // Shift str1_reg and str2_reg to the end of the arrays, negate limit
+    __ add(str1_reg, limit_reg, str1_reg);
+    __ add(str2_reg, limit_reg, str2_reg);
     __ neg(chr1_reg, limit_reg);  // limit = -(limit-2)
 
     // Compare the rest of the characters
-    __ lduh(tmp1_reg, limit_reg, chr1_reg);
+    __ lduh(str1_reg, limit_reg, chr1_reg);
     __ bind(Lloop);
-    // __ lduh(tmp1_reg, limit_reg, chr1_reg); // hoisted
-    __ lduh(tmp2_reg, limit_reg, chr2_reg);
+    // __ lduh(str1_reg, limit_reg, chr1_reg); // hoisted
+    __ lduh(str2_reg, limit_reg, chr2_reg);
     __ subcc(chr1_reg, chr2_reg, chr1_reg);
     __ br(Assembler::notZero, false, Assembler::pt, Ldone);
     assert(chr1_reg == result_reg, "result must be pre-placed");
     __ delayed()->inccc(limit_reg, sizeof(jchar));
     // annul LDUH if branch is not taken to prevent access past end of string
     __ br(Assembler::notZero, true, Assembler::pt, Lloop);
-    __ delayed()->lduh(tmp1_reg, limit_reg, chr1_reg); // hoisted
+    __ delayed()->lduh(str1_reg, limit_reg, chr1_reg); // hoisted
 
     // If strings are equal up to min length, return the length difference.
     __ mov(O7, result_reg);
@@ -2957,125 +2935,80 @@
     __ bind(Ldone);
   %}
 
-enc_class enc_String_Equals(o0RegP str1, o1RegP str2, g3RegP tmp1, g4RegP tmp2, notemp_iRegI result) %{
-    Label Lword, Lword_loop, Lpost_word, Lchar, Lchar_loop, Ldone;
+enc_class enc_String_Equals(o0RegP str1, o1RegP str2, g3RegI cnt, notemp_iRegI result) %{
+    Label Lword_loop, Lpost_word, Lchar, Lchar_loop, Ldone;
     MacroAssembler _masm(&cbuf);
 
     Register   str1_reg = reg_to_register_object($str1$$reg);
     Register   str2_reg = reg_to_register_object($str2$$reg);
-    Register   tmp1_reg = reg_to_register_object($tmp1$$reg);
-    Register   tmp2_reg = reg_to_register_object($tmp2$$reg);
+    Register    cnt_reg = reg_to_register_object($cnt$$reg);
+    Register   tmp1_reg = O7;
     Register result_reg = reg_to_register_object($result$$reg);
 
-    // Get the first character position in both strings
-    //         [8] char array, [12] offset, [16] count
-    int  value_offset = java_lang_String:: value_offset_in_bytes();
-    int offset_offset = java_lang_String::offset_offset_in_bytes();
-    int  count_offset = java_lang_String:: count_offset_in_bytes();
-
-    // load str1 (jchar*) base address into tmp1_reg
-    __ load_heap_oop(Address(str1_reg, value_offset), tmp1_reg);
-    __ ld(Address(str1_reg, offset_offset), result_reg);
-    __ add(tmp1_reg, arrayOopDesc::base_offset_in_bytes(T_CHAR), tmp1_reg);
-    __    ld(Address(str1_reg, count_offset), str1_reg); // hoisted
-    __ sll(result_reg, exact_log2(sizeof(jchar)), result_reg);
-    __    load_heap_oop(Address(str2_reg, value_offset), tmp2_reg); // hoisted
-    __ add(result_reg, tmp1_reg, tmp1_reg);
-
-    // load str2 (jchar*) base address into tmp2_reg
-    // __ ld_ptr(Address(str2_reg, value_offset), tmp2_reg); // hoisted
-    __ ld(Address(str2_reg, offset_offset), result_reg);
-    __ add(tmp2_reg, arrayOopDesc::base_offset_in_bytes(T_CHAR), tmp2_reg);
-    __    ld(Address(str2_reg, count_offset), str2_reg); // hoisted
-    __ sll(result_reg, exact_log2(sizeof(jchar)), result_reg);
-    __   cmp(str1_reg, str2_reg); // hoisted
-    __ add(result_reg, tmp2_reg, tmp2_reg);
-
-    __ sll(str1_reg, exact_log2(sizeof(jchar)), str1_reg);
-    __ br(Assembler::notEqual, true, Assembler::pt, Ldone);
-    __ delayed()->mov(G0, result_reg);    // not equal
-
-    __ br_zero(Assembler::equal, true, Assembler::pn, str1_reg, Ldone);
-    __ delayed()->add(G0, 1, result_reg); //equals
-
-    __ cmp(tmp1_reg, tmp2_reg); //same string ?
+    assert(result_reg != str1_reg &&
+           result_reg != str2_reg &&
+           result_reg !=  cnt_reg &&
+           result_reg != tmp1_reg ,
+           "need different registers");
+
+    __ cmp(str1_reg, str2_reg); //same char[] ?
     __ brx(Assembler::equal, true, Assembler::pn, Ldone);
     __ delayed()->add(G0, 1, result_reg);
 
+    __ br_on_reg_cond(Assembler::rc_z, true, Assembler::pn, cnt_reg, Ldone);
+    __ delayed()->add(G0, 1, result_reg); // count == 0
+
     //rename registers
-    Register limit_reg =   str1_reg;
-    Register  chr2_reg =   str2_reg;
+    Register limit_reg =    cnt_reg;
     Register  chr1_reg = result_reg;
-    // tmp{12} are the base pointers
+    Register  chr2_reg =   tmp1_reg;
 
     //check for alignment and position the pointers to the ends
-    __ or3(tmp1_reg, tmp2_reg, chr1_reg);
-    __ andcc(chr1_reg, 0x3, chr1_reg); // notZero means at least one not 4-byte aligned
-    __ br(Assembler::notZero, false, Assembler::pn, Lchar);
-    __ delayed()->nop();
-
-    __ bind(Lword);
-    __ and3(limit_reg, 0x2, O7); //remember the remainder (either 0 or 2)
-    __ andn(limit_reg, 0x3, limit_reg);
-    __ br_zero(Assembler::zero, false, Assembler::pn, limit_reg, Lpost_word);
-    __ delayed()->nop();
-
-    __ add(tmp1_reg, limit_reg, tmp1_reg);
-    __ add(tmp2_reg, limit_reg, tmp2_reg);
-    __ neg(limit_reg);
-
-    __ lduw(tmp1_reg, limit_reg, chr1_reg);
-    __ bind(Lword_loop);
-    __ lduw(tmp2_reg, limit_reg, chr2_reg);
-    __ cmp(chr1_reg, chr2_reg);
-    __ br(Assembler::notEqual, true, Assembler::pt, Ldone);
-    __ delayed()->mov(G0, result_reg);
-    __ inccc(limit_reg, 2*sizeof(jchar));
-    // annul LDUW if branch i  s not taken to prevent access past end of string
-    __ br(Assembler::notZero, true, Assembler::pt, Lword_loop); //annul on taken
-    __ delayed()->lduw(tmp1_reg, limit_reg, chr1_reg); // hoisted
-
-    __ bind(Lpost_word);
-    __ br_zero(Assembler::zero, true, Assembler::pt, O7, Ldone);
-    __ delayed()->add(G0, 1, result_reg);
-
-    __ lduh(tmp1_reg, 0, chr1_reg);
-    __ lduh(tmp2_reg, 0, chr2_reg);
-    __ cmp (chr1_reg, chr2_reg);
-    __ br(Assembler::notEqual, true, Assembler::pt, Ldone);
-    __ delayed()->mov(G0, result_reg);
+    __ or3(str1_reg, str2_reg, chr1_reg);
+    __ andcc(chr1_reg, 0x3, chr1_reg);
+    // notZero means at least one not 4-byte aligned.
+    // We could optimize the case when both arrays are not aligned
+    // but it is not frequent case and it requires additional checks.
+    __ br(Assembler::notZero, false, Assembler::pn, Lchar); // char by char compare
+    __ delayed()->sll(limit_reg, exact_log2(sizeof(jchar)), limit_reg); // set byte count
+
+    // Compare char[] arrays aligned to 4 bytes.
+    __ char_arrays_equals(str1_reg, str2_reg, limit_reg, result_reg,
+                          chr1_reg, chr2_reg, Ldone);
     __ ba(false,Ldone);
     __ delayed()->add(G0, 1, result_reg);
 
+    // char by char compare
     __ bind(Lchar);
-    __ add(tmp1_reg, limit_reg, tmp1_reg);
-    __ add(tmp2_reg, limit_reg, tmp2_reg);
+    __ add(str1_reg, limit_reg, str1_reg);
+    __ add(str2_reg, limit_reg, str2_reg);
     __ neg(limit_reg); //negate count
 
-    __ lduh(tmp1_reg, limit_reg, chr1_reg);
+    __ lduh(str1_reg, limit_reg, chr1_reg);
+    // Lchar_loop
     __ bind(Lchar_loop);
-    __ lduh(tmp2_reg, limit_reg, chr2_reg);
+    __ lduh(str2_reg, limit_reg, chr2_reg);
     __ cmp(chr1_reg, chr2_reg);
     __ br(Assembler::notEqual, true, Assembler::pt, Ldone);
     __ delayed()->mov(G0, result_reg); //not equal
     __ inccc(limit_reg, sizeof(jchar));
     // annul LDUH if branch is not taken to prevent access past end of string
-    __ br(Assembler::notZero, true, Assembler::pt, Lchar_loop); //annul on taken
-    __ delayed()->lduh(tmp1_reg, limit_reg, chr1_reg); // hoisted
+    __ br(Assembler::notZero, true, Assembler::pt, Lchar_loop);
+    __ delayed()->lduh(str1_reg, limit_reg, chr1_reg); // hoisted
 
     __ add(G0, 1, result_reg);  //equal
 
     __ bind(Ldone);
   %}
 
-enc_class enc_Array_Equals(o0RegP ary1, o1RegP ary2, g3RegP tmp1, g4RegP tmp2, notemp_iRegI result) %{
+enc_class enc_Array_Equals(o0RegP ary1, o1RegP ary2, g3RegP tmp1, notemp_iRegI result) %{
     Label Lvector, Ldone, Lloop;
     MacroAssembler _masm(&cbuf);
 
     Register   ary1_reg = reg_to_register_object($ary1$$reg);
     Register   ary2_reg = reg_to_register_object($ary2$$reg);
     Register   tmp1_reg = reg_to_register_object($tmp1$$reg);
-    Register   tmp2_reg = reg_to_register_object($tmp2$$reg);
+    Register   tmp2_reg = O7;
     Register result_reg = reg_to_register_object($result$$reg);
 
     int length_offset  = arrayOopDesc::length_offset_in_bytes();
@@ -3101,7 +3034,7 @@
     __ br(Assembler::notEqual, true, Assembler::pn, Ldone);
     __ delayed()->mov(G0, result_reg);     // not equal
 
-    __ br_zero(Assembler::zero, true, Assembler::pn, tmp1_reg, Ldone);
+    __ br_on_reg_cond(Assembler::rc_z, true, Assembler::pn, tmp1_reg, Ldone);
     __ delayed()->add(G0, 1, result_reg); // zero-length arrays are equal
 
     // load array addresses
@@ -3109,45 +3042,16 @@
     __ add(ary2_reg, base_offset, ary2_reg);
 
     // renaming registers
-    Register chr1_reg  =  tmp2_reg;   // for characters in ary1
-    Register chr2_reg  =  result_reg; // for characters in ary2
+    Register chr1_reg  =  result_reg; // for characters in ary1
+    Register chr2_reg  =  tmp2_reg;   // for characters in ary2
     Register limit_reg =  tmp1_reg;   // length
 
     // set byte count
     __ sll(limit_reg, exact_log2(sizeof(jchar)), limit_reg);
-    __ andcc(limit_reg, 0x2, chr1_reg); //trailing character ?
-    __ br(Assembler::zero, false, Assembler::pt, Lvector);
-    __ delayed()->nop();
-
-    //compare the trailing char
-    __ sub(limit_reg, sizeof(jchar), limit_reg);
-    __ lduh(ary1_reg, limit_reg, chr1_reg);
-    __ lduh(ary2_reg, limit_reg, chr2_reg);
-    __ cmp(chr1_reg, chr2_reg);
-    __ br(Assembler::notEqual, true, Assembler::pt, Ldone);
-    __ delayed()->mov(G0, result_reg);     // not equal
-
-    // only one char ?
-    __ br_zero(Assembler::zero, true, Assembler::pn, limit_reg, Ldone);
-    __ delayed()->add(G0, 1, result_reg); // zero-length arrays are equal
-
-    __ bind(Lvector);
-    // Shift ary1_reg and ary2_reg to the end of the arrays, negate limit
-    __ add(ary1_reg, limit_reg, ary1_reg);
-    __ add(ary2_reg, limit_reg, ary2_reg);
-    __ neg(limit_reg, limit_reg);
-
-    __ lduw(ary1_reg, limit_reg, chr1_reg);
-    __ bind(Lloop);
-    __ lduw(ary2_reg, limit_reg, chr2_reg);
-    __ cmp(chr1_reg, chr2_reg);
-    __ br(Assembler::notEqual, false, Assembler::pt, Ldone);
-    __ delayed()->mov(G0, result_reg);     // not equal
-    __ inccc(limit_reg, 2*sizeof(jchar));
-    // annul LDUW if branch is not taken to prevent access past end of string
-    __ br(Assembler::notZero, true, Assembler::pt, Lloop); //annul on taken
-    __ delayed()->lduw(ary1_reg, limit_reg, chr1_reg); // hoisted
-
+
+    // Compare char[] arrays aligned to 4 bytes.
+    __ char_arrays_equals(ary1_reg, ary2_reg, limit_reg, result_reg,
+                          chr1_reg, chr2_reg, Ldone);
     __ add(G0, 1, result_reg); // equals
 
     __ bind(Ldone);
@@ -9471,33 +9375,33 @@
   ins_pipe(long_memory_op);
 %}
 
-instruct string_compare(o0RegP str1, o1RegP str2, g3RegP tmp1, g4RegP tmp2, notemp_iRegI result,
-                        o7RegI tmp3, flagsReg ccr) %{
-  match(Set result (StrComp str1 str2));
-  effect(USE_KILL str1, USE_KILL str2, KILL tmp1, KILL tmp2, KILL ccr, KILL tmp3);
+instruct string_compare(o0RegP str1, o1RegP str2, g3RegI cnt1, g4RegI cnt2, notemp_iRegI result,
+                        o7RegI tmp, flagsReg ccr) %{
+  match(Set result (StrComp (Binary str1 cnt1) (Binary str2 cnt2)));
+  effect(USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL ccr, KILL tmp);
   ins_cost(300);
-  format %{ "String Compare $str1,$str2 -> $result" %}
-  ins_encode( enc_String_Compare(str1, str2, tmp1, tmp2, result) );
+  format %{ "String Compare $str1,$cnt1,$str2,$cnt2 -> $result   // KILL $tmp" %}
+  ins_encode( enc_String_Compare(str1, str2, cnt1, cnt2, result) );
   ins_pipe(long_memory_op);
 %}
 
-instruct string_equals(o0RegP str1, o1RegP str2, g3RegP tmp1, g4RegP tmp2, notemp_iRegI result,
-                       o7RegI tmp3, flagsReg ccr) %{
-  match(Set result (StrEquals str1 str2));
-  effect(USE_KILL str1, USE_KILL str2, KILL tmp1, KILL tmp2, KILL ccr, KILL tmp3);
+instruct string_equals(o0RegP str1, o1RegP str2, g3RegI cnt, notemp_iRegI result,
+                       o7RegI tmp, flagsReg ccr) %{
+  match(Set result (StrEquals (Binary str1 str2) cnt));
+  effect(USE_KILL str1, USE_KILL str2, USE_KILL cnt, KILL tmp, KILL ccr);
   ins_cost(300);
-  format %{ "String Equals $str1,$str2 -> $result" %}
-  ins_encode( enc_String_Equals(str1, str2, tmp1, tmp2, result) );
+  format %{ "String Equals $str1,$str2,$cnt -> $result   // KILL $tmp" %}
+  ins_encode( enc_String_Equals(str1, str2, cnt, result) );
   ins_pipe(long_memory_op);
 %}
 
-instruct array_equals(o0RegP ary1, o1RegP ary2, g3RegP tmp1, g4RegP tmp2, notemp_iRegI result,
-                        flagsReg ccr) %{
+instruct array_equals(o0RegP ary1, o1RegP ary2, g3RegI tmp1, notemp_iRegI result,
+                      o7RegI tmp2, flagsReg ccr) %{
   match(Set result (AryEq ary1 ary2));
   effect(USE_KILL ary1, USE_KILL ary2, KILL tmp1, KILL tmp2, KILL ccr);
   ins_cost(300);
-  format %{ "Array Equals $ary1,$ary2 -> $result" %}
-  ins_encode( enc_Array_Equals(ary1, ary2, tmp1, tmp2, result));
+  format %{ "Array Equals $ary1,$ary2 -> $result   // KILL $tmp1,$tmp2" %}
+  ins_encode( enc_Array_Equals(ary1, ary2, tmp1, result));
   ins_pipe(long_memory_op);
 %}
 
--- a/hotspot/src/cpu/x86/vm/assembler_x86.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/cpu/x86/vm/assembler_x86.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -8404,6 +8404,319 @@
 }
 #endif // _LP64
 
+// IndexOf substring.
+void MacroAssembler::string_indexof(Register str1, Register str2,
+                                    Register cnt1, Register cnt2, Register result,
+                                    XMMRegister vec, Register tmp) {
+  assert(UseSSE42Intrinsics, "SSE4.2 is required");
+
+  Label RELOAD_SUBSTR, PREP_FOR_SCAN, SCAN_TO_SUBSTR,
+        SCAN_SUBSTR, RET_NOT_FOUND, CLEANUP;
+
+  push(str1); // string addr
+  push(str2); // substr addr
+  push(cnt2); // substr count
+  jmpb(PREP_FOR_SCAN);
+
+  // Substr count saved at sp
+  // Substr saved at sp+1*wordSize
+  // String saved at sp+2*wordSize
+
+  // Reload substr for rescan
+  bind(RELOAD_SUBSTR);
+  movl(cnt2, Address(rsp, 0));
+  movptr(str2, Address(rsp, wordSize));
+  // We came here after the beginninig of the substring was
+  // matched but the rest of it was not so we need to search
+  // again. Start from the next element after the previous match.
+  subptr(str1, result); // Restore counter
+  shrl(str1, 1);
+  addl(cnt1, str1);
+  lea(str1, Address(result, 2)); // Reload string
+
+  // Load substr
+  bind(PREP_FOR_SCAN);
+  movdqu(vec, Address(str2, 0));
+  addl(cnt1, 8);  // prime the loop
+  subptr(str1, 16);
+
+  // Scan string for substr in 16-byte vectors
+  bind(SCAN_TO_SUBSTR);
+  subl(cnt1, 8);
+  addptr(str1, 16);
+
+  // pcmpestri
+  //   inputs:
+  //     xmm - substring
+  //     rax - substring length (elements count)
+  //     mem - scaned string
+  //     rdx - string length (elements count)
+  //     0xd - mode: 1100 (substring search) + 01 (unsigned shorts)
+  //   outputs:
+  //     rcx - matched index in string
+  assert(cnt1 == rdx && cnt2 == rax && tmp == rcx, "pcmpestri");
+
+  pcmpestri(vec, Address(str1, 0), 0x0d);
+  jcc(Assembler::above, SCAN_TO_SUBSTR);      // CF == 0 && ZF == 0
+  jccb(Assembler::aboveEqual, RET_NOT_FOUND); // CF == 0
+
+  // Fallthrough: found a potential substr
+
+  // Make sure string is still long enough
+  subl(cnt1, tmp);
+  cmpl(cnt1, cnt2);
+  jccb(Assembler::negative, RET_NOT_FOUND);
+  // Compute start addr of substr
+  lea(str1, Address(str1, tmp, Address::times_2));
+  movptr(result, str1); // save
+
+  // Compare potential substr
+  addl(cnt1, 8);     // prime the loop
+  addl(cnt2, 8);
+  subptr(str1, 16);
+  subptr(str2, 16);
+
+  // Scan 16-byte vectors of string and substr
+  bind(SCAN_SUBSTR);
+  subl(cnt1, 8);
+  subl(cnt2, 8);
+  addptr(str1, 16);
+  addptr(str2, 16);
+  movdqu(vec, Address(str2, 0));
+  pcmpestri(vec, Address(str1, 0), 0x0d);
+  jcc(Assembler::noOverflow, RELOAD_SUBSTR); // OF == 0
+  jcc(Assembler::positive, SCAN_SUBSTR);     // SF == 0
+
+  // Compute substr offset
+  subptr(result, Address(rsp, 2*wordSize));
+  shrl(result, 1); // index
+  jmpb(CLEANUP);
+
+  bind(RET_NOT_FOUND);
+  movl(result, -1);
+
+  bind(CLEANUP);
+  addptr(rsp, 3*wordSize);
+}
+
+// Compare strings.
+void MacroAssembler::string_compare(Register str1, Register str2,
+                                    Register cnt1, Register cnt2, Register result,
+                                    XMMRegister vec1, XMMRegister vec2) {
+  Label LENGTH_DIFF_LABEL, POP_LABEL, DONE_LABEL, WHILE_HEAD_LABEL;
+
+  // Compute the minimum of the string lengths and the
+  // difference of the string lengths (stack).
+  // Do the conditional move stuff
+  movl(result, cnt1);
+  subl(cnt1, cnt2);
+  push(cnt1);
+  if (VM_Version::supports_cmov()) {
+    cmovl(Assembler::lessEqual, cnt2, result);
+  } else {
+    Label GT_LABEL;
+    jccb(Assembler::greater, GT_LABEL);
+    movl(cnt2, result);
+    bind(GT_LABEL);
+  }
+
+  // Is the minimum length zero?
+  testl(cnt2, cnt2);
+  jcc(Assembler::zero, LENGTH_DIFF_LABEL);
+
+  // Load first characters
+  load_unsigned_short(result, Address(str1, 0));
+  load_unsigned_short(cnt1, Address(str2, 0));
+
+  // Compare first characters
+  subl(result, cnt1);
+  jcc(Assembler::notZero,  POP_LABEL);
+  decrementl(cnt2);
+  jcc(Assembler::zero, LENGTH_DIFF_LABEL);
+
+  {
+    // Check after comparing first character to see if strings are equivalent
+    Label LSkip2;
+    // Check if the strings start at same location
+    cmpptr(str1, str2);
+    jccb(Assembler::notEqual, LSkip2);
+
+    // Check if the length difference is zero (from stack)
+    cmpl(Address(rsp, 0), 0x0);
+    jcc(Assembler::equal,  LENGTH_DIFF_LABEL);
+
+    // Strings might not be equivalent
+    bind(LSkip2);
+  }
+
+  // Advance to next character
+  addptr(str1, 2);
+  addptr(str2, 2);
+
+  if (UseSSE42Intrinsics) {
+    // With SSE4.2, use double quad vector compare
+    Label COMPARE_VECTORS, VECTOR_NOT_EQUAL, COMPARE_TAIL;
+    // Setup to compare 16-byte vectors
+    movl(cnt1, cnt2);
+    andl(cnt2, 0xfffffff8); // cnt2 holds the vector count
+    andl(cnt1, 0x00000007); // cnt1 holds the tail count
+    testl(cnt2, cnt2);
+    jccb(Assembler::zero, COMPARE_TAIL);
+
+    lea(str2, Address(str2, cnt2, Address::times_2));
+    lea(str1, Address(str1, cnt2, Address::times_2));
+    negptr(cnt2);
+
+    bind(COMPARE_VECTORS);
+    movdqu(vec1, Address(str1, cnt2, Address::times_2));
+    movdqu(vec2, Address(str2, cnt2, Address::times_2));
+    pxor(vec1, vec2);
+    ptest(vec1, vec1);
+    jccb(Assembler::notZero, VECTOR_NOT_EQUAL);
+    addptr(cnt2, 8);
+    jcc(Assembler::notZero, COMPARE_VECTORS);
+    jmpb(COMPARE_TAIL);
+
+    // Mismatched characters in the vectors
+    bind(VECTOR_NOT_EQUAL);
+    lea(str1, Address(str1, cnt2, Address::times_2));
+    lea(str2, Address(str2, cnt2, Address::times_2));
+    movl(cnt1, 8);
+
+    // Compare tail (< 8 chars), or rescan last vectors to
+    // find 1st mismatched characters
+    bind(COMPARE_TAIL);
+    testl(cnt1, cnt1);
+    jccb(Assembler::zero, LENGTH_DIFF_LABEL);
+    movl(cnt2, cnt1);
+    // Fallthru to tail compare
+  }
+
+  // Shift str2 and str1 to the end of the arrays, negate min
+  lea(str1, Address(str1, cnt2, Address::times_2, 0));
+  lea(str2, Address(str2, cnt2, Address::times_2, 0));
+  negptr(cnt2);
+
+    // Compare the rest of the characters
+  bind(WHILE_HEAD_LABEL);
+  load_unsigned_short(result, Address(str1, cnt2, Address::times_2, 0));
+  load_unsigned_short(cnt1, Address(str2, cnt2, Address::times_2, 0));
+  subl(result, cnt1);
+  jccb(Assembler::notZero, POP_LABEL);
+  increment(cnt2);
+  jcc(Assembler::notZero, WHILE_HEAD_LABEL);
+
+  // Strings are equal up to min length.  Return the length difference.
+  bind(LENGTH_DIFF_LABEL);
+  pop(result);
+  jmpb(DONE_LABEL);
+
+  // Discard the stored length difference
+  bind(POP_LABEL);
+  addptr(rsp, wordSize);
+
+  // That's it
+  bind(DONE_LABEL);
+}
+
+// Compare char[] arrays aligned to 4 bytes or substrings.
+void MacroAssembler::char_arrays_equals(bool is_array_equ, Register ary1, Register ary2,
+                                        Register limit, Register result, Register chr,
+                                        XMMRegister vec1, XMMRegister vec2) {
+  Label TRUE_LABEL, FALSE_LABEL, DONE, COMPARE_VECTORS, COMPARE_CHAR;
+
+  int length_offset  = arrayOopDesc::length_offset_in_bytes();
+  int base_offset    = arrayOopDesc::base_offset_in_bytes(T_CHAR);
+
+  // Check the input args
+  cmpptr(ary1, ary2);
+  jcc(Assembler::equal, TRUE_LABEL);
+
+  if (is_array_equ) {
+    // Need additional checks for arrays_equals.
+    andptr(ary1, ary2);
+    jcc(Assembler::zero, FALSE_LABEL); // One pointer is NULL
+
+    // Check the lengths
+    movl(limit, Address(ary1, length_offset));
+    cmpl(limit, Address(ary2, length_offset));
+    jcc(Assembler::notEqual, FALSE_LABEL);
+  }
+
+  // count == 0
+  testl(limit, limit);
+  jcc(Assembler::zero, TRUE_LABEL);
+
+  if (is_array_equ) {
+    // Load array address
+    lea(ary1, Address(ary1, base_offset));
+    lea(ary2, Address(ary2, base_offset));
+  }
+
+  shll(limit, 1);      // byte count != 0
+  movl(result, limit); // copy
+
+  if (UseSSE42Intrinsics) {
+    // With SSE4.2, use double quad vector compare
+    Label COMPARE_WIDE_VECTORS, COMPARE_TAIL;
+    // Compare 16-byte vectors
+    andl(result, 0x0000000e);  //   tail count (in bytes)
+    andl(limit, 0xfffffff0);   // vector count (in bytes)
+    jccb(Assembler::zero, COMPARE_TAIL);
+
+    lea(ary1, Address(ary1, limit, Address::times_1));
+    lea(ary2, Address(ary2, limit, Address::times_1));
+    negptr(limit);
+
+    bind(COMPARE_WIDE_VECTORS);
+    movdqu(vec1, Address(ary1, limit, Address::times_1));
+    movdqu(vec2, Address(ary2, limit, Address::times_1));
+    pxor(vec1, vec2);
+    ptest(vec1, vec1);
+    jccb(Assembler::notZero, FALSE_LABEL);
+    addptr(limit, 16);
+    jcc(Assembler::notZero, COMPARE_WIDE_VECTORS);
+
+    bind(COMPARE_TAIL); // limit is zero
+    movl(limit, result);
+    // Fallthru to tail compare
+  }
+
+  // Compare 4-byte vectors
+  andl(limit, 0xfffffffc); // vector count (in bytes)
+  jccb(Assembler::zero, COMPARE_CHAR);
+
+  lea(ary1, Address(ary1, limit, Address::times_1));
+  lea(ary2, Address(ary2, limit, Address::times_1));
+  negptr(limit);
+
+  bind(COMPARE_VECTORS);
+  movl(chr, Address(ary1, limit, Address::times_1));
+  cmpl(chr, Address(ary2, limit, Address::times_1));
+  jccb(Assembler::notEqual, FALSE_LABEL);
+  addptr(limit, 4);
+  jcc(Assembler::notZero, COMPARE_VECTORS);
+
+  // Compare trailing char (final 2 bytes), if any
+  bind(COMPARE_CHAR);
+  testl(result, 0x2);   // tail  char
+  jccb(Assembler::zero, TRUE_LABEL);
+  load_unsigned_short(chr, Address(ary1, 0));
+  load_unsigned_short(limit, Address(ary2, 0));
+  cmpl(chr, limit);
+  jccb(Assembler::notEqual, FALSE_LABEL);
+
+  bind(TRUE_LABEL);
+  movl(result, 1);   // return true
+  jmpb(DONE);
+
+  bind(FALSE_LABEL);
+  xorl(result, result); // return false
+
+  // That's it
+  bind(DONE);
+}
+
 Assembler::Condition MacroAssembler::negate_condition(Assembler::Condition cond) {
   switch (cond) {
     // Note some conditions are synonyms for others
--- a/hotspot/src/cpu/x86/vm/assembler_x86.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/cpu/x86/vm/assembler_x86.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -2206,6 +2206,20 @@
   void movl2ptr(Register dst, Address src) { LP64_ONLY(movslq(dst, src)) NOT_LP64(movl(dst, src)); }
   void movl2ptr(Register dst, Register src) { LP64_ONLY(movslq(dst, src)) NOT_LP64(if (dst != src) movl(dst, src)); }
 
+  // IndexOf strings.
+  void string_indexof(Register str1, Register str2,
+                      Register cnt1, Register cnt2, Register result,
+                      XMMRegister vec, Register tmp);
+
+  // Compare strings.
+  void string_compare(Register str1, Register str2,
+                      Register cnt1, Register cnt2, Register result,
+                      XMMRegister vec1, XMMRegister vec2);
+
+  // Compare char[] arrays.
+  void char_arrays_equals(bool is_array_equ, Register ary1, Register ary2,
+                          Register limit, Register result, Register chr,
+                          XMMRegister vec1, XMMRegister vec2);
 
 #undef VIRTUAL
 
--- a/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -1638,7 +1638,7 @@
       jobject2reg_with_patching(k_RInfo, op->info_for_patch());
     } else {
 #ifdef _LP64
-      __ movoop(k_RInfo, k->encoding());
+      __ movoop(k_RInfo, k->constant_encoding());
 #else
       k_RInfo = noreg;
 #endif // _LP64
@@ -1661,7 +1661,7 @@
       assert(data != NULL,       "need data for checkcast");
       assert(data->is_BitData(), "need BitData for checkcast");
       Register mdo  = klass_RInfo;
-      __ movoop(mdo, md->encoding());
+      __ movoop(mdo, md->constant_encoding());
       Address data_addr(mdo, md->byte_offset_of_slot(data, DataLayout::header_offset()));
       int header_bits = DataLayout::flag_mask_to_header_mask(BitData::null_seen_byte_constant());
       __ orl(data_addr, header_bits);
@@ -1679,7 +1679,7 @@
 #ifdef _LP64
         __ cmpptr(k_RInfo, Address(obj, oopDesc::klass_offset_in_bytes()));
 #else
-        __ cmpoop(Address(obj, oopDesc::klass_offset_in_bytes()), k->encoding());
+        __ cmpoop(Address(obj, oopDesc::klass_offset_in_bytes()), k->constant_encoding());
 #endif // _LP64
       } else {
         __ cmpptr(k_RInfo, Address(obj, oopDesc::klass_offset_in_bytes()));
@@ -1696,7 +1696,7 @@
 #ifdef _LP64
         __ cmpptr(k_RInfo, Address(klass_RInfo, k->super_check_offset()));
 #else
-        __ cmpoop(Address(klass_RInfo, k->super_check_offset()), k->encoding());
+        __ cmpoop(Address(klass_RInfo, k->super_check_offset()), k->constant_encoding());
 #endif // _LP64
         if (sizeof(oopDesc) + Klass::secondary_super_cache_offset_in_bytes() != k->super_check_offset()) {
           __ jcc(Assembler::notEqual, *stub->entry());
@@ -1707,7 +1707,7 @@
 #ifdef _LP64
           __ cmpptr(klass_RInfo, k_RInfo);
 #else
-          __ cmpoop(klass_RInfo, k->encoding());
+          __ cmpoop(klass_RInfo, k->constant_encoding());
 #endif // _LP64
           __ jcc(Assembler::equal, done);
 
@@ -1715,7 +1715,7 @@
 #ifdef _LP64
           __ push(k_RInfo);
 #else
-          __ pushoop(k->encoding());
+          __ pushoop(k->constant_encoding());
 #endif // _LP64
           __ call(RuntimeAddress(Runtime1::entry_for(Runtime1::slow_subtype_check_id)));
           __ pop(klass_RInfo);
@@ -1763,7 +1763,7 @@
     if (!k->is_loaded()) {
       jobject2reg_with_patching(k_RInfo, op->info_for_patch());
     } else {
-      LP64_ONLY(__ movoop(k_RInfo, k->encoding()));
+      LP64_ONLY(__ movoop(k_RInfo, k->constant_encoding()));
     }
     assert(obj != k_RInfo, "must be different");
 
@@ -1774,7 +1774,7 @@
       // get object class
       // not a safepoint as obj null check happens earlier
       if (LP64_ONLY(false &&) k->is_loaded()) {
-        NOT_LP64(__ cmpoop(Address(obj, oopDesc::klass_offset_in_bytes()), k->encoding()));
+        NOT_LP64(__ cmpoop(Address(obj, oopDesc::klass_offset_in_bytes()), k->constant_encoding()));
         k_RInfo = noreg;
       } else {
         __ cmpptr(k_RInfo, Address(obj, oopDesc::klass_offset_in_bytes()));
@@ -1791,14 +1791,14 @@
 #ifndef _LP64
       if (k->is_loaded()) {
         // See if we get an immediate positive hit
-        __ cmpoop(Address(klass_RInfo, k->super_check_offset()), k->encoding());
+        __ cmpoop(Address(klass_RInfo, k->super_check_offset()), k->constant_encoding());
         __ jcc(Assembler::equal, one);
         if (sizeof(oopDesc) + Klass::secondary_super_cache_offset_in_bytes() == k->super_check_offset()) {
           // check for self
-          __ cmpoop(klass_RInfo, k->encoding());
+          __ cmpoop(klass_RInfo, k->constant_encoding());
           __ jcc(Assembler::equal, one);
           __ push(klass_RInfo);
-          __ pushoop(k->encoding());
+          __ pushoop(k->constant_encoding());
           __ call(RuntimeAddress(Runtime1::entry_for(Runtime1::slow_subtype_check_id)));
           __ pop(klass_RInfo);
           __ pop(dst);
@@ -3112,7 +3112,7 @@
     // subtype which we can't check or src is the same array as dst
     // but not necessarily exactly of type default_type.
     Label known_ok, halt;
-    __ movoop(tmp, default_type->encoding());
+    __ movoop(tmp, default_type->constant_encoding());
     if (basic_type != T_OBJECT) {
       __ cmpptr(tmp, dst_klass_addr);
       __ jcc(Assembler::notEqual, halt);
@@ -3200,7 +3200,7 @@
   assert(data->is_CounterData(), "need CounterData for calls");
   assert(op->mdo()->is_single_cpu(),  "mdo must be allocated");
   Register mdo  = op->mdo()->as_register();
-  __ movoop(mdo, md->encoding());
+  __ movoop(mdo, md->constant_encoding());
   Address counter_addr(mdo, md->byte_offset_of_slot(data, CounterData::count_offset()));
   __ addl(counter_addr, DataLayout::counter_increment);
   Bytecodes::Code bc = method->java_code_at_bci(bci);
@@ -3240,7 +3240,7 @@
         ciKlass* receiver = vc_data->receiver(i);
         if (receiver == NULL) {
           Address recv_addr(mdo, md->byte_offset_of_slot(data, VirtualCallData::receiver_offset(i)));
-          __ movoop(recv_addr, known_klass->encoding());
+          __ movoop(recv_addr, known_klass->constant_encoding());
           Address data_addr(mdo, md->byte_offset_of_slot(data, VirtualCallData::receiver_count_offset(i)));
           __ addl(data_addr, DataLayout::counter_increment);
           return;
--- a/hotspot/src/cpu/x86/vm/c1_LIRGenerator_x86.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/cpu/x86/vm/c1_LIRGenerator_x86.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -994,7 +994,7 @@
   LIR_Opr len = length.result();
   BasicType elem_type = x->elt_type();
 
-  __ oop2reg(ciTypeArrayKlass::make(elem_type)->encoding(), klass_reg);
+  __ oop2reg(ciTypeArrayKlass::make(elem_type)->constant_encoding(), klass_reg);
 
   CodeStub* slow_path = new NewTypeArrayStub(klass_reg, len, reg, info);
   __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, elem_type, klass_reg, slow_path);
--- a/hotspot/src/cpu/x86/vm/x86_32.ad	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/cpu/x86/vm/x86_32.ad	Fri Oct 16 18:02:31 2009 -0700
@@ -379,7 +379,7 @@
         int format) {
 #ifdef ASSERT
   if (rspec.reloc()->type() == relocInfo::oop_type && d32 != 0 && d32 != (int)Universe::non_oop_word()) {
-    assert(oop(d32)->is_oop() && oop(d32)->is_perm(), "cannot embed non-perm oops in code");
+    assert(oop(d32)->is_oop() && (ScavengeRootsInCode || !oop(d32)->is_scavengable()), "cannot embed scavengable oops in code");
   }
 #endif
   cbuf.relocate(cbuf.inst_mark(), rspec, format);
@@ -3701,458 +3701,6 @@
     }
   %}
 
-  enc_class enc_String_Compare(eDIRegP str1, eSIRegP str2, regXD tmp1, regXD tmp2,
-                        eAXRegI tmp3, eBXRegI tmp4, eCXRegI result) %{
-    Label ECX_GOOD_LABEL, LENGTH_DIFF_LABEL,
-          POP_LABEL, DONE_LABEL, CONT_LABEL,
-          WHILE_HEAD_LABEL;
-    MacroAssembler masm(&cbuf);
-
-    XMMRegister tmp1Reg   = as_XMMRegister($tmp1$$reg);
-    XMMRegister tmp2Reg   = as_XMMRegister($tmp2$$reg);
-
-    // Get the first character position in both strings
-    //         [8] char array, [12] offset, [16] count
-    int value_offset  = java_lang_String::value_offset_in_bytes();
-    int offset_offset = java_lang_String::offset_offset_in_bytes();
-    int count_offset  = java_lang_String::count_offset_in_bytes();
-    int base_offset   = arrayOopDesc::base_offset_in_bytes(T_CHAR);
-
-    masm.movptr(rax, Address(rsi, value_offset));
-    masm.movl(rcx, Address(rsi, offset_offset));
-    masm.lea(rax, Address(rax, rcx, Address::times_2, base_offset));
-    masm.movptr(rbx, Address(rdi, value_offset));
-    masm.movl(rcx, Address(rdi, offset_offset));
-    masm.lea(rbx, Address(rbx, rcx, Address::times_2, base_offset));
-
-    // Compute the minimum of the string lengths(rsi) and the
-    // difference of the string lengths (stack)
-
-    if (VM_Version::supports_cmov()) {
-      masm.movl(rdi, Address(rdi, count_offset));
-      masm.movl(rsi, Address(rsi, count_offset));
-      masm.movl(rcx, rdi);
-      masm.subl(rdi, rsi);
-      masm.push(rdi);
-      masm.cmovl(Assembler::lessEqual, rsi, rcx);
-    } else {
-      masm.movl(rdi, Address(rdi, count_offset));
-      masm.movl(rcx, Address(rsi, count_offset));
-      masm.movl(rsi, rdi);
-      masm.subl(rdi, rcx);
-      masm.push(rdi);
-      masm.jccb(Assembler::lessEqual, ECX_GOOD_LABEL);
-      masm.movl(rsi, rcx);
-      // rsi holds min, rcx is unused
-    }
-
-    // Is the minimum length zero?
-    masm.bind(ECX_GOOD_LABEL);
-    masm.testl(rsi, rsi);
-    masm.jcc(Assembler::zero, LENGTH_DIFF_LABEL);
-
-    // Load first characters
-    masm.load_unsigned_short(rcx, Address(rbx, 0));
-    masm.load_unsigned_short(rdi, Address(rax, 0));
-
-    // Compare first characters
-    masm.subl(rcx, rdi);
-    masm.jcc(Assembler::notZero,  POP_LABEL);
-    masm.decrementl(rsi);
-    masm.jcc(Assembler::zero, LENGTH_DIFF_LABEL);
-
-    {
-      // Check after comparing first character to see if strings are equivalent
-      Label LSkip2;
-      // Check if the strings start at same location
-      masm.cmpptr(rbx,rax);
-      masm.jccb(Assembler::notEqual, LSkip2);
-
-      // Check if the length difference is zero (from stack)
-      masm.cmpl(Address(rsp, 0), 0x0);
-      masm.jcc(Assembler::equal,  LENGTH_DIFF_LABEL);
-
-      // Strings might not be equivalent
-      masm.bind(LSkip2);
-    }
-
-   // Advance to next character
-    masm.addptr(rax, 2);
-    masm.addptr(rbx, 2);
-
-    if (UseSSE42Intrinsics) {
-      // With SSE4.2, use double quad vector compare
-      Label COMPARE_VECTORS, VECTOR_NOT_EQUAL, COMPARE_TAIL;
-      // Setup to compare 16-byte vectors
-      masm.movl(rdi, rsi);
-      masm.andl(rsi, 0xfffffff8); // rsi holds the vector count
-      masm.andl(rdi, 0x00000007); // rdi holds the tail count
-      masm.testl(rsi, rsi);
-      masm.jccb(Assembler::zero, COMPARE_TAIL);
-
-      masm.lea(rax, Address(rax, rsi, Address::times_2));
-      masm.lea(rbx, Address(rbx, rsi, Address::times_2));
-      masm.negl(rsi);
-
-      masm.bind(COMPARE_VECTORS);
-      masm.movdqu(tmp1Reg, Address(rax, rsi, Address::times_2));
-      masm.movdqu(tmp2Reg, Address(rbx, rsi, Address::times_2));
-      masm.pxor(tmp1Reg, tmp2Reg);
-      masm.ptest(tmp1Reg, tmp1Reg);
-      masm.jccb(Assembler::notZero, VECTOR_NOT_EQUAL);
-      masm.addl(rsi, 8);
-      masm.jcc(Assembler::notZero, COMPARE_VECTORS);
-      masm.jmpb(COMPARE_TAIL);
-
-      // Mismatched characters in the vectors
-      masm.bind(VECTOR_NOT_EQUAL);
-      masm.lea(rax, Address(rax, rsi, Address::times_2));
-      masm.lea(rbx, Address(rbx, rsi, Address::times_2));
-      masm.movl(rdi, 8);
-
-      // Compare tail (< 8 chars), or rescan last vectors to
-      // find 1st mismatched characters
-      masm.bind(COMPARE_TAIL);
-      masm.testl(rdi, rdi);
-      masm.jccb(Assembler::zero, LENGTH_DIFF_LABEL);
-      masm.movl(rsi, rdi);
-      // Fallthru to tail compare
-    }
-
-    //Shift rax, and rbx, to the end of the arrays, negate min
-    masm.lea(rax, Address(rax, rsi, Address::times_2, 0));
-    masm.lea(rbx, Address(rbx, rsi, Address::times_2, 0));
-    masm.negl(rsi);
-
-    // Compare the rest of the characters
-    masm.bind(WHILE_HEAD_LABEL);
-    masm.load_unsigned_short(rcx, Address(rbx, rsi, Address::times_2, 0));
-    masm.load_unsigned_short(rdi, Address(rax, rsi, Address::times_2, 0));
-    masm.subl(rcx, rdi);
-    masm.jccb(Assembler::notZero, POP_LABEL);
-    masm.incrementl(rsi);
-    masm.jcc(Assembler::notZero, WHILE_HEAD_LABEL);
-
-    // Strings are equal up to min length.  Return the length difference.
-    masm.bind(LENGTH_DIFF_LABEL);
-    masm.pop(rcx);
-    masm.jmpb(DONE_LABEL);
-
-    // Discard the stored length difference
-    masm.bind(POP_LABEL);
-    masm.addptr(rsp, 4);
-
-    // That's it
-    masm.bind(DONE_LABEL);
-  %}
-
- enc_class enc_String_Equals(eDIRegP str1, eSIRegP str2, regXD tmp1, regXD tmp2,
-                       eBXRegI tmp3, eCXRegI tmp4, eAXRegI result) %{
-    Label RET_TRUE, RET_FALSE, DONE, COMPARE_VECTORS, COMPARE_CHAR;
-    MacroAssembler masm(&cbuf);
-
-    XMMRegister tmp1Reg   = as_XMMRegister($tmp1$$reg);
-    XMMRegister tmp2Reg   = as_XMMRegister($tmp2$$reg);
-
-    int value_offset  = java_lang_String::value_offset_in_bytes();
-    int offset_offset = java_lang_String::offset_offset_in_bytes();
-    int count_offset  = java_lang_String::count_offset_in_bytes();
-    int base_offset   = arrayOopDesc::base_offset_in_bytes(T_CHAR);
-
-    // does source == target string?
-    masm.cmpptr(rdi, rsi);
-    masm.jcc(Assembler::equal, RET_TRUE);
-
-    // get and compare counts
-    masm.movl(rcx, Address(rdi, count_offset));
-    masm.movl(rax, Address(rsi, count_offset));
-    masm.cmpl(rcx, rax);
-    masm.jcc(Assembler::notEqual, RET_FALSE);
-    masm.testl(rax, rax);
-    masm.jcc(Assembler::zero, RET_TRUE);
-
-    // get source string offset and value
-    masm.movptr(rbx, Address(rsi, value_offset));
-    masm.movl(rax, Address(rsi, offset_offset));
-    masm.leal(rsi, Address(rbx, rax, Address::times_2, base_offset));
-
-    // get compare string offset and value
-    masm.movptr(rbx, Address(rdi, value_offset));
-    masm.movl(rax, Address(rdi, offset_offset));
-    masm.leal(rdi, Address(rbx, rax, Address::times_2, base_offset));
-
-    // Set byte count
-    masm.shll(rcx, 1);
-    masm.movl(rax, rcx);
-
-    if (UseSSE42Intrinsics) {
-      // With SSE4.2, use double quad vector compare
-      Label COMPARE_WIDE_VECTORS, COMPARE_TAIL;
-      // Compare 16-byte vectors
-      masm.andl(rcx, 0xfffffff0);  // vector count (in bytes)
-      masm.andl(rax, 0x0000000e);  // tail count (in bytes)
-      masm.testl(rcx, rcx);
-      masm.jccb(Assembler::zero, COMPARE_TAIL);
-      masm.lea(rdi, Address(rdi, rcx, Address::times_1));
-      masm.lea(rsi, Address(rsi, rcx, Address::times_1));
-      masm.negl(rcx);
-
-      masm.bind(COMPARE_WIDE_VECTORS);
-      masm.movdqu(tmp1Reg, Address(rdi, rcx, Address::times_1));
-      masm.movdqu(tmp2Reg, Address(rsi, rcx, Address::times_1));
-      masm.pxor(tmp1Reg, tmp2Reg);
-      masm.ptest(tmp1Reg, tmp1Reg);
-      masm.jccb(Assembler::notZero, RET_FALSE);
-      masm.addl(rcx, 16);
-      masm.jcc(Assembler::notZero, COMPARE_WIDE_VECTORS);
-      masm.bind(COMPARE_TAIL);
-      masm.movl(rcx, rax);
-      // Fallthru to tail compare
-    }
-
-    // Compare 4-byte vectors
-    masm.andl(rcx, 0xfffffffc);  // vector count (in bytes)
-    masm.andl(rax, 0x00000002);  // tail char (in bytes)
-    masm.testl(rcx, rcx);
-    masm.jccb(Assembler::zero, COMPARE_CHAR);
-    masm.lea(rdi, Address(rdi, rcx, Address::times_1));
-    masm.lea(rsi, Address(rsi, rcx, Address::times_1));
-    masm.negl(rcx);
-
-    masm.bind(COMPARE_VECTORS);
-    masm.movl(rbx, Address(rdi, rcx, Address::times_1));
-    masm.cmpl(rbx, Address(rsi, rcx, Address::times_1));
-    masm.jccb(Assembler::notEqual, RET_FALSE);
-    masm.addl(rcx, 4);
-    masm.jcc(Assembler::notZero, COMPARE_VECTORS);
-
-    // Compare trailing char (final 2 bytes), if any
-    masm.bind(COMPARE_CHAR);
-    masm.testl(rax, rax);
-    masm.jccb(Assembler::zero, RET_TRUE);
-    masm.load_unsigned_short(rbx, Address(rdi, 0));
-    masm.load_unsigned_short(rcx, Address(rsi, 0));
-    masm.cmpl(rbx, rcx);
-    masm.jccb(Assembler::notEqual, RET_FALSE);
-
-    masm.bind(RET_TRUE);
-    masm.movl(rax, 1);   // return true
-    masm.jmpb(DONE);
-
-    masm.bind(RET_FALSE);
-    masm.xorl(rax, rax); // return false
-
-    masm.bind(DONE);
-    %}
-
- enc_class enc_String_IndexOf(eSIRegP str1, eDIRegP str2, regXD tmp1, eAXRegI tmp2,
-                        eCXRegI tmp3, eDXRegI tmp4, eBXRegI result) %{
-    // SSE4.2 version
-    Label LOAD_SUBSTR, PREP_FOR_SCAN, SCAN_TO_SUBSTR,
-          SCAN_SUBSTR, RET_NEG_ONE, RET_NOT_FOUND, CLEANUP, DONE;
-    MacroAssembler masm(&cbuf);
-
-    XMMRegister tmp1Reg   = as_XMMRegister($tmp1$$reg);
-
-    // Get the first character position in both strings
-    //         [8] char array, [12] offset, [16] count
-    int value_offset  = java_lang_String::value_offset_in_bytes();
-    int offset_offset = java_lang_String::offset_offset_in_bytes();
-    int count_offset  = java_lang_String::count_offset_in_bytes();
-    int base_offset   = arrayOopDesc::base_offset_in_bytes(T_CHAR);
-
-    // Get counts for string and substr
-    masm.movl(rdx, Address(rsi, count_offset));
-    masm.movl(rax, Address(rdi, count_offset));
-    // Check for substr count > string count
-    masm.cmpl(rax, rdx);
-    masm.jcc(Assembler::greater, RET_NEG_ONE);
-
-    // Start the indexOf operation
-    // Get start addr of string
-    masm.movptr(rbx, Address(rsi, value_offset));
-    masm.movl(rcx, Address(rsi, offset_offset));
-    masm.lea(rsi, Address(rbx, rcx, Address::times_2, base_offset));
-    masm.push(rsi);
-
-    // Get start addr of substr
-    masm.movptr(rbx, Address(rdi, value_offset));
-    masm.movl(rcx, Address(rdi, offset_offset));
-    masm.lea(rdi, Address(rbx, rcx, Address::times_2, base_offset));
-    masm.push(rdi);
-    masm.push(rax);
-    masm.jmpb(PREP_FOR_SCAN);
-
-    // Substr count saved at sp
-    // Substr saved at sp+4
-    // String saved at sp+8
-
-    // Prep to load substr for scan
-    masm.bind(LOAD_SUBSTR);
-    masm.movptr(rdi, Address(rsp, 4));
-    masm.movl(rax, Address(rsp, 0));
-
-    // Load substr
-    masm.bind(PREP_FOR_SCAN);
-    masm.movdqu(tmp1Reg, Address(rdi, 0));
-    masm.addl(rdx, 8);        // prime the loop
-    masm.subptr(rsi, 16);
-
-    // Scan string for substr in 16-byte vectors
-    masm.bind(SCAN_TO_SUBSTR);
-    masm.subl(rdx, 8);
-    masm.addptr(rsi, 16);
-    masm.pcmpestri(tmp1Reg, Address(rsi, 0), 0x0d);
-    masm.jcc(Assembler::above, SCAN_TO_SUBSTR);     // CF == 0 && ZF == 0
-    masm.jccb(Assembler::aboveEqual, RET_NOT_FOUND); // CF == 0
-
-    // Fallthru: found a potential substr
-
-    // Make sure string is still long enough
-    masm.subl(rdx, rcx);
-    masm.cmpl(rdx, rax);
-    masm.jccb(Assembler::negative, RET_NOT_FOUND);
-    // Compute start addr of substr
-    masm.lea(rsi, Address(rsi, rcx, Address::times_2));
-    masm.movptr(rbx, rsi);
-
-    // Compare potential substr
-    masm.addl(rdx, 8);        // prime the loop
-    masm.addl(rax, 8);
-    masm.subptr(rsi, 16);
-    masm.subptr(rdi, 16);
-
-    // Scan 16-byte vectors of string and substr
-    masm.bind(SCAN_SUBSTR);
-    masm.subl(rax, 8);
-    masm.subl(rdx, 8);
-    masm.addptr(rsi, 16);
-    masm.addptr(rdi, 16);
-    masm.movdqu(tmp1Reg, Address(rdi, 0));
-    masm.pcmpestri(tmp1Reg, Address(rsi, 0), 0x0d);
-    masm.jcc(Assembler::noOverflow, LOAD_SUBSTR);   // OF == 0
-    masm.jcc(Assembler::positive, SCAN_SUBSTR);     // SF == 0
-
-    // Compute substr offset
-    masm.movptr(rsi, Address(rsp, 8));
-    masm.subptr(rbx, rsi);
-    masm.shrl(rbx, 1);
-    masm.jmpb(CLEANUP);
-
-    masm.bind(RET_NEG_ONE);
-    masm.movl(rbx, -1);
-    masm.jmpb(DONE);
-
-    masm.bind(RET_NOT_FOUND);
-    masm.movl(rbx, -1);
-
-    masm.bind(CLEANUP);
-    masm.addptr(rsp, 12);
-
-    masm.bind(DONE);
-  %}
-
-  enc_class enc_Array_Equals(eDIRegP ary1, eSIRegP ary2, regXD tmp1, regXD tmp2,
-                             eBXRegI tmp3, eDXRegI tmp4, eAXRegI result) %{
-    Label TRUE_LABEL, FALSE_LABEL, DONE, COMPARE_VECTORS, COMPARE_CHAR;
-    MacroAssembler masm(&cbuf);
-
-    XMMRegister tmp1Reg   = as_XMMRegister($tmp1$$reg);
-    XMMRegister tmp2Reg   = as_XMMRegister($tmp2$$reg);
-    Register ary1Reg      = as_Register($ary1$$reg);
-    Register ary2Reg      = as_Register($ary2$$reg);
-    Register tmp3Reg      = as_Register($tmp3$$reg);
-    Register tmp4Reg      = as_Register($tmp4$$reg);
-    Register resultReg    = as_Register($result$$reg);
-
-    int length_offset  = arrayOopDesc::length_offset_in_bytes();
-    int base_offset    = arrayOopDesc::base_offset_in_bytes(T_CHAR);
-
-    // Check the input args
-    masm.cmpptr(ary1Reg, ary2Reg);
-    masm.jcc(Assembler::equal, TRUE_LABEL);
-    masm.testptr(ary1Reg, ary1Reg);
-    masm.jcc(Assembler::zero, FALSE_LABEL);
-    masm.testptr(ary2Reg, ary2Reg);
-    masm.jcc(Assembler::zero, FALSE_LABEL);
-
-    // Check the lengths
-    masm.movl(tmp4Reg, Address(ary1Reg, length_offset));
-    masm.movl(resultReg, Address(ary2Reg, length_offset));
-    masm.cmpl(tmp4Reg, resultReg);
-    masm.jcc(Assembler::notEqual, FALSE_LABEL);
-    masm.testl(resultReg, resultReg);
-    masm.jcc(Assembler::zero, TRUE_LABEL);
-
-    // Load array addrs
-    masm.lea(ary1Reg, Address(ary1Reg, base_offset));
-    masm.lea(ary2Reg, Address(ary2Reg, base_offset));
-
-    // Set byte count
-    masm.shll(tmp4Reg, 1);
-    masm.movl(resultReg, tmp4Reg);
-
-    if (UseSSE42Intrinsics) {
-      // With SSE4.2, use double quad vector compare
-      Label COMPARE_WIDE_VECTORS, COMPARE_TAIL;
-      // Compare 16-byte vectors
-      masm.andl(tmp4Reg, 0xfffffff0);    // vector count (in bytes)
-      masm.andl(resultReg, 0x0000000e);  // tail count (in bytes)
-      masm.testl(tmp4Reg, tmp4Reg);
-      masm.jccb(Assembler::zero, COMPARE_TAIL);
-      masm.lea(ary1Reg, Address(ary1Reg, tmp4Reg, Address::times_1));
-      masm.lea(ary2Reg, Address(ary2Reg, tmp4Reg, Address::times_1));
-      masm.negl(tmp4Reg);
-
-      masm.bind(COMPARE_WIDE_VECTORS);
-      masm.movdqu(tmp1Reg, Address(ary1Reg, tmp4Reg, Address::times_1));
-      masm.movdqu(tmp2Reg, Address(ary2Reg, tmp4Reg, Address::times_1));
-      masm.pxor(tmp1Reg, tmp2Reg);
-      masm.ptest(tmp1Reg, tmp1Reg);
-
-      masm.jccb(Assembler::notZero, FALSE_LABEL);
-      masm.addl(tmp4Reg, 16);
-      masm.jcc(Assembler::notZero, COMPARE_WIDE_VECTORS);
-      masm.bind(COMPARE_TAIL);
-      masm.movl(tmp4Reg, resultReg);
-      // Fallthru to tail compare
-    }
-
-    // Compare 4-byte vectors
-    masm.andl(tmp4Reg, 0xfffffffc);    // vector count (in bytes)
-    masm.andl(resultReg, 0x00000002);  // tail char (in bytes)
-    masm.testl(tmp4Reg, tmp4Reg);
-    masm.jccb(Assembler::zero, COMPARE_CHAR);
-    masm.lea(ary1Reg, Address(ary1Reg, tmp4Reg, Address::times_1));
-    masm.lea(ary2Reg, Address(ary2Reg, tmp4Reg, Address::times_1));
-    masm.negl(tmp4Reg);
-
-    masm.bind(COMPARE_VECTORS);
-    masm.movl(tmp3Reg, Address(ary1Reg, tmp4Reg, Address::times_1));
-    masm.cmpl(tmp3Reg, Address(ary2Reg, tmp4Reg, Address::times_1));
-    masm.jccb(Assembler::notEqual, FALSE_LABEL);
-    masm.addl(tmp4Reg, 4);
-    masm.jcc(Assembler::notZero, COMPARE_VECTORS);
-
-    // Compare trailing char (final 2 bytes), if any
-    masm.bind(COMPARE_CHAR);
-    masm.testl(resultReg, resultReg);
-    masm.jccb(Assembler::zero, TRUE_LABEL);
-    masm.load_unsigned_short(tmp3Reg, Address(ary1Reg, 0));
-    masm.load_unsigned_short(tmp4Reg, Address(ary2Reg, 0));
-    masm.cmpl(tmp3Reg, tmp4Reg);
-    masm.jccb(Assembler::notEqual, FALSE_LABEL);
-
-    masm.bind(TRUE_LABEL);
-    masm.movl(resultReg, 1);   // return true
-    masm.jmpb(DONE);
-
-    masm.bind(FALSE_LABEL);
-    masm.xorl(resultReg, resultReg); // return false
-
-    // That's it
-    masm.bind(DONE);
-  %}
 
   enc_class enc_pop_rdx() %{
     emit_opcode(cbuf,0x5A);
@@ -12718,48 +12266,64 @@
   ins_pipe( pipe_slow );
 %}
 
-instruct string_compare(eDIRegP str1, eSIRegP str2, regXD tmp1, regXD tmp2,
-                        eAXRegI tmp3, eBXRegI tmp4, eCXRegI result, eFlagsReg cr) %{
-  match(Set result (StrComp str1 str2));
-  effect(TEMP tmp1, TEMP tmp2, USE_KILL str1, USE_KILL str2, KILL tmp3, KILL tmp4, KILL cr);
-  //ins_cost(300);
-
-  format %{ "String Compare $str1,$str2 -> $result    // KILL EAX, EBX" %}
-  ins_encode( enc_String_Compare(str1, str2, tmp1, tmp2, tmp3, tmp4, result) );
+instruct string_compare(eDIRegP str1, eCXRegI cnt1, eSIRegP str2, eBXRegI cnt2,
+                        eAXRegI result, regXD tmp1, regXD tmp2, eFlagsReg cr) %{
+  match(Set result (StrComp (Binary str1 cnt1) (Binary str2 cnt2)));
+  effect(TEMP tmp1, TEMP tmp2, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL cr);
+
+  format %{ "String Compare $str1,$cnt1,$str2,$cnt2 -> $result   // KILL $tmp1, $tmp2" %}
+  ins_encode %{
+    __ string_compare($str1$$Register, $str2$$Register,
+                      $cnt1$$Register, $cnt2$$Register, $result$$Register,
+                      $tmp1$$XMMRegister, $tmp2$$XMMRegister);
+  %}
   ins_pipe( pipe_slow );
 %}
 
 // fast string equals
-instruct string_equals(eDIRegP str1, eSIRegP str2, regXD tmp1, regXD tmp2,
-                       eBXRegI tmp3, eCXRegI tmp4, eAXRegI result, eFlagsReg cr) %{
-  match(Set result (StrEquals str1 str2));
-  effect(TEMP tmp1, TEMP tmp2, USE_KILL str1, USE_KILL str2, KILL tmp3, KILL tmp4, KILL cr);
-
-  format %{ "String Equals $str1,$str2 -> $result    // KILL EBX, ECX" %}
-  ins_encode( enc_String_Equals(tmp1, tmp2, str1, str2, tmp3, tmp4, result) );
-  ins_pipe( pipe_slow );
-%}
-
-instruct string_indexof(eSIRegP str1, eDIRegP str2, regXD tmp1, eAXRegI tmp2,
-                        eCXRegI tmp3, eDXRegI tmp4, eBXRegI result, eFlagsReg cr) %{
+instruct string_equals(eDIRegP str1, eSIRegP str2, eCXRegI cnt, eAXRegI result,
+                       regXD tmp1, regXD tmp2, eBXRegI tmp3, eFlagsReg cr) %{
+  match(Set result (StrEquals (Binary str1 str2) cnt));
+  effect(TEMP tmp1, TEMP tmp2, USE_KILL str1, USE_KILL str2, USE_KILL cnt, KILL tmp3, KILL cr);
+
+  format %{ "String Equals $str1,$str2,$cnt -> $result    // KILL $tmp1, $tmp2, $tmp3" %}
+  ins_encode %{
+    __ char_arrays_equals(false, $str1$$Register, $str2$$Register,
+                          $cnt$$Register, $result$$Register, $tmp3$$Register,
+                          $tmp1$$XMMRegister, $tmp2$$XMMRegister);
+  %}
+  ins_pipe( pipe_slow );
+%}
+
+instruct string_indexof(eDIRegP str1, eDXRegI cnt1, eSIRegP str2, eAXRegI cnt2,
+                        eBXRegI result, regXD tmp1, eCXRegI tmp2, eFlagsReg cr) %{
   predicate(UseSSE42Intrinsics);
-  match(Set result (StrIndexOf str1 str2));
-  effect(TEMP tmp1, USE_KILL str1, USE_KILL str2, KILL tmp2, KILL tmp3, KILL tmp4, KILL cr);
-
-  format %{ "String IndexOf $str1,$str2 -> $result    // KILL EAX, ECX, EDX" %}
-  ins_encode( enc_String_IndexOf(str1, str2, tmp1, tmp2, tmp3, tmp4, result) );
+  match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 cnt2)));
+  effect(TEMP tmp1, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL tmp2, KILL cr);
+
+  format %{ "String IndexOf $str1,$cnt1,$str2,$cnt2 -> $result   // KILL $tmp2, $tmp1" %}
+  ins_encode %{
+    __ string_indexof($str1$$Register, $str2$$Register,
+                      $cnt1$$Register, $cnt2$$Register, $result$$Register,
+                      $tmp1$$XMMRegister, $tmp2$$Register);
+  %}
   ins_pipe( pipe_slow );
 %}
 
 // fast array equals
-instruct array_equals(eDIRegP ary1, eSIRegP ary2, regXD tmp1, regXD tmp2, eBXRegI tmp3,
-                      eDXRegI tmp4, eAXRegI result, eFlagsReg cr) %{
+instruct array_equals(eDIRegP ary1, eSIRegP ary2, eAXRegI result,
+                      regXD tmp1, regXD tmp2, eCXRegI tmp3, eBXRegI tmp4, eFlagsReg cr)
+%{
   match(Set result (AryEq ary1 ary2));
   effect(TEMP tmp1, TEMP tmp2, USE_KILL ary1, USE_KILL ary2, KILL tmp3, KILL tmp4, KILL cr);
   //ins_cost(300);
 
-  format %{ "Array Equals $ary1,$ary2 -> $result    // KILL EBX, EDX" %}
-  ins_encode( enc_Array_Equals(ary1, ary2, tmp1, tmp2, tmp3, tmp4, result) );
+  format %{ "Array Equals $ary1,$ary2 -> $result   // KILL $tmp1, $tmp2, $tmp3, $tmp4" %}
+  ins_encode %{
+    __ char_arrays_equals(true, $ary1$$Register, $ary2$$Register,
+                          $tmp3$$Register, $result$$Register, $tmp4$$Register,
+                          $tmp1$$XMMRegister, $tmp2$$XMMRegister);
+  %}
   ins_pipe( pipe_slow );
 %}
 
--- a/hotspot/src/cpu/x86/vm/x86_64.ad	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/cpu/x86/vm/x86_64.ad	Fri Oct 16 18:02:31 2009 -0700
@@ -683,7 +683,7 @@
 #ifdef ASSERT
   if (rspec.reloc()->type() == relocInfo::oop_type &&
       d32 != 0 && d32 != (intptr_t) Universe::non_oop_word()) {
-    assert(oop((intptr_t)d32)->is_oop() && oop((intptr_t)d32)->is_perm(), "cannot embed non-perm oops in code");
+    assert(oop((intptr_t)d32)->is_oop() && (ScavengeRootsInCode || !oop((intptr_t)d32)->is_scavengable()), "cannot embed scavengable oops in code");
   }
 #endif
   cbuf.relocate(cbuf.inst_mark(), rspec, format);
@@ -721,8 +721,8 @@
 #ifdef ASSERT
   if (rspec.reloc()->type() == relocInfo::oop_type &&
       d64 != 0 && d64 != (int64_t) Universe::non_oop_word()) {
-    assert(oop(d64)->is_oop() && oop(d64)->is_perm(),
-           "cannot embed non-perm oops in code");
+    assert(oop(d64)->is_oop() && (ScavengeRootsInCode || !oop(d64)->is_scavengable()),
+           "cannot embed scavengable oops in code");
   }
 #endif
   cbuf.relocate(cbuf.inst_mark(), rspec, format);
@@ -3701,448 +3701,6 @@
     }
   %}
 
-  enc_class enc_String_Compare(rdi_RegP str1, rsi_RegP str2, regD tmp1, regD tmp2,
-                        rax_RegI tmp3, rbx_RegI tmp4, rcx_RegI result) %{
-    Label RCX_GOOD_LABEL, LENGTH_DIFF_LABEL,
-          POP_LABEL, DONE_LABEL, CONT_LABEL,
-          WHILE_HEAD_LABEL;
-    MacroAssembler masm(&cbuf);
-
-    XMMRegister tmp1Reg   = as_XMMRegister($tmp1$$reg);
-    XMMRegister tmp2Reg   = as_XMMRegister($tmp2$$reg);
-
-    // Get the first character position in both strings
-    //         [8] char array, [12] offset, [16] count
-    int value_offset  = java_lang_String::value_offset_in_bytes();
-    int offset_offset = java_lang_String::offset_offset_in_bytes();
-    int count_offset  = java_lang_String::count_offset_in_bytes();
-    int base_offset   = arrayOopDesc::base_offset_in_bytes(T_CHAR);
-
-    masm.load_heap_oop(rax, Address(rsi, value_offset));
-    masm.movl(rcx, Address(rsi, offset_offset));
-    masm.lea(rax, Address(rax, rcx, Address::times_2, base_offset));
-    masm.load_heap_oop(rbx, Address(rdi, value_offset));
-    masm.movl(rcx, Address(rdi, offset_offset));
-    masm.lea(rbx, Address(rbx, rcx, Address::times_2, base_offset));
-
-    // Compute the minimum of the string lengths(rsi) and the
-    // difference of the string lengths (stack)
-
-    // do the conditional move stuff
-    masm.movl(rdi, Address(rdi, count_offset));
-    masm.movl(rsi, Address(rsi, count_offset));
-    masm.movl(rcx, rdi);
-    masm.subl(rdi, rsi);
-    masm.push(rdi);
-    masm.cmov(Assembler::lessEqual, rsi, rcx);
-
-    // Is the minimum length zero?
-    masm.bind(RCX_GOOD_LABEL);
-    masm.testl(rsi, rsi);
-    masm.jcc(Assembler::zero, LENGTH_DIFF_LABEL);
-
-    // Load first characters
-    masm.load_unsigned_short(rcx, Address(rbx, 0));
-    masm.load_unsigned_short(rdi, Address(rax, 0));
-
-    // Compare first characters
-    masm.subl(rcx, rdi);
-    masm.jcc(Assembler::notZero,  POP_LABEL);
-    masm.decrementl(rsi);
-    masm.jcc(Assembler::zero, LENGTH_DIFF_LABEL);
-
-    {
-      // Check after comparing first character to see if strings are equivalent
-      Label LSkip2;
-      // Check if the strings start at same location
-      masm.cmpptr(rbx, rax);
-      masm.jccb(Assembler::notEqual, LSkip2);
-
-      // Check if the length difference is zero (from stack)
-      masm.cmpl(Address(rsp, 0), 0x0);
-      masm.jcc(Assembler::equal,  LENGTH_DIFF_LABEL);
-
-      // Strings might not be equivalent
-      masm.bind(LSkip2);
-    }
-
-    // Advance to next character
-    masm.addptr(rax, 2);
-    masm.addptr(rbx, 2);
-
-    if (UseSSE42Intrinsics) {
-      // With SSE4.2, use double quad vector compare
-      Label COMPARE_VECTORS, VECTOR_NOT_EQUAL, COMPARE_TAIL;
-      // Setup to compare 16-byte vectors
-      masm.movl(rdi, rsi);
-      masm.andl(rsi, 0xfffffff8); // rsi holds the vector count
-      masm.andl(rdi, 0x00000007); // rdi holds the tail count
-      masm.testl(rsi, rsi);
-      masm.jccb(Assembler::zero, COMPARE_TAIL);
-
-      masm.lea(rax, Address(rax, rsi, Address::times_2));
-      masm.lea(rbx, Address(rbx, rsi, Address::times_2));
-      masm.negptr(rsi);
-
-      masm.bind(COMPARE_VECTORS);
-      masm.movdqu(tmp1Reg, Address(rax, rsi, Address::times_2));
-      masm.movdqu(tmp2Reg, Address(rbx, rsi, Address::times_2));
-      masm.pxor(tmp1Reg, tmp2Reg);
-      masm.ptest(tmp1Reg, tmp1Reg);
-      masm.jccb(Assembler::notZero, VECTOR_NOT_EQUAL);
-      masm.addptr(rsi, 8);
-      masm.jcc(Assembler::notZero, COMPARE_VECTORS);
-      masm.jmpb(COMPARE_TAIL);
-
-      // Mismatched characters in the vectors
-      masm.bind(VECTOR_NOT_EQUAL);
-      masm.lea(rax, Address(rax, rsi, Address::times_2));
-      masm.lea(rbx, Address(rbx, rsi, Address::times_2));
-      masm.movl(rdi, 8);
-
-      // Compare tail (< 8 chars), or rescan last vectors to
-      // find 1st mismatched characters
-      masm.bind(COMPARE_TAIL);
-      masm.testl(rdi, rdi);
-      masm.jccb(Assembler::zero, LENGTH_DIFF_LABEL);
-      masm.movl(rsi, rdi);
-      // Fallthru to tail compare
-    }
-
-    // Shift RAX and RBX to the end of the arrays, negate min
-    masm.lea(rax, Address(rax, rsi, Address::times_2, 0));
-    masm.lea(rbx, Address(rbx, rsi, Address::times_2, 0));
-    masm.negptr(rsi);
-
-    // Compare the rest of the characters
-    masm.bind(WHILE_HEAD_LABEL);
-    masm.load_unsigned_short(rcx, Address(rbx, rsi, Address::times_2, 0));
-    masm.load_unsigned_short(rdi, Address(rax, rsi, Address::times_2, 0));
-    masm.subl(rcx, rdi);
-    masm.jccb(Assembler::notZero, POP_LABEL);
-    masm.increment(rsi);
-    masm.jcc(Assembler::notZero, WHILE_HEAD_LABEL);
-
-    // Strings are equal up to min length.  Return the length difference.
-    masm.bind(LENGTH_DIFF_LABEL);
-    masm.pop(rcx);
-    masm.jmpb(DONE_LABEL);
-
-    // Discard the stored length difference
-    masm.bind(POP_LABEL);
-    masm.addptr(rsp, 8);
-
-    // That's it
-    masm.bind(DONE_LABEL);
-  %}
-
- enc_class enc_String_IndexOf(rsi_RegP str1, rdi_RegP str2, regD tmp1, rax_RegI tmp2,
-                        rcx_RegI tmp3, rdx_RegI tmp4, rbx_RegI result) %{
-    // SSE4.2 version
-    Label LOAD_SUBSTR, PREP_FOR_SCAN, SCAN_TO_SUBSTR,
-          SCAN_SUBSTR, RET_NEG_ONE, RET_NOT_FOUND, CLEANUP, DONE;
-    MacroAssembler masm(&cbuf);
-
-    XMMRegister tmp1Reg   = as_XMMRegister($tmp1$$reg);
-
-    // Get the first character position in both strings
-    //         [8] char array, [12] offset, [16] count
-    int value_offset  = java_lang_String::value_offset_in_bytes();
-    int offset_offset = java_lang_String::offset_offset_in_bytes();
-    int count_offset  = java_lang_String::count_offset_in_bytes();
-    int base_offset   = arrayOopDesc::base_offset_in_bytes(T_CHAR);
-
-    // Get counts for string and substr
-    masm.movl(rdx, Address(rsi, count_offset));
-    masm.movl(rax, Address(rdi, count_offset));
-    // Check for substr count > string count
-    masm.cmpl(rax, rdx);
-    masm.jcc(Assembler::greater, RET_NEG_ONE);
-
-    // Start the indexOf operation
-    // Get start addr of string
-    masm.load_heap_oop(rbx, Address(rsi, value_offset));
-    masm.movl(rcx, Address(rsi, offset_offset));
-    masm.lea(rsi, Address(rbx, rcx, Address::times_2, base_offset));
-    masm.push(rsi);
-
-    // Get start addr of substr
-    masm.load_heap_oop(rbx, Address(rdi, value_offset));
-    masm.movl(rcx, Address(rdi, offset_offset));
-    masm.lea(rdi, Address(rbx, rcx, Address::times_2, base_offset));
-    masm.push(rdi);
-    masm.push(rax);
-    masm.jmpb(PREP_FOR_SCAN);
-
-    // Substr count saved at sp
-    // Substr saved at sp+8
-    // String saved at sp+16
-
-    // Prep to load substr for scan
-    masm.bind(LOAD_SUBSTR);
-    masm.movptr(rdi, Address(rsp, 8));
-    masm.movl(rax, Address(rsp, 0));
-
-    // Load substr
-    masm.bind(PREP_FOR_SCAN);
-    masm.movdqu(tmp1Reg, Address(rdi, 0));
-    masm.addq(rdx, 8);    // prime the loop
-    masm.subptr(rsi, 16);
-
-    // Scan string for substr in 16-byte vectors
-    masm.bind(SCAN_TO_SUBSTR);
-    masm.subq(rdx, 8);
-    masm.addptr(rsi, 16);
-    masm.pcmpestri(tmp1Reg, Address(rsi, 0), 0x0d);
-    masm.jcc(Assembler::above, SCAN_TO_SUBSTR);
-    masm.jccb(Assembler::aboveEqual, RET_NOT_FOUND);
-
-    // Fallthru: found a potential substr
-
-    //Make sure string is still long enough
-    masm.subl(rdx, rcx);
-    masm.cmpl(rdx, rax);
-    masm.jccb(Assembler::negative, RET_NOT_FOUND);
-    // Compute start addr of substr
-    masm.lea(rsi, Address(rsi, rcx, Address::times_2));
-    masm.movptr(rbx, rsi);
-
-    // Compare potential substr
-    masm.addq(rdx, 8);        // prime the loop
-    masm.addq(rax, 8);
-    masm.subptr(rsi, 16);
-    masm.subptr(rdi, 16);
-
-    // Scan 16-byte vectors of string and substr
-    masm.bind(SCAN_SUBSTR);
-    masm.subq(rax, 8);
-    masm.subq(rdx, 8);
-    masm.addptr(rsi, 16);
-    masm.addptr(rdi, 16);
-    masm.movdqu(tmp1Reg, Address(rdi, 0));
-    masm.pcmpestri(tmp1Reg, Address(rsi, 0), 0x0d);
-    masm.jcc(Assembler::noOverflow, LOAD_SUBSTR);   // OF == 0
-    masm.jcc(Assembler::positive, SCAN_SUBSTR);     // SF == 0
-
-    // Compute substr offset
-    masm.movptr(rsi, Address(rsp, 16));
-    masm.subptr(rbx, rsi);
-    masm.shrl(rbx, 1);
-    masm.jmpb(CLEANUP);
-
-    masm.bind(RET_NEG_ONE);
-    masm.movl(rbx, -1);
-    masm.jmpb(DONE);
-
-    masm.bind(RET_NOT_FOUND);
-    masm.movl(rbx, -1);
-
-    masm.bind(CLEANUP);
-    masm.addptr(rsp, 24);
-
-    masm.bind(DONE);
-  %}
-
-  enc_class enc_String_Equals(rdi_RegP str1, rsi_RegP str2, regD tmp1, regD tmp2,
-                              rbx_RegI tmp3, rcx_RegI tmp2, rax_RegI result) %{
-    Label RET_TRUE, RET_FALSE, DONE, COMPARE_VECTORS, COMPARE_CHAR;
-    MacroAssembler masm(&cbuf);
-
-    XMMRegister tmp1Reg   = as_XMMRegister($tmp1$$reg);
-    XMMRegister tmp2Reg   = as_XMMRegister($tmp2$$reg);
-
-    int value_offset  = java_lang_String::value_offset_in_bytes();
-    int offset_offset = java_lang_String::offset_offset_in_bytes();
-    int count_offset  = java_lang_String::count_offset_in_bytes();
-    int base_offset   = arrayOopDesc::base_offset_in_bytes(T_CHAR);
-
-    // does source == target string?
-    masm.cmpptr(rdi, rsi);
-    masm.jcc(Assembler::equal, RET_TRUE);
-
-    // get and compare counts
-    masm.movl(rcx, Address(rdi, count_offset));
-    masm.movl(rax, Address(rsi, count_offset));
-    masm.cmpl(rcx, rax);
-    masm.jcc(Assembler::notEqual, RET_FALSE);
-    masm.testl(rax, rax);
-    masm.jcc(Assembler::zero, RET_TRUE);
-
-    // get source string offset and value
-    masm.load_heap_oop(rbx, Address(rsi, value_offset));
-    masm.movl(rax, Address(rsi, offset_offset));
-    masm.lea(rsi, Address(rbx, rax, Address::times_2, base_offset));
-
-    // get compare string offset and value
-    masm.load_heap_oop(rbx, Address(rdi, value_offset));
-    masm.movl(rax, Address(rdi, offset_offset));
-    masm.lea(rdi, Address(rbx, rax, Address::times_2, base_offset));
-
-    // Set byte count
-    masm.shll(rcx, 1);
-    masm.movl(rax, rcx);
-
-    if (UseSSE42Intrinsics) {
-      // With SSE4.2, use double quad vector compare
-      Label COMPARE_WIDE_VECTORS, COMPARE_TAIL;
-      // Compare 16-byte vectors
-      masm.andl(rcx, 0xfffffff0);  // vector count (in bytes)
-      masm.andl(rax, 0x0000000e);  // tail count (in bytes)
-      masm.testl(rcx, rcx);
-      masm.jccb(Assembler::zero, COMPARE_TAIL);
-      masm.lea(rdi, Address(rdi, rcx, Address::times_1));
-      masm.lea(rsi, Address(rsi, rcx, Address::times_1));
-      masm.negptr(rcx);
-
-      masm.bind(COMPARE_WIDE_VECTORS);
-      masm.movdqu(tmp1Reg, Address(rdi, rcx, Address::times_1));
-      masm.movdqu(tmp2Reg, Address(rsi, rcx, Address::times_1));
-      masm.pxor(tmp1Reg, tmp2Reg);
-      masm.ptest(tmp1Reg, tmp1Reg);
-      masm.jccb(Assembler::notZero, RET_FALSE);
-      masm.addptr(rcx, 16);
-      masm.jcc(Assembler::notZero, COMPARE_WIDE_VECTORS);
-      masm.bind(COMPARE_TAIL);
-      masm.movl(rcx, rax);
-      // Fallthru to tail compare
-    }
-
-    // Compare 4-byte vectors
-    masm.andl(rcx, 0xfffffffc);  // vector count (in bytes)
-    masm.andl(rax, 0x00000002);  // tail char (in bytes)
-    masm.testl(rcx, rcx);
-    masm.jccb(Assembler::zero, COMPARE_CHAR);
-    masm.lea(rdi, Address(rdi, rcx, Address::times_1));
-    masm.lea(rsi, Address(rsi, rcx, Address::times_1));
-    masm.negptr(rcx);
-
-    masm.bind(COMPARE_VECTORS);
-    masm.movl(rbx, Address(rdi, rcx, Address::times_1));
-    masm.cmpl(rbx, Address(rsi, rcx, Address::times_1));
-    masm.jccb(Assembler::notEqual, RET_FALSE);
-    masm.addptr(rcx, 4);
-    masm.jcc(Assembler::notZero, COMPARE_VECTORS);
-
-    // Compare trailing char (final 2 bytes), if any
-    masm.bind(COMPARE_CHAR);
-    masm.testl(rax, rax);
-    masm.jccb(Assembler::zero, RET_TRUE);
-    masm.load_unsigned_short(rbx, Address(rdi, 0));
-    masm.load_unsigned_short(rcx, Address(rsi, 0));
-    masm.cmpl(rbx, rcx);
-    masm.jccb(Assembler::notEqual, RET_FALSE);
-
-    masm.bind(RET_TRUE);
-    masm.movl(rax, 1);   // return true
-    masm.jmpb(DONE);
-
-    masm.bind(RET_FALSE);
-    masm.xorl(rax, rax); // return false
-
-    masm.bind(DONE);
-  %}
-
-  enc_class enc_Array_Equals(rdi_RegP ary1, rsi_RegP ary2, regD tmp1, regD tmp2,
-                             rax_RegI tmp3, rbx_RegI tmp4, rcx_RegI result) %{
-    Label TRUE_LABEL, FALSE_LABEL, DONE, COMPARE_VECTORS, COMPARE_CHAR;
-    MacroAssembler masm(&cbuf);
-
-    XMMRegister tmp1Reg   = as_XMMRegister($tmp1$$reg);
-    XMMRegister tmp2Reg   = as_XMMRegister($tmp2$$reg);
-    Register ary1Reg      = as_Register($ary1$$reg);
-    Register ary2Reg      = as_Register($ary2$$reg);
-    Register tmp3Reg      = as_Register($tmp3$$reg);
-    Register tmp4Reg      = as_Register($tmp4$$reg);
-    Register resultReg    = as_Register($result$$reg);
-
-    int length_offset  = arrayOopDesc::length_offset_in_bytes();
-    int base_offset    = arrayOopDesc::base_offset_in_bytes(T_CHAR);
-
-    // Check the input args
-    masm.cmpq(ary1Reg, ary2Reg);
-    masm.jcc(Assembler::equal, TRUE_LABEL);
-    masm.testq(ary1Reg, ary1Reg);
-    masm.jcc(Assembler::zero, FALSE_LABEL);
-    masm.testq(ary2Reg, ary2Reg);
-    masm.jcc(Assembler::zero, FALSE_LABEL);
-
-    // Check the lengths
-    masm.movl(tmp4Reg, Address(ary1Reg, length_offset));
-    masm.movl(resultReg, Address(ary2Reg, length_offset));
-    masm.cmpl(tmp4Reg, resultReg);
-    masm.jcc(Assembler::notEqual, FALSE_LABEL);
-    masm.testl(resultReg, resultReg);
-    masm.jcc(Assembler::zero, TRUE_LABEL);
-
-    //load array address
-    masm.lea(ary1Reg, Address(ary1Reg, base_offset));
-    masm.lea(ary2Reg, Address(ary2Reg, base_offset));
-
-    //set byte count
-    masm.shll(tmp4Reg, 1);
-    masm.movl(resultReg,tmp4Reg);
-
-    if (UseSSE42Intrinsics){
-      // With SSE4.2, use double quad vector compare
-      Label COMPARE_WIDE_VECTORS, COMPARE_TAIL;
-      // Compare 16-byte vectors
-      masm.andl(tmp4Reg, 0xfffffff0);    // vector count (in bytes)
-      masm.andl(resultReg, 0x0000000e);  // tail count (in bytes)
-      masm.testl(tmp4Reg, tmp4Reg);
-      masm.jccb(Assembler::zero, COMPARE_TAIL);
-      masm.lea(ary1Reg, Address(ary1Reg, tmp4Reg, Address::times_1));
-      masm.lea(ary2Reg, Address(ary2Reg, tmp4Reg, Address::times_1));
-      masm.negptr(tmp4Reg);
-
-      masm.bind(COMPARE_WIDE_VECTORS);
-      masm.movdqu(tmp1Reg, Address(ary1Reg, tmp4Reg, Address::times_1));
-      masm.movdqu(tmp2Reg, Address(ary2Reg, tmp4Reg, Address::times_1));
-      masm.pxor(tmp1Reg, tmp2Reg);
-      masm.ptest(tmp1Reg, tmp1Reg);
-
-      masm.jccb(Assembler::notZero, FALSE_LABEL);
-      masm.addptr(tmp4Reg, 16);
-      masm.jcc(Assembler::notZero, COMPARE_WIDE_VECTORS);
-      masm.bind(COMPARE_TAIL);
-      masm.movl(tmp4Reg, resultReg);
-      // Fallthru to tail compare
-    }
-
-   // Compare 4-byte vectors
-    masm.andl(tmp4Reg, 0xfffffffc);    // vector count (in bytes)
-    masm.andl(resultReg, 0x00000002);  // tail char (in bytes)
-    masm.testl(tmp4Reg, tmp4Reg); //if tmp2 == 0, only compare char
-    masm.jccb(Assembler::zero, COMPARE_CHAR);
-    masm.lea(ary1Reg, Address(ary1Reg, tmp4Reg, Address::times_1));
-    masm.lea(ary2Reg, Address(ary2Reg, tmp4Reg, Address::times_1));
-    masm.negptr(tmp4Reg);
-
-    masm.bind(COMPARE_VECTORS);
-    masm.movl(tmp3Reg, Address(ary1Reg, tmp4Reg, Address::times_1));
-    masm.cmpl(tmp3Reg, Address(ary2Reg, tmp4Reg, Address::times_1));
-    masm.jccb(Assembler::notEqual, FALSE_LABEL);
-    masm.addptr(tmp4Reg, 4);
-    masm.jcc(Assembler::notZero, COMPARE_VECTORS);
-
-    // Compare trailing char (final 2 bytes), if any
-    masm.bind(COMPARE_CHAR);
-    masm.testl(resultReg, resultReg);
-    masm.jccb(Assembler::zero, TRUE_LABEL);
-    masm.load_unsigned_short(tmp3Reg, Address(ary1Reg, 0));
-    masm.load_unsigned_short(tmp4Reg, Address(ary2Reg, 0));
-    masm.cmpl(tmp3Reg, tmp4Reg);
-    masm.jccb(Assembler::notEqual, FALSE_LABEL);
-
-    masm.bind(TRUE_LABEL);
-    masm.movl(resultReg, 1);   // return true
-    masm.jmpb(DONE);
-
-    masm.bind(FALSE_LABEL);
-    masm.xorl(resultReg, resultReg); // return false
-
-    // That's it
-    masm.bind(DONE);
-  %}
 
   enc_class enc_rethrow()
   %{
@@ -12096,52 +11654,67 @@
   ins_pipe(pipe_slow);
 %}
 
-instruct string_compare(rdi_RegP str1, rsi_RegP str2, regD tmp1, regD tmp2,
-                        rax_RegI tmp3, rbx_RegI tmp4, rcx_RegI result, rFlagsReg cr)
-%{
-  match(Set result (StrComp str1 str2));
-  effect(TEMP tmp1, TEMP tmp2, USE_KILL str1, USE_KILL str2, KILL tmp3, KILL tmp4, KILL cr);
-  //ins_cost(300);
-
-  format %{ "String Compare $str1, $str2 -> $result    // XXX KILL RAX, RBX" %}
-  ins_encode( enc_String_Compare(str1, str2, tmp1, tmp2, tmp3, tmp4, result) );
+instruct string_compare(rdi_RegP str1, rcx_RegI cnt1, rsi_RegP str2, rbx_RegI cnt2,
+                        rax_RegI result, regD tmp1, regD tmp2, rFlagsReg cr)
+%{
+  match(Set result (StrComp (Binary str1 cnt1) (Binary str2 cnt2)));
+  effect(TEMP tmp1, TEMP tmp2, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL cr);
+
+  format %{ "String Compare $str1,$cnt1,$str2,$cnt2 -> $result   // KILL $tmp1, $tmp2" %}
+  ins_encode %{
+    __ string_compare($str1$$Register, $str2$$Register,
+                      $cnt1$$Register, $cnt2$$Register, $result$$Register,
+                      $tmp1$$XMMRegister, $tmp2$$XMMRegister);
+  %}
   ins_pipe( pipe_slow );
 %}
 
-instruct string_indexof(rsi_RegP str1, rdi_RegP str2, regD tmp1, rax_RegI tmp2,
-                        rcx_RegI tmp3, rdx_RegI tmp4, rbx_RegI result, rFlagsReg cr)
+instruct string_indexof(rdi_RegP str1, rdx_RegI cnt1, rsi_RegP str2, rax_RegI cnt2,
+                        rbx_RegI result, regD tmp1, rcx_RegI tmp2, rFlagsReg cr)
 %{
   predicate(UseSSE42Intrinsics);
-  match(Set result (StrIndexOf str1 str2));
-  effect(TEMP tmp1, USE_KILL str1, USE_KILL str2, KILL tmp2, KILL tmp3, KILL tmp4, KILL cr);
-
-  format %{ "String IndexOf $str1,$str2 -> $result   // KILL RAX, RCX, RDX" %}
-  ins_encode( enc_String_IndexOf(str1, str2, tmp1, tmp2, tmp3, tmp4, result) );
+  match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 cnt2)));
+  effect(TEMP tmp1, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL tmp2, KILL cr);
+
+  format %{ "String IndexOf $str1,$cnt1,$str2,$cnt2 -> $result   // KILL $tmp1, $tmp2" %}
+  ins_encode %{
+    __ string_indexof($str1$$Register, $str2$$Register,
+                      $cnt1$$Register, $cnt2$$Register, $result$$Register,
+                      $tmp1$$XMMRegister, $tmp2$$Register);
+  %}
   ins_pipe( pipe_slow );
 %}
 
 // fast string equals
-instruct string_equals(rdi_RegP str1, rsi_RegP str2, regD tmp1, regD tmp2, rbx_RegI tmp3,
-                       rcx_RegI tmp4, rax_RegI result, rFlagsReg cr)
-%{
-  match(Set result (StrEquals str1 str2));
-  effect(TEMP tmp1, TEMP tmp2, USE_KILL str1, USE_KILL str2, KILL tmp3, KILL tmp4, KILL cr);
-
-  format %{ "String Equals $str1,$str2 -> $result    // KILL RBX, RCX" %}
-  ins_encode( enc_String_Equals(str1, str2, tmp1, tmp2, tmp3, tmp4, result) );
+instruct string_equals(rdi_RegP str1, rsi_RegP str2, rcx_RegI cnt, rax_RegI result,
+                       regD tmp1, regD tmp2, rbx_RegI tmp3, rFlagsReg cr)
+%{
+  match(Set result (StrEquals (Binary str1 str2) cnt));
+  effect(TEMP tmp1, TEMP tmp2, USE_KILL str1, USE_KILL str2, USE_KILL cnt, KILL tmp3, KILL cr);
+
+  format %{ "String Equals $str1,$str2,$cnt -> $result    // KILL $tmp1, $tmp2, $tmp3" %}
+  ins_encode %{
+    __ char_arrays_equals(false, $str1$$Register, $str2$$Register,
+                          $cnt$$Register, $result$$Register, $tmp3$$Register,
+                          $tmp1$$XMMRegister, $tmp2$$XMMRegister);
+  %}
   ins_pipe( pipe_slow );
 %}
 
 // fast array equals
-instruct array_equals(rdi_RegP ary1, rsi_RegP ary2, regD tmp1, regD tmp2, rax_RegI tmp3,
-                      rbx_RegI tmp4, rcx_RegI result, rFlagsReg cr)
+instruct array_equals(rdi_RegP ary1, rsi_RegP ary2, rax_RegI result,
+                      regD tmp1, regD tmp2, rcx_RegI tmp3, rbx_RegI tmp4, rFlagsReg cr)
 %{
   match(Set result (AryEq ary1 ary2));
   effect(TEMP tmp1, TEMP tmp2, USE_KILL ary1, USE_KILL ary2, KILL tmp3, KILL tmp4, KILL cr);
   //ins_cost(300);
 
-  format %{ "Array Equals $ary1,$ary2 -> $result   // KILL RAX, RBX" %}
-  ins_encode( enc_Array_Equals(ary1, ary2, tmp1, tmp2, tmp3, tmp4, result) );
+  format %{ "Array Equals $ary1,$ary2 -> $result   // KILL $tmp1, $tmp2, $tmp3, $tmp4" %}
+  ins_encode %{
+    __ char_arrays_equals(true, $ary1$$Register, $ary2$$Register,
+                          $tmp3$$Register, $result$$Register, $tmp4$$Register,
+                          $tmp1$$XMMRegister, $tmp2$$XMMRegister);
+  %}
   ins_pipe( pipe_slow );
 %}
 
--- a/hotspot/src/share/vm/adlc/formssel.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/adlc/formssel.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -828,11 +828,13 @@
     return AdlcVMDeps::Parms;   // Skip the machine-state edges
 
   if( _matrule->_rChild &&
-      ( strcmp(_matrule->_rChild->_opType,"StrComp"   )==0 ||
+      ( strcmp(_matrule->_rChild->_opType,"AryEq"     )==0 ||
+        strcmp(_matrule->_rChild->_opType,"StrComp"   )==0 ||
         strcmp(_matrule->_rChild->_opType,"StrEquals" )==0 ||
         strcmp(_matrule->_rChild->_opType,"StrIndexOf")==0 )) {
-        // String.(compareTo/equals/indexOf) take 1 control and 4 memory edges.
-    return 5;
+        // String.(compareTo/equals/indexOf) and Arrays.equals
+        // take 1 control and 1 memory edges.
+    return 2;
   }
 
   // Check for handling of 'Memory' input/edge in the ideal world.
--- a/hotspot/src/share/vm/c1/c1_GraphBuilder.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/c1/c1_GraphBuilder.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -1442,7 +1442,7 @@
         switch (field_type) {
         case T_ARRAY:
         case T_OBJECT:
-          if (field_val.as_object()->has_encoding()) {
+          if (field_val.as_object()->should_be_constant()) {
             constant =  new Constant(as_ValueType(field_val));
           }
           break;
--- a/hotspot/src/share/vm/c1/c1_InstructionPrinter.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/c1/c1_InstructionPrinter.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -133,12 +133,12 @@
       ciMethod* m = (ciMethod*)value;
       output()->print("<method %s.%s>", m->holder()->name()->as_utf8(), m->name()->as_utf8());
     } else {
-      output()->print("<object 0x%x>", value->encoding());
+      output()->print("<object 0x%x>", value->constant_encoding());
     }
   } else if (type->as_InstanceConstant() != NULL) {
-    output()->print("<instance 0x%x>", type->as_InstanceConstant()->value()->encoding());
+    output()->print("<instance 0x%x>", type->as_InstanceConstant()->value()->constant_encoding());
   } else if (type->as_ArrayConstant() != NULL) {
-    output()->print("<array 0x%x>", type->as_ArrayConstant()->value()->encoding());
+    output()->print("<array 0x%x>", type->as_ArrayConstant()->value()->constant_encoding());
   } else if (type->as_ClassConstant() != NULL) {
     ciInstanceKlass* klass = type->as_ClassConstant()->value();
     if (!klass->is_loaded()) {
--- a/hotspot/src/share/vm/c1/c1_LIRGenerator.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/c1/c1_LIRGenerator.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -440,7 +440,7 @@
     __ oop2reg_patch(NULL, r, info);
   } else {
     // no patching needed
-    __ oop2reg(obj->encoding(), r);
+    __ oop2reg(obj->constant_encoding(), r);
   }
 }
 
@@ -831,7 +831,7 @@
     int taken_count_offset     = md->byte_offset_of_slot(data, BranchData::taken_offset());
     int not_taken_count_offset = md->byte_offset_of_slot(data, BranchData::not_taken_offset());
     LIR_Opr md_reg = new_register(T_OBJECT);
-    __ move(LIR_OprFact::oopConst(md->encoding()), md_reg);
+    __ move(LIR_OprFact::oopConst(md->constant_encoding()), md_reg);
     LIR_Opr data_offset_reg = new_register(T_INT);
     __ cmove(lir_cond(cond),
              LIR_OprFact::intConst(taken_count_offset),
@@ -1071,7 +1071,7 @@
     LIR_OprList* args = new LIR_OprList();
     args->append(getThreadPointer());
     LIR_Opr meth = new_register(T_OBJECT);
-    __ oop2reg(method()->encoding(), meth);
+    __ oop2reg(method()->constant_encoding(), meth);
     args->append(meth);
     call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), voidType, NULL);
   }
@@ -1784,7 +1784,7 @@
     LIR_OprList* args = new LIR_OprList();
     args->append(getThreadPointer());
     LIR_Opr meth = new_register(T_OBJECT);
-    __ oop2reg(method()->encoding(), meth);
+    __ oop2reg(method()->constant_encoding(), meth);
     args->append(meth);
     call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), voidType, NULL);
   }
@@ -2207,7 +2207,7 @@
     LIR_OprList* args = new LIR_OprList();
     args->append(getThreadPointer());
     LIR_Opr meth = new_register(T_OBJECT);
-    __ oop2reg(method()->encoding(), meth);
+    __ oop2reg(method()->constant_encoding(), meth);
     args->append(meth);
     call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), voidType, NULL);
   }
@@ -2216,7 +2216,7 @@
     LIR_Opr obj;
     if (method()->is_static()) {
       obj = new_register(T_OBJECT);
-      __ oop2reg(method()->holder()->java_mirror()->encoding(), obj);
+      __ oop2reg(method()->holder()->java_mirror()->constant_encoding(), obj);
     } else {
       Local* receiver = x->state()->local_at(0)->as_Local();
       assert(receiver != NULL, "must already exist");
@@ -2660,7 +2660,7 @@
     }
 
     LIR_Opr meth = new_register(T_OBJECT);
-    __ oop2reg(method()->encoding(), meth);
+    __ oop2reg(method()->constant_encoding(), meth);
     LIR_Opr result = increment_and_return_counter(meth, offset, InvocationCounter::count_increment);
     __ cmp(lir_cond_aboveEqual, result, LIR_OprFact::intConst(limit));
     CodeStub* overflow = new CounterOverflowStub(info, info->bci());
--- a/hotspot/src/share/vm/c1/c1_ValueType.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/c1/c1_ValueType.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -86,7 +86,7 @@
 
 jobject ObjectType::encoding() const {
   assert(is_constant(), "must be");
-  return constant_value()->encoding();
+  return constant_value()->constant_encoding();
 }
 
 bool ObjectType::is_loaded() const {
--- a/hotspot/src/share/vm/ci/ciEnv.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/ci/ciEnv.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -257,7 +257,7 @@
 
 // ------------------------------------------------------------------
 // ciEnv::make_array
-ciArray* ciEnv::make_array(GrowableArray<ciObject*>* objects) {
+ciArray* ciEnv::make_system_array(GrowableArray<ciObject*>* objects) {
   VM_ENTRY_MARK;
   int length = objects->length();
   objArrayOop a = oopFactory::new_system_objArray(length, THREAD);
--- a/hotspot/src/share/vm/ci/ciEnv.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/ci/ciEnv.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -339,8 +339,8 @@
   // but consider adding to vmSymbols.hpp instead.
 
   // Use this to make a holder for non-perm compile time constants.
-  // The resulting array is guaranteed to satisfy "has_encoding".
-  ciArray*  make_array(GrowableArray<ciObject*>* objects);
+  // The resulting array is guaranteed to satisfy "can_be_constant".
+  ciArray*  make_system_array(GrowableArray<ciObject*>* objects);
 
   // converts the ciKlass* representing the holder of a method into a
   // ciInstanceKlass*.  This is needed since the holder of a method in
--- a/hotspot/src/share/vm/ci/ciMethod.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/ci/ciMethod.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -325,10 +325,10 @@
 }
 
 // ------------------------------------------------------------------
-// ciMethod::liveness_at_bci
+// ciMethod::raw_liveness_at_bci
 //
 // Which local variables are live at a specific bci?
-MethodLivenessResult ciMethod::liveness_at_bci(int bci) {
+MethodLivenessResult ciMethod::raw_liveness_at_bci(int bci) {
   check_is_loaded();
   if (_liveness == NULL) {
     // Create the liveness analyzer.
@@ -336,7 +336,17 @@
     _liveness = new (arena) MethodLiveness(arena, this);
     _liveness->compute_liveness();
   }
-  MethodLivenessResult result = _liveness->get_liveness_at(bci);
+  return _liveness->get_liveness_at(bci);
+}
+
+// ------------------------------------------------------------------
+// ciMethod::liveness_at_bci
+//
+// Which local variables are live at a specific bci?  When debugging
+// will return true for all locals in some cases to improve debug
+// information.
+MethodLivenessResult ciMethod::liveness_at_bci(int bci) {
+  MethodLivenessResult result = raw_liveness_at_bci(bci);
   if (CURRENT_ENV->jvmti_can_access_local_variables() || DeoptimizeALot || CompileTheWorld) {
     // Keep all locals live for the user's edification and amusement.
     result.at_put_range(0, result.size(), true);
--- a/hotspot/src/share/vm/ci/ciMethod.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/ci/ciMethod.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -149,6 +149,12 @@
   bool          has_monitor_bytecodes() const    { return _uses_monitors; }
   bool          has_balanced_monitors();
 
+  // Returns a bitmap indicating which locals are required to be
+  // maintained as live for deopt.  raw_liveness_at_bci is always the
+  // direct output of the liveness computation while liveness_at_bci
+  // may mark all locals as live to improve support for debugging Java
+  // code by maintaining the state of as many locals as possible.
+  MethodLivenessResult raw_liveness_at_bci(int bci);
   MethodLivenessResult liveness_at_bci(int bci);
 
   // Get the interpreters viewpoint on oop liveness.  MethodLiveness is
--- a/hotspot/src/share/vm/ci/ciObject.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/ci/ciObject.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -55,6 +55,7 @@
   }
   _klass = NULL;
   _ident = 0;
+  init_flags_from(o);
 }
 
 // ------------------------------------------------------------------
@@ -69,6 +70,7 @@
   }
   _klass = NULL;
   _ident = 0;
+  init_flags_from(h());
 }
 
 // ------------------------------------------------------------------
@@ -158,7 +160,7 @@
 }
 
 // ------------------------------------------------------------------
-// ciObject::encoding
+// ciObject::constant_encoding
 //
 // The address which the compiler should embed into the
 // generated code to represent this oop.  This address
@@ -172,16 +174,24 @@
 //
 // This method should be changed to return an generified address
 // to discourage use of the JNI handle.
-jobject ciObject::encoding() {
+jobject ciObject::constant_encoding() {
   assert(is_null_object() || handle() != NULL, "cannot embed null pointer");
-  assert(has_encoding(), "oop must be NULL or perm");
+  assert(can_be_constant(), "oop must be NULL or perm");
   return handle();
 }
 
 // ------------------------------------------------------------------
-// ciObject::has_encoding
-bool ciObject::has_encoding() {
-  return handle() == NULL || is_perm();
+// ciObject::can_be_constant
+bool ciObject::can_be_constant() {
+  if (ScavengeRootsInCode >= 1)  return true;  // now everybody can encode as a constant
+  return handle() == NULL || !is_scavengable();
+}
+
+// ------------------------------------------------------------------
+// ciObject::should_be_constant()
+bool ciObject::should_be_constant() {
+  if (ScavengeRootsInCode >= 2)  return true;  // force everybody to be a constant
+  return handle() == NULL || !is_scavengable();
 }
 
 
@@ -195,8 +205,9 @@
 void ciObject::print(outputStream* st) {
   st->print("<%s", type_string());
   GUARDED_VM_ENTRY(print_impl(st);)
-  st->print(" ident=%d %s address=0x%x>", ident(),
+  st->print(" ident=%d %s%s address=0x%x>", ident(),
         is_perm() ? "PERM" : "",
+        is_scavengable() ? "SCAVENGABLE" : "",
         (address)this);
 }
 
--- a/hotspot/src/share/vm/ci/ciObject.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/ci/ciObject.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -51,9 +51,10 @@
   ciKlass* _klass;
   uint     _ident;
 
-  enum { FLAG_BITS   = 1};
+  enum { FLAG_BITS   = 2 };
   enum {
-         PERM_FLAG    = 1
+         PERM_FLAG        = 1,
+         SCAVENGABLE_FLAG = 2
        };
 protected:
   ciObject();
@@ -68,8 +69,15 @@
     return JNIHandles::resolve_non_null(_handle);
   }
 
-  void set_perm() {
-    _ident |=  PERM_FLAG;
+  void init_flags_from(oop x) {
+    int flags = 0;
+    if (x != NULL) {
+      if (x->is_perm())
+        flags |= PERM_FLAG;
+      if (x->is_scavengable())
+        flags |= SCAVENGABLE_FLAG;
+    }
+    _ident |= flags;
   }
 
   // Virtual behavior of the print() method.
@@ -91,17 +99,27 @@
   // A hash value for the convenience of compilers.
   int hash();
 
-  // Tells if this oop has an encoding.  (I.e., is it null or perm?)
+  // Tells if this oop has an encoding as a constant.
+  // True if is_scavengable is false.
+  // Also true if ScavengeRootsInCode is non-zero.
   // If it does not have an encoding, the compiler is responsible for
   // making other arrangements for dealing with the oop.
-  // See ciEnv::make_perm_array
-  bool has_encoding();
+  // See ciEnv::make_array
+  bool can_be_constant();
+
+  // Tells if this oop should be made a constant.
+  // True if is_scavengable is false or ScavengeRootsInCode > 1.
+  bool should_be_constant();
 
   // Is this object guaranteed to be in the permanent part of the heap?
   // If so, CollectedHeap::can_elide_permanent_oop_store_barriers is relevant.
   // If the answer is false, no guarantees are made.
   bool is_perm() { return (_ident & PERM_FLAG) != 0; }
 
+  // Might this object possibly move during a scavenge operation?
+  // If the answer is true and ScavengeRootsInCode==0, the oop cannot be embedded in code.
+  bool is_scavengable() { return (_ident & SCAVENGABLE_FLAG) != 0; }
+
   // The address which the compiler should embed into the
   // generated code to represent this oop.  This address
   // is not the true address of the oop -- it will get patched
@@ -109,7 +127,7 @@
   //
   // Usage note: no address arithmetic allowed.  Oop must
   // be registered with the oopRecorder.
-  jobject encoding();
+  jobject constant_encoding();
 
   // What kind of ciObject is this?
   virtual bool is_null_object() const       { return false; }
--- a/hotspot/src/share/vm/ci/ciObjectFactory.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/ci/ciObjectFactory.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -261,12 +261,11 @@
     ciObject* new_object = create_new_object(keyHandle());
     assert(keyHandle() == new_object->get_oop(), "must be properly recorded");
     init_ident_of(new_object);
-    if (!keyHandle->is_perm()) {
+    if (!new_object->is_perm()) {
       // Not a perm-space object.
       insert_non_perm(bucket, keyHandle(), new_object);
       return new_object;
     }
-    new_object->set_perm();
     if (len != _ci_objects->length()) {
       // creating the new object has recursively entered new objects
       // into the table.  We need to recompute our index.
--- a/hotspot/src/share/vm/ci/ciTypeFlow.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/ci/ciTypeFlow.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -2486,8 +2486,13 @@
         // Assume irreducible entries need more data flow
         add_to_work_list(succ);
       }
-      lp = lp->parent();
-      assert(lp != NULL, "nested loop must have parent by now");
+      Loop* plp = lp->parent();
+      if (plp == NULL) {
+        // This only happens for some irreducible cases.  The parent
+        // will be updated during a later pass.
+        break;
+      }
+      lp = plp;
     }
 
     // Merge loop tree branch for all successors.
--- a/hotspot/src/share/vm/classfile/systemDictionary.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/classfile/systemDictionary.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -2417,6 +2417,8 @@
                          vmSymbols::makeSite_name(), vmSymbols::makeSite_signature(),
                          &args, CHECK_(empty));
   oop call_site_oop = (oop) result.get_jobject();
+  assert(call_site_oop->is_oop()
+         /*&& sun_dyn_CallSiteImpl::is_instance(call_site_oop)*/, "must be sane");
   sun_dyn_CallSiteImpl::set_vmmethod(call_site_oop, mh_invdyn());
   if (TraceMethodHandles) {
     tty->print_cr("Linked invokedynamic bci=%d site="INTPTR_FORMAT":", caller_bci, call_site_oop);
@@ -2453,6 +2455,8 @@
   oop boot_method_oop = (oop) result.get_jobject();
 
   if (boot_method_oop != NULL) {
+    assert(boot_method_oop->is_oop()
+           && java_dyn_MethodHandle::is_instance(boot_method_oop), "must be sane");
     // probably no race conditions, but let's be careful:
     if (Atomic::cmpxchg_ptr(boot_method_oop, ik->adr_bootstrap_method(), NULL) == NULL)
       ik->set_bootstrap_method(boot_method_oop);
--- a/hotspot/src/share/vm/code/codeBlob.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/code/codeBlob.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -175,6 +175,8 @@
                             OopClosure* keep_alive,
                             bool unloading_occurred);
   virtual void oops_do(OopClosure* f) = 0;
+  // (All CodeBlob subtypes other than NMethod currently have
+  // an empty oops_do() method.
 
   // OopMap for frame
   OopMapSet* oop_maps() const                    { return _oop_maps; }
--- a/hotspot/src/share/vm/code/codeCache.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/code/codeCache.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -95,6 +95,7 @@
 int CodeCache::_number_of_blobs = 0;
 int CodeCache::_number_of_nmethods_with_dependencies = 0;
 bool CodeCache::_needs_cache_clean = false;
+nmethod* CodeCache::_scavenge_root_nmethods = NULL;
 
 
 CodeBlob* CodeCache::first() {
@@ -148,10 +149,7 @@
     }
   }
   verify_if_often();
-  if (PrintCodeCache2) {        // Need to add a new flag
-      ResourceMark rm;
-      tty->print_cr("CodeCache allocation:  addr: " INTPTR_FORMAT ", size: 0x%x\n", cb, size);
-  }
+  print_trace("allocation", cb, size);
   return cb;
 }
 
@@ -159,10 +157,7 @@
   assert_locked_or_safepoint(CodeCache_lock);
   verify_if_often();
 
-  if (PrintCodeCache2) {        // Need to add a new flag
-      ResourceMark rm;
-      tty->print_cr("CodeCache free:  addr: " INTPTR_FORMAT ", size: 0x%x\n", cb, cb->size());
-  }
+  print_trace("free", cb);
   if (cb->is_nmethod() && ((nmethod *)cb)->has_dependencies()) {
     _number_of_nmethods_with_dependencies--;
   }
@@ -260,14 +255,148 @@
   }
 }
 
-void CodeCache::oops_do(OopClosure* f) {
+void CodeCache::blobs_do(CodeBlobClosure* f) {
   assert_locked_or_safepoint(CodeCache_lock);
   FOR_ALL_ALIVE_BLOBS(cb) {
-    cb->oops_do(f);
+    f->do_code_blob(cb);
+
+#ifdef ASSERT
+    if (cb->is_nmethod())
+      ((nmethod*)cb)->verify_scavenge_root_oops();
+#endif //ASSERT
   }
 }
 
+// Walk the list of methods which might contain non-perm oops.
+void CodeCache::scavenge_root_nmethods_do(CodeBlobClosure* f) {
+  assert_locked_or_safepoint(CodeCache_lock);
+  debug_only(mark_scavenge_root_nmethods());
+
+  for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) {
+    debug_only(cur->clear_scavenge_root_marked());
+    assert(cur->scavenge_root_not_marked(), "");
+    assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
+
+    bool is_live = (!cur->is_zombie() && !cur->is_unloaded());
+#ifndef PRODUCT
+    if (TraceScavenge) {
+      cur->print_on(tty, is_live ? "scavenge root" : "dead scavenge root"); tty->cr();
+    }
+#endif //PRODUCT
+    if (is_live)
+      // Perform cur->oops_do(f), maybe just once per nmethod.
+      f->do_code_blob(cur);
+  }
+
+  // Check for stray marks.
+  debug_only(verify_perm_nmethods(NULL));
+}
+
+void CodeCache::add_scavenge_root_nmethod(nmethod* nm) {
+  assert_locked_or_safepoint(CodeCache_lock);
+  nm->set_on_scavenge_root_list();
+  nm->set_scavenge_root_link(_scavenge_root_nmethods);
+  set_scavenge_root_nmethods(nm);
+  print_trace("add_scavenge_root", nm);
+}
+
+void CodeCache::drop_scavenge_root_nmethod(nmethod* nm) {
+  assert_locked_or_safepoint(CodeCache_lock);
+  print_trace("drop_scavenge_root", nm);
+  nmethod* last = NULL;
+  nmethod* cur = scavenge_root_nmethods();
+  while (cur != NULL) {
+    nmethod* next = cur->scavenge_root_link();
+    if (cur == nm) {
+      if (last != NULL)
+            last->set_scavenge_root_link(next);
+      else  set_scavenge_root_nmethods(next);
+      nm->set_scavenge_root_link(NULL);
+      nm->clear_on_scavenge_root_list();
+      return;
+    }
+    last = cur;
+    cur = next;
+  }
+  assert(false, "should have been on list");
+}
+
+void CodeCache::prune_scavenge_root_nmethods() {
+  assert_locked_or_safepoint(CodeCache_lock);
+  debug_only(mark_scavenge_root_nmethods());
+
+  nmethod* last = NULL;
+  nmethod* cur = scavenge_root_nmethods();
+  while (cur != NULL) {
+    nmethod* next = cur->scavenge_root_link();
+    debug_only(cur->clear_scavenge_root_marked());
+    assert(cur->scavenge_root_not_marked(), "");
+    assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
+
+    if (!cur->is_zombie() && !cur->is_unloaded()
+        && cur->detect_scavenge_root_oops()) {
+      // Keep it.  Advance 'last' to prevent deletion.
+      last = cur;
+    } else {
+      // Prune it from the list, so we don't have to look at it any more.
+      print_trace("prune_scavenge_root", cur);
+      cur->set_scavenge_root_link(NULL);
+      cur->clear_on_scavenge_root_list();
+      if (last != NULL)
+            last->set_scavenge_root_link(next);
+      else  set_scavenge_root_nmethods(next);
+    }
+    cur = next;
+  }
+
+  // Check for stray marks.
+  debug_only(verify_perm_nmethods(NULL));
+}
+
+#ifndef PRODUCT
+void CodeCache::asserted_non_scavengable_nmethods_do(CodeBlobClosure* f) {
+  // While we are here, verify the integrity of the list.
+  mark_scavenge_root_nmethods();
+  for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) {
+    assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
+    cur->clear_scavenge_root_marked();
+  }
+  verify_perm_nmethods(f);
+}
+
+// Temporarily mark nmethods that are claimed to be on the non-perm list.
+void CodeCache::mark_scavenge_root_nmethods() {
+  FOR_ALL_ALIVE_BLOBS(cb) {
+    if (cb->is_nmethod()) {
+      nmethod *nm = (nmethod*)cb;
+      assert(nm->scavenge_root_not_marked(), "clean state");
+      if (nm->on_scavenge_root_list())
+        nm->set_scavenge_root_marked();
+    }
+  }
+}
+
+// If the closure is given, run it on the unlisted nmethods.
+// Also make sure that the effects of mark_scavenge_root_nmethods is gone.
+void CodeCache::verify_perm_nmethods(CodeBlobClosure* f_or_null) {
+  FOR_ALL_ALIVE_BLOBS(cb) {
+    bool call_f = (f_or_null != NULL);
+    if (cb->is_nmethod()) {
+      nmethod *nm = (nmethod*)cb;
+      assert(nm->scavenge_root_not_marked(), "must be already processed");
+      if (nm->on_scavenge_root_list())
+        call_f = false;  // don't show this one to the client
+      nm->verify_scavenge_root_oops();
+    } else {
+      call_f = false;   // not an nmethod
+    }
+    if (call_f)  f_or_null->do_code_blob(cb);
+  }
+}
+#endif //PRODUCT
+
 void CodeCache::gc_prologue() {
+  assert(!nmethod::oops_do_marking_is_active(), "oops_do_marking_epilogue must be called");
 }
 
 
@@ -285,6 +414,8 @@
     cb->fix_oop_relocations();
   }
   set_needs_cache_clean(false);
+  prune_scavenge_root_nmethods();
+  assert(!nmethod::oops_do_marking_is_active(), "oops_do_marking_prologue must be called");
 }
 
 
@@ -508,6 +639,14 @@
   }
 }
 
+void CodeCache::print_trace(const char* event, CodeBlob* cb, int size) {
+  if (PrintCodeCache2) {  // Need to add a new flag
+    ResourceMark rm;
+    if (size == 0)  size = cb->size();
+    tty->print_cr("CodeCache %s:  addr: " INTPTR_FORMAT ", size: 0x%x", event, cb, size);
+  }
+}
+
 void CodeCache::print_internals() {
   int nmethodCount = 0;
   int runtimeStubCount = 0;
--- a/hotspot/src/share/vm/code/codeCache.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/code/codeCache.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -45,8 +45,13 @@
   static int _number_of_blobs;
   static int _number_of_nmethods_with_dependencies;
   static bool _needs_cache_clean;
+  static nmethod* _scavenge_root_nmethods;  // linked via nm->scavenge_root_link()
 
   static void verify_if_often() PRODUCT_RETURN;
+
+  static void mark_scavenge_root_nmethods() PRODUCT_RETURN;
+  static void verify_perm_nmethods(CodeBlobClosure* f_or_null) PRODUCT_RETURN;
+
  public:
 
   // Initialization
@@ -61,6 +66,7 @@
   static void flush();                              // flushes all CodeBlobs
   static bool contains(void *p);                    // returns whether p is included
   static void blobs_do(void f(CodeBlob* cb));       // iterates over all CodeBlobs
+  static void blobs_do(CodeBlobClosure* f);         // iterates over all CodeBlobs
   static void nmethods_do(void f(nmethod* nm));     // iterates over all nmethods
 
   // Lookup
@@ -106,12 +112,24 @@
   static void do_unloading(BoolObjectClosure* is_alive,
                            OopClosure* keep_alive,
                            bool unloading_occurred);
-  static void oops_do(OopClosure* f);
+  static void oops_do(OopClosure* f) {
+    CodeBlobToOopClosure oopc(f, /*do_marking=*/ false);
+    blobs_do(&oopc);
+  }
+  static void asserted_non_scavengable_nmethods_do(CodeBlobClosure* f = NULL) PRODUCT_RETURN;
+  static void scavenge_root_nmethods_do(CodeBlobClosure* f);
+
+  static nmethod* scavenge_root_nmethods()          { return _scavenge_root_nmethods; }
+  static void set_scavenge_root_nmethods(nmethod* nm) { _scavenge_root_nmethods = nm; }
+  static void add_scavenge_root_nmethod(nmethod* nm);
+  static void drop_scavenge_root_nmethod(nmethod* nm);
+  static void prune_scavenge_root_nmethods();
 
   // Printing/debugging
   static void print()   PRODUCT_RETURN;          // prints summary
   static void print_internals();
   static void verify();                          // verifies the code cache
+  static void print_trace(const char* event, CodeBlob* cb, int size = 0) PRODUCT_RETURN;
 
   // The full limits of the codeCache
   static address  low_bound()                    { return (address) _heap->low_boundary(); }
--- a/hotspot/src/share/vm/code/debugInfoRec.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/code/debugInfoRec.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -299,7 +299,7 @@
   stream()->write_int(sender_stream_offset);
 
   // serialize scope
-  jobject method_enc = (method == NULL)? NULL: method->encoding();
+  jobject method_enc = (method == NULL)? NULL: method->constant_encoding();
   stream()->write_int(oop_recorder()->find_index(method_enc));
   stream()->write_bci(bci);
   assert(method == NULL ||
--- a/hotspot/src/share/vm/code/dependencies.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/code/dependencies.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -302,7 +302,7 @@
       bytes.write_byte(code_byte);
       for (int j = 0; j < stride; j++) {
         if (j == skipj)  continue;
-        bytes.write_int(_oop_recorder->find_index(deps->at(i+j)->encoding()));
+        bytes.write_int(_oop_recorder->find_index(deps->at(i+j)->constant_encoding()));
       }
     }
   }
--- a/hotspot/src/share/vm/code/nmethod.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/code/nmethod.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -581,10 +581,13 @@
     debug_only(No_Safepoint_Verifier nsv;)
     assert_locked_or_safepoint(CodeCache_lock);
 
-    NOT_PRODUCT(_has_debug_info = false; )
+    NOT_PRODUCT(_has_debug_info = false);
+    _oops_do_mark_link       = NULL;
     _method                  = method;
     _entry_bci               = InvocationEntryBci;
-    _link                    = NULL;
+    _osr_link                = NULL;
+    _scavenge_root_link      = NULL;
+    _scavenge_root_state     = 0;
     _compiler                = NULL;
     // We have no exception handler or deopt handler make the
     // values something that will never match a pc like the nmethod vtable entry
@@ -618,7 +621,7 @@
     _stack_traversal_mark    = 0;
 
     code_buffer->copy_oops_to(this);
-    debug_only(check_store();)
+    debug_only(verify_scavenge_root_oops());
     CodeCache::commit(this);
     VTune::create_nmethod(this);
   }
@@ -668,10 +671,13 @@
     debug_only(No_Safepoint_Verifier nsv;)
     assert_locked_or_safepoint(CodeCache_lock);
 
-    NOT_PRODUCT(_has_debug_info = false; )
+    NOT_PRODUCT(_has_debug_info = false);
+    _oops_do_mark_link       = NULL;
     _method                  = method;
     _entry_bci               = InvocationEntryBci;
-    _link                    = NULL;
+    _osr_link                = NULL;
+    _scavenge_root_link      = NULL;
+    _scavenge_root_state     = 0;
     _compiler                = NULL;
     // We have no exception handler or deopt handler make the
     // values something that will never match a pc like the nmethod vtable entry
@@ -703,7 +709,7 @@
     _stack_traversal_mark    = 0;
 
     code_buffer->copy_oops_to(this);
-    debug_only(check_store();)
+    debug_only(verify_scavenge_root_oops());
     CodeCache::commit(this);
     VTune::create_nmethod(this);
   }
@@ -770,12 +776,15 @@
     debug_only(No_Safepoint_Verifier nsv;)
     assert_locked_or_safepoint(CodeCache_lock);
 
-    NOT_PRODUCT(_has_debug_info = false; )
+    NOT_PRODUCT(_has_debug_info = false);
+    _oops_do_mark_link       = NULL;
     _method                  = method;
     _compile_id              = compile_id;
     _comp_level              = comp_level;
     _entry_bci               = entry_bci;
-    _link                    = NULL;
+    _osr_link                = NULL;
+    _scavenge_root_link      = NULL;
+    _scavenge_root_state     = 0;
     _compiler                = compiler;
     _orig_pc_offset          = orig_pc_offset;
 #ifdef HAVE_DTRACE_H
@@ -813,7 +822,10 @@
     code_buffer->copy_oops_to(this);
     debug_info->copy_to(this);
     dependencies->copy_to(this);
-    debug_only(check_store();)
+    if (ScavengeRootsInCode && detect_scavenge_root_oops()) {
+      CodeCache::add_scavenge_root_nmethod(this);
+    }
+    debug_only(verify_scavenge_root_oops());
 
     CodeCache::commit(this);
 
@@ -902,23 +914,30 @@
   if (st != NULL) {
     ttyLocker ttyl;
     // Print a little tag line that looks like +PrintCompilation output:
-    st->print("%3d%c  %s",
+    int tlen = (int) strlen(title);
+    bool do_nl = false;
+    if (tlen > 0 && title[tlen-1] == '\n') { tlen--; do_nl = true; }
+    st->print("%3d%c  %.*s",
               compile_id(),
               is_osr_method() ? '%' :
               method() != NULL &&
               is_native_method() ? 'n' : ' ',
-              title);
+              tlen, title);
 #ifdef TIERED
     st->print(" (%d) ", comp_level());
 #endif // TIERED
     if (WizardMode) st->print(" (" INTPTR_FORMAT ")", this);
-    if (method() != NULL) {
-      method()->print_short_name(st);
+    if (Universe::heap()->is_gc_active() && method() != NULL) {
+      st->print("(method)");
+    } else if (method() != NULL) {
+        method()->print_short_name(st);
       if (is_osr_method())
         st->print(" @ %d", osr_entry_bci());
       if (method()->code_size() > 0)
         st->print(" (%d bytes)", method()->code_size());
     }
+
+    if (do_nl)  st->cr();
   }
 }
 
@@ -1033,6 +1052,7 @@
   }
 }
 
+// This is a private interface with the sweeper.
 void nmethod::mark_as_seen_on_stack() {
   assert(is_not_entrant(), "must be a non-entrant method");
   set_stack_traversal_mark(NMethodSweeper::traversal_count());
@@ -1077,7 +1097,8 @@
                   " unloadable], methodOop(" INTPTR_FORMAT
                   "), cause(" INTPTR_FORMAT ")",
                   this, (address)_method, (address)cause);
-    cause->klass()->print();
+    if (!Universe::heap()->is_gc_active())
+      cause->klass()->print();
   }
   // Unlink the osr method, so we do not look this up again
   if (is_osr_method()) {
@@ -1109,7 +1130,8 @@
   // The methodOop is gone at this point
   assert(_method == NULL, "Tautology");
 
-  set_link(NULL);
+  set_osr_link(NULL);
+  //set_scavenge_root_link(NULL); // done by prune_scavenge_root_nmethods
   NMethodSweeper::notify(this);
 }
 
@@ -1295,6 +1317,10 @@
     ec = next;
   }
 
+  if (on_scavenge_root_list()) {
+    CodeCache::drop_scavenge_root_nmethod(this);
+  }
+
   ((CodeBlob*)(this))->flush();
 
   CodeCache::free(this);
@@ -1354,7 +1380,10 @@
       return false;
     }
   }
-  assert(unloading_occurred, "Inconsistency in unloading");
+  // If ScavengeRootsInCode is true, an nmethod might be unloaded
+  // simply because one of its constant oops has gone dead.
+  // No actual classes need to be unloaded in order for this to occur.
+  assert(unloading_occurred || ScavengeRootsInCode, "Inconsistency in unloading");
   make_unloaded(is_alive, obj);
   return true;
 }
@@ -1529,13 +1558,12 @@
 // the (strong) marking phase, and then again when walking
 // the code cache contents during the weak roots processing
 // phase. The two uses are distinguished by means of the
-// do_nmethods() method in the closure "f" below -- which
-// answers "yes" in the first case, and "no" in the second
+// 'do_strong_roots_only' flag, which is true in the first
 // case. We want to walk the weak roots in the nmethod
 // only in the second case. The weak roots in the nmethod
 // are the oops in the ExceptionCache and the InlineCache
 // oops.
-void nmethod::oops_do(OopClosure* f) {
+void nmethod::oops_do(OopClosure* f, bool do_strong_roots_only) {
   // make sure the oops ready to receive visitors
   assert(!is_zombie() && !is_unloaded(),
          "should not call follow on zombie or unloaded nmethod");
@@ -1553,7 +1581,7 @@
 
   // Compiled code
   f->do_oop((oop*) &_method);
-  if (!f->do_nmethods()) {
+  if (!do_strong_roots_only) {
     // weak roots processing phase -- update ExceptionCache oops
     ExceptionCache* ec = exception_cache();
     while(ec != NULL) {
@@ -1579,12 +1607,108 @@
   }
 
   // Scopes
+  // This includes oop constants not inlined in the code stream.
   for (oop* p = oops_begin(); p < oops_end(); p++) {
     if (*p == Universe::non_oop_word())  continue;  // skip non-oops
     f->do_oop(p);
   }
 }
 
+#define NMETHOD_SENTINEL ((nmethod*)badAddress)
+
+nmethod* volatile nmethod::_oops_do_mark_nmethods;
+
+// An nmethod is "marked" if its _mark_link is set non-null.
+// Even if it is the end of the linked list, it will have a non-null link value,
+// as long as it is on the list.
+// This code must be MP safe, because it is used from parallel GC passes.
+bool nmethod::test_set_oops_do_mark() {
+  assert(nmethod::oops_do_marking_is_active(), "oops_do_marking_prologue must be called");
+  nmethod* observed_mark_link = _oops_do_mark_link;
+  if (observed_mark_link == NULL) {
+    // Claim this nmethod for this thread to mark.
+    observed_mark_link = (nmethod*)
+      Atomic::cmpxchg_ptr(NMETHOD_SENTINEL, &_oops_do_mark_link, NULL);
+    if (observed_mark_link == NULL) {
+
+      // Atomically append this nmethod (now claimed) to the head of the list:
+      nmethod* observed_mark_nmethods = _oops_do_mark_nmethods;
+      for (;;) {
+        nmethod* required_mark_nmethods = observed_mark_nmethods;
+        _oops_do_mark_link = required_mark_nmethods;
+        observed_mark_nmethods = (nmethod*)
+          Atomic::cmpxchg_ptr(this, &_oops_do_mark_nmethods, required_mark_nmethods);
+        if (observed_mark_nmethods == required_mark_nmethods)
+          break;
+      }
+      // Mark was clear when we first saw this guy.
+      NOT_PRODUCT(if (TraceScavenge)  print_on(tty, "oops_do, mark\n"));
+      return false;
+    }
+  }
+  // On fall through, another racing thread marked this nmethod before we did.
+  return true;
+}
+
+void nmethod::oops_do_marking_prologue() {
+  NOT_PRODUCT(if (TraceScavenge)  tty->print_cr("[oops_do_marking_prologue"));
+  assert(_oops_do_mark_nmethods == NULL, "must not call oops_do_marking_prologue twice in a row");
+  // We use cmpxchg_ptr instead of regular assignment here because the user
+  // may fork a bunch of threads, and we need them all to see the same state.
+  void* observed = Atomic::cmpxchg_ptr(NMETHOD_SENTINEL, &_oops_do_mark_nmethods, NULL);
+  guarantee(observed == NULL, "no races in this sequential code");
+}
+
+void nmethod::oops_do_marking_epilogue() {
+  assert(_oops_do_mark_nmethods != NULL, "must not call oops_do_marking_epilogue twice in a row");
+  nmethod* cur = _oops_do_mark_nmethods;
+  while (cur != NMETHOD_SENTINEL) {
+    assert(cur != NULL, "not NULL-terminated");
+    nmethod* next = cur->_oops_do_mark_link;
+    cur->_oops_do_mark_link = NULL;
+    NOT_PRODUCT(if (TraceScavenge)  cur->print_on(tty, "oops_do, unmark\n"));
+    cur = next;
+  }
+  void* required = _oops_do_mark_nmethods;
+  void* observed = Atomic::cmpxchg_ptr(NULL, &_oops_do_mark_nmethods, required);
+  guarantee(observed == required, "no races in this sequential code");
+  NOT_PRODUCT(if (TraceScavenge)  tty->print_cr("oops_do_marking_epilogue]"));
+}
+
+class DetectScavengeRoot: public OopClosure {
+  bool     _detected_scavenge_root;
+public:
+  DetectScavengeRoot() : _detected_scavenge_root(false)
+  { NOT_PRODUCT(_print_nm = NULL); }
+  bool detected_scavenge_root() { return _detected_scavenge_root; }
+  virtual void do_oop(oop* p) {
+    if ((*p) != NULL && (*p)->is_scavengable()) {
+      NOT_PRODUCT(maybe_print(p));
+      _detected_scavenge_root = true;
+    }
+  }
+  virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
+
+#ifndef PRODUCT
+  nmethod* _print_nm;
+  void maybe_print(oop* p) {
+    if (_print_nm == NULL)  return;
+    if (!_detected_scavenge_root)  _print_nm->print_on(tty, "new scavenge root");
+    tty->print_cr(""PTR_FORMAT"[offset=%d] detected non-perm oop "PTR_FORMAT" (found at "PTR_FORMAT")",
+                  _print_nm, (int)((intptr_t)p - (intptr_t)_print_nm),
+                  (intptr_t)(*p), (intptr_t)p);
+    (*p)->print();
+  }
+#endif //PRODUCT
+};
+
+bool nmethod::detect_scavenge_root_oops() {
+  DetectScavengeRoot detect_scavenge_root;
+  NOT_PRODUCT(if (TraceScavenge)  detect_scavenge_root._print_nm = this);
+  oops_do(&detect_scavenge_root);
+  return detect_scavenge_root.detected_scavenge_root();
+}
+
 // Method that knows how to preserve outgoing arguments at call. This method must be
 // called with a frame corresponding to a Java invoke
 void nmethod::preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) {
@@ -1899,6 +2023,24 @@
 // -----------------------------------------------------------------------------
 // Verification
 
+class VerifyOopsClosure: public OopClosure {
+  nmethod* _nm;
+  bool     _ok;
+public:
+  VerifyOopsClosure(nmethod* nm) : _nm(nm), _ok(true) { }
+  bool ok() { return _ok; }
+  virtual void do_oop(oop* p) {
+    if ((*p) == NULL || (*p)->is_oop())  return;
+    if (_ok) {
+      _nm->print_nmethod(true);
+      _ok = false;
+    }
+    tty->print_cr("*** non-oop "PTR_FORMAT" found at "PTR_FORMAT" (offset %d)",
+                  (intptr_t)(*p), (intptr_t)p, (int)((intptr_t)p - (intptr_t)_nm));
+  }
+  virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
+};
+
 void nmethod::verify() {
 
   // Hmm. OSR methods can be deopted but not marked as zombie or not_entrant
@@ -1932,6 +2074,11 @@
     }
   }
 
+  VerifyOopsClosure voc(this);
+  oops_do(&voc);
+  assert(voc.ok(), "embedded oops must be OK");
+  verify_scavenge_root_oops();
+
   verify_scopes();
 }
 
@@ -1995,19 +2142,34 @@
 // Non-product code
 #ifndef PRODUCT
 
-void nmethod::check_store() {
-  // Make sure all oops in the compiled code are tenured
+class DebugScavengeRoot: public OopClosure {
+  nmethod* _nm;
+  bool     _ok;
+public:
+  DebugScavengeRoot(nmethod* nm) : _nm(nm), _ok(true) { }
+  bool ok() { return _ok; }
+  virtual void do_oop(oop* p) {
+    if ((*p) == NULL || !(*p)->is_scavengable())  return;
+    if (_ok) {
+      _nm->print_nmethod(true);
+      _ok = false;
+    }
+    tty->print_cr("*** non-perm oop "PTR_FORMAT" found at "PTR_FORMAT" (offset %d)",
+                  (intptr_t)(*p), (intptr_t)p, (int)((intptr_t)p - (intptr_t)_nm));
+    (*p)->print();
+  }
+  virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
+};
 
-  RelocIterator iter(this);
-  while (iter.next()) {
-    if (iter.type() == relocInfo::oop_type) {
-      oop_Relocation* reloc = iter.oop_reloc();
-      oop obj = reloc->oop_value();
-      if (obj != NULL && !obj->is_perm()) {
-        fatal("must be permanent oop in compiled code");
-      }
-    }
+void nmethod::verify_scavenge_root_oops() {
+  if (!on_scavenge_root_list()) {
+    // Actually look inside, to verify the claim that it's clean.
+    DebugScavengeRoot debug_scavenge_root(this);
+    oops_do(&debug_scavenge_root);
+    if (!debug_scavenge_root.ok())
+      fatal("found an unadvertised bad non-perm oop in the code cache");
   }
+  assert(scavenge_root_not_marked(), "");
 }
 
 #endif // PRODUCT
@@ -2040,6 +2202,7 @@
     if (is_not_entrant()) tty->print("not_entrant ");
     if (is_zombie())      tty->print("zombie ");
     if (is_unloaded())    tty->print("unloaded ");
+    if (on_scavenge_root_list())  tty->print("scavenge_root ");
     tty->print_cr("}:");
   }
   if (size              () > 0) tty->print_cr(" total in heap  [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
--- a/hotspot/src/share/vm/code/nmethod.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/code/nmethod.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -125,6 +125,7 @@
 class nmethod : public CodeBlob {
   friend class VMStructs;
   friend class NMethodSweeper;
+  friend class CodeCache;  // non-perm oops
  private:
   // Shared fields for all nmethod's
   static int _zombie_instruction_size;
@@ -132,7 +133,12 @@
   methodOop _method;
   int       _entry_bci;        // != InvocationEntryBci if this nmethod is an on-stack replacement method
 
-  nmethod*  _link;             // To support simple linked-list chaining of nmethods
+  // To support simple linked-list chaining of nmethods:
+  nmethod*  _osr_link;         // from instanceKlass::osr_nmethods_head
+  nmethod*  _scavenge_root_link; // from CodeCache::scavenge_root_nmethods
+
+  static nmethod* volatile _oops_do_mark_nmethods;
+  nmethod*        volatile _oops_do_mark_link;
 
   AbstractCompiler* _compiler; // The compiler which compiled this nmethod
 
@@ -174,6 +180,8 @@
   // used by jvmti to track if an unload event has been posted for this nmethod.
   bool _unload_reported;
 
+  jbyte _scavenge_root_state;
+
   NOT_PRODUCT(bool _has_debug_info; )
 
   // Nmethod Flushing lock (if non-zero, then the nmethod is not removed)
@@ -242,7 +250,6 @@
 
   // helper methods
   void* operator new(size_t size, int nmethod_size);
-  void check_store();
 
   const char* reloc_string_for(u_char* begin, u_char* end);
   void make_not_entrant_or_zombie(int state);
@@ -406,6 +413,24 @@
   int   version() const                           { return flags.version; }
   void  set_version(int v);
 
+  // Non-perm oop support
+  bool  on_scavenge_root_list() const                  { return (_scavenge_root_state & 1) != 0; }
+ protected:
+  enum { npl_on_list = 0x01, npl_marked = 0x10 };
+  void  set_on_scavenge_root_list()                    { _scavenge_root_state = npl_on_list; }
+  void  clear_on_scavenge_root_list()                  { _scavenge_root_state = 0; }
+  // assertion-checking and pruning logic uses the bits of _scavenge_root_state
+#ifndef PRODUCT
+  void  set_scavenge_root_marked()                     { _scavenge_root_state |= npl_marked; }
+  void  clear_scavenge_root_marked()                   { _scavenge_root_state &= ~npl_marked; }
+  bool  scavenge_root_not_marked()                     { return (_scavenge_root_state &~ npl_on_list) == 0; }
+  // N.B. there is no positive marked query, and we only use the not_marked query for asserts.
+#endif //PRODUCT
+  nmethod* scavenge_root_link() const                  { return _scavenge_root_link; }
+  void     set_scavenge_root_link(nmethod *n)          { _scavenge_root_link = n; }
+
+ public:
+
   // Sweeper support
   long  stack_traversal_mark()                    { return _stack_traversal_mark; }
   void  set_stack_traversal_mark(long l)          { _stack_traversal_mark = l; }
@@ -424,8 +449,8 @@
   int   osr_entry_bci() const                     { assert(_entry_bci != InvocationEntryBci, "wrong kind of nmethod"); return _entry_bci; }
   address  osr_entry() const                      { assert(_entry_bci != InvocationEntryBci, "wrong kind of nmethod"); return _osr_entry_point; }
   void  invalidate_osr_method();
-  nmethod* link() const                           { return _link; }
-  void     set_link(nmethod *n)                   { _link = n; }
+  nmethod* osr_link() const                       { return _osr_link; }
+  void     set_osr_link(nmethod *n)               { _osr_link = n; }
 
   // tells whether frames described by this nmethod can be deoptimized
   // note: native wrappers cannot be deoptimized.
@@ -465,7 +490,16 @@
 
   void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map,
                                      OopClosure* f);
-  void oops_do(OopClosure* f);
+  virtual void oops_do(OopClosure* f) { oops_do(f, false); }
+  void         oops_do(OopClosure* f, bool do_strong_roots_only);
+  bool detect_scavenge_root_oops();
+  void verify_scavenge_root_oops() PRODUCT_RETURN;
+
+  bool test_set_oops_do_mark();
+  static void oops_do_marking_prologue();
+  static void oops_do_marking_epilogue();
+  static bool oops_do_marking_is_active() { return _oops_do_mark_nmethods != NULL; }
+  DEBUG_ONLY(bool test_oops_do_mark() { return _oops_do_mark_link != NULL; })
 
   // ScopeDesc for an instruction
   ScopeDesc* scope_desc_at(address pc);
--- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsOopClosures.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsOopClosures.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -47,20 +47,15 @@
  private:
   const MemRegion _span;
   CMSBitMap*      _bitMap;
-  const bool      _should_do_nmethods;
  protected:
   DO_OOP_WORK_DEFN
  public:
-  MarkRefsIntoClosure(MemRegion span, CMSBitMap* bitMap,
-                      bool should_do_nmethods);
+  MarkRefsIntoClosure(MemRegion span, CMSBitMap* bitMap);
   virtual void do_oop(oop* p);
   virtual void do_oop(narrowOop* p);
   inline void do_oop_nv(oop* p)       { MarkRefsIntoClosure::do_oop_work(p); }
   inline void do_oop_nv(narrowOop* p) { MarkRefsIntoClosure::do_oop_work(p); }
   bool do_header() { return true; }
-  virtual const bool do_nmethods() const {
-    return _should_do_nmethods;
-  }
   Prefetch::style prefetch_style() {
     return Prefetch::do_read;
   }
@@ -73,20 +68,16 @@
   const MemRegion _span;
   CMSBitMap*      _verification_bm;
   CMSBitMap*      _cms_bm;
-  const bool      _should_do_nmethods;
  protected:
   DO_OOP_WORK_DEFN
  public:
   MarkRefsIntoVerifyClosure(MemRegion span, CMSBitMap* verification_bm,
-                            CMSBitMap* cms_bm, bool should_do_nmethods);
+                            CMSBitMap* cms_bm);
   virtual void do_oop(oop* p);
   virtual void do_oop(narrowOop* p);
   inline void do_oop_nv(oop* p)       { MarkRefsIntoVerifyClosure::do_oop_work(p); }
   inline void do_oop_nv(narrowOop* p) { MarkRefsIntoVerifyClosure::do_oop_work(p); }
   bool do_header() { return true; }
-  virtual const bool do_nmethods() const {
-    return _should_do_nmethods;
-  }
   Prefetch::style prefetch_style() {
     return Prefetch::do_read;
   }
@@ -228,7 +219,6 @@
   inline void do_oop_nv(oop* p)       { MarkRefsIntoAndScanClosure::do_oop_work(p); }
   inline void do_oop_nv(narrowOop* p) { MarkRefsIntoAndScanClosure::do_oop_work(p); }
   bool do_header() { return true; }
-  virtual const bool do_nmethods() const { return true; }
   Prefetch::style prefetch_style() {
     return Prefetch::do_read;
   }
@@ -273,7 +263,6 @@
   inline void do_oop_nv(oop* p)       { Par_MarkRefsIntoAndScanClosure::do_oop_work(p); }
   inline void do_oop_nv(narrowOop* p) { Par_MarkRefsIntoAndScanClosure::do_oop_work(p); }
   bool do_header() { return true; }
-  virtual const bool do_nmethods() const { return true; }
   // When ScanMarkedObjectsAgainClosure is used,
   // it passes [Par_]MarkRefsIntoAndScanClosure to oop_oop_iterate(),
   // and this delegation is used.
--- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -2852,14 +2852,17 @@
   GenCollectedHeap* gch = GenCollectedHeap::heap();
 
   // Mark from roots one level into CMS
-  MarkRefsIntoClosure notOlder(_span, verification_mark_bm(), true /* nmethods */);
+  MarkRefsIntoClosure notOlder(_span, verification_mark_bm());
   gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
 
   gch->gen_process_strong_roots(_cmsGen->level(),
                                 true,   // younger gens are roots
+                                true,   // activate StrongRootsScope
                                 true,   // collecting perm gen
                                 SharedHeap::ScanningOption(roots_scanning_options()),
-                                NULL, &notOlder);
+                                &notOlder,
+                                true,   // walk code active on stacks
+                                NULL);
 
   // Now mark from the roots
   assert(_revisitStack.isEmpty(), "Should be empty");
@@ -2901,13 +2904,16 @@
 
   // Mark from roots one level into CMS
   MarkRefsIntoVerifyClosure notOlder(_span, verification_mark_bm(),
-                                     markBitMap(), true /* nmethods */);
+                                     markBitMap());
   gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
   gch->gen_process_strong_roots(_cmsGen->level(),
                                 true,   // younger gens are roots
+                                true,   // activate StrongRootsScope
                                 true,   // collecting perm gen
                                 SharedHeap::ScanningOption(roots_scanning_options()),
-                                NULL, &notOlder);
+                                &notOlder,
+                                true,   // walk code active on stacks
+                                NULL);
 
   // Now mark from the roots
   assert(_revisitStack.isEmpty(), "Should be empty");
@@ -3484,8 +3490,10 @@
   FalseClosure falseClosure;
   // In the case of a synchronous collection, we will elide the
   // remark step, so it's important to catch all the nmethod oops
-  // in this step; hence the last argument to the constrcutor below.
-  MarkRefsIntoClosure notOlder(_span, &_markBitMap, !asynch /* nmethods */);
+  // in this step.
+  // The final 'true' flag to gen_process_strong_roots will ensure this.
+  // If 'async' is true, we can relax the nmethod tracing.
+  MarkRefsIntoClosure notOlder(_span, &_markBitMap);
   GenCollectedHeap* gch = GenCollectedHeap::heap();
 
   verify_work_stacks_empty();
@@ -3504,9 +3512,12 @@
     gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
     gch->gen_process_strong_roots(_cmsGen->level(),
                                   true,   // younger gens are roots
+                                  true,   // activate StrongRootsScope
                                   true,   // collecting perm gen
                                   SharedHeap::ScanningOption(roots_scanning_options()),
-                                  NULL, &notOlder);
+                                  &notOlder,
+                                  true,   // walk all of code cache if (so & SO_CodeCache)
+                                  NULL);
   }
 
   // Clear mod-union table; it will be dirtied in the prologue of
@@ -5040,9 +5051,15 @@
   _timer.start();
   gch->gen_process_strong_roots(_collector->_cmsGen->level(),
                                 false,     // yg was scanned above
+                                false,     // this is parallel code
                                 true,      // collecting perm gen
                                 SharedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()),
-                                NULL, &par_mrias_cl);
+                                &par_mrias_cl,
+                                true,   // walk all of code cache if (so & SO_CodeCache)
+                                NULL);
+  assert(_collector->should_unload_classes()
+         || (_collector->CMSCollector::roots_scanning_options() & SharedHeap::SO_CodeCache),
+         "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops");
   _timer.stop();
   if (PrintCMSStatistics != 0) {
     gclog_or_tty->print_cr(
@@ -5423,7 +5440,6 @@
 
   // Set up for parallel process_strong_roots work.
   gch->set_par_threads(n_workers);
-  gch->change_strong_roots_parity();
   // We won't be iterating over the cards in the card table updating
   // the younger_gen cards, so we shouldn't call the following else
   // the verification code as well as subsequent younger_refs_iterate
@@ -5454,8 +5470,10 @@
   if (n_workers > 1) {
     // Make refs discovery MT-safe
     ReferenceProcessorMTMutator mt(ref_processor(), true);
+    GenCollectedHeap::StrongRootsScope srs(gch);
     workers->run_task(&tsk);
   } else {
+    GenCollectedHeap::StrongRootsScope srs(gch);
     tsk.work(0);
   }
   gch->set_par_threads(0);  // 0 ==> non-parallel.
@@ -5539,11 +5557,18 @@
     verify_work_stacks_empty();
 
     gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
+    GenCollectedHeap::StrongRootsScope srs(gch);
     gch->gen_process_strong_roots(_cmsGen->level(),
                                   true,  // younger gens as roots
+                                  false, // use the local StrongRootsScope
                                   true,  // collecting perm gen
                                   SharedHeap::ScanningOption(roots_scanning_options()),
-                                  NULL, &mrias_cl);
+                                  &mrias_cl,
+                                  true,   // walk code active on stacks
+                                  NULL);
+    assert(should_unload_classes()
+           || (roots_scanning_options() & SharedHeap::SO_CodeCache),
+           "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops");
   }
   verify_work_stacks_empty();
   // Restore evacuated mark words, if any, used for overflow list links
@@ -6418,10 +6443,9 @@
 // generation then this will lose younger_gen cards!
 
 MarkRefsIntoClosure::MarkRefsIntoClosure(
-  MemRegion span, CMSBitMap* bitMap, bool should_do_nmethods):
+  MemRegion span, CMSBitMap* bitMap):
     _span(span),
-    _bitMap(bitMap),
-    _should_do_nmethods(should_do_nmethods)
+    _bitMap(bitMap)
 {
     assert(_ref_processor == NULL, "deliberately left NULL");
     assert(_bitMap->covers(_span), "_bitMap/_span mismatch");
@@ -6442,12 +6466,11 @@
 
 // A variant of the above, used for CMS marking verification.
 MarkRefsIntoVerifyClosure::MarkRefsIntoVerifyClosure(
-  MemRegion span, CMSBitMap* verification_bm, CMSBitMap* cms_bm,
-  bool should_do_nmethods):
+  MemRegion span, CMSBitMap* verification_bm, CMSBitMap* cms_bm):
     _span(span),
     _verification_bm(verification_bm),
-    _cms_bm(cms_bm),
-    _should_do_nmethods(should_do_nmethods) {
+    _cms_bm(cms_bm)
+{
     assert(_ref_processor == NULL, "deliberately left NULL");
     assert(_verification_bm->covers(_span), "_verification_bm/_span mismatch");
 }
--- a/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -746,10 +746,11 @@
   // clear the mark bitmap (no grey objects to start with)
   _nextMarkBitMap->clearAll();
   PrintReachableClosure prcl(_nextMarkBitMap);
-  g1h->process_strong_roots(
+  g1h->process_strong_roots(true,    // activate StrongRootsScope
                             false,   // fake perm gen collection
                             SharedHeap::SO_AllClasses,
                             &prcl, // Regular roots
+                            NULL,  // do not visit active blobs
                             &prcl    // Perm Gen Roots
                             );
   // The root iteration above "consumed" dirty cards in the perm gen.
@@ -852,9 +853,11 @@
   g1h->set_marking_started();
   g1h->rem_set()->prepare_for_younger_refs_iterate(false);
 
-  g1h->process_strong_roots(false,   // fake perm gen collection
+  g1h->process_strong_roots(true,    // activate StrongRootsScope
+                            false,   // fake perm gen collection
                             SharedHeap::SO_AllClasses,
                             &notOlder, // Regular roots
+                            NULL,     // do not visit active blobs
                             &older    // Perm Gen Roots
                             );
   checkpointRootsInitialPost();
@@ -1915,7 +1918,7 @@
   g1h->ensure_parsability(false);
 
   if (ParallelGCThreads > 0) {
-    g1h->change_strong_roots_parity();
+    G1CollectedHeap::StrongRootsScope srs(g1h);
     // this is remark, so we'll use up all available threads
     int active_workers = ParallelGCThreads;
     set_phase(active_workers, false);
@@ -1932,7 +1935,7 @@
     SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set();
     guarantee( satb_mq_set.completed_buffers_num() == 0, "invariant" );
   } else {
-    g1h->change_strong_roots_parity();
+    G1CollectedHeap::StrongRootsScope srs(g1h);
     // this is remark, so we'll use up all available threads
     int active_workers = 1;
     set_phase(active_workers, false);
--- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -2300,9 +2300,12 @@
   if (SafepointSynchronize::is_at_safepoint() || ! UseTLAB) {
     if (!silent) { gclog_or_tty->print("roots "); }
     VerifyRootsClosure rootsCl(use_prev_marking);
-    process_strong_roots(false,
+    CodeBlobToOopClosure blobsCl(&rootsCl, /*do_marking=*/ false);
+    process_strong_roots(true,  // activate StrongRootsScope
+                         false,
                          SharedHeap::SO_AllClasses,
                          &rootsCl,
+                         &blobsCl,
                          &rootsCl);
     rem_set()->invalidate(perm_gen()->used_region(), false);
     if (!silent) { gclog_or_tty->print("heapRegions "); }
@@ -3987,8 +3990,14 @@
   BufferingOopsInGenClosure buf_scan_perm(scan_perm);
   buf_scan_perm.set_generation(perm_gen());
 
-  process_strong_roots(collecting_perm_gen, so,
+  // Walk the code cache w/o buffering, because StarTask cannot handle
+  // unaligned oop locations.
+  CodeBlobToOopClosure eager_scan_code_roots(scan_non_heap_roots, /*do_marking=*/ true);
+
+  process_strong_roots(false, // no scoping; this is parallel code
+                       collecting_perm_gen, so,
                        &buf_scan_non_heap_roots,
+                       &eager_scan_code_roots,
                        &buf_scan_perm);
   // Finish up any enqueued closure apps.
   buf_scan_non_heap_roots.done();
@@ -4078,7 +4087,8 @@
 void
 G1CollectedHeap::g1_process_weak_roots(OopClosure* root_closure,
                                        OopClosure* non_root_closure) {
-  SharedHeap::process_weak_roots(root_closure, non_root_closure);
+  CodeBlobToOopClosure roots_in_blobs(root_closure, /*do_marking=*/ false);
+  SharedHeap::process_weak_roots(root_closure, &roots_in_blobs, non_root_closure);
 }
 
 
@@ -4112,15 +4122,16 @@
 
   init_for_evac_failure(NULL);
 
-  change_strong_roots_parity();  // In preparation for parallel strong roots.
   rem_set()->prepare_for_younger_refs_iterate(true);
 
   assert(dirty_card_queue_set().completed_buffers_num() == 0, "Should be empty");
   double start_par = os::elapsedTime();
   if (ParallelGCThreads > 0) {
     // The individual threads will set their evac-failure closures.
+    StrongRootsScope srs(this);
     workers()->run_task(&g1_par_task);
   } else {
+    StrongRootsScope srs(this);
     g1_par_task.work(0);
   }
 
--- a/hotspot/src/share/vm/gc_implementation/g1/g1MarkSweep.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/gc_implementation/g1/g1MarkSweep.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -121,9 +121,11 @@
 
   SharedHeap* sh = SharedHeap::heap();
 
-  sh->process_strong_roots(true,  // Collecting permanent generation.
+  sh->process_strong_roots(true,  // activeate StrongRootsScope
+                           true,  // Collecting permanent generation.
                            SharedHeap::SO_SystemClasses,
                            &GenMarkSweep::follow_root_closure,
+                           &GenMarkSweep::follow_code_root_closure,
                            &GenMarkSweep::follow_root_closure);
 
   // Process reference objects found during marking
@@ -286,9 +288,11 @@
 
   SharedHeap* sh = SharedHeap::heap();
 
-  sh->process_strong_roots(true,  // Collecting permanent generation.
+  sh->process_strong_roots(true,  // activate StrongRootsScope
+                           true,  // Collecting permanent generation.
                            SharedHeap::SO_AllClasses,
                            &GenMarkSweep::adjust_root_pointer_closure,
+                           NULL,  // do not touch code cache here
                            &GenMarkSweep::adjust_pointer_closure);
 
   g1h->ref_processor()->weak_oops_do(&GenMarkSweep::adjust_root_pointer_closure);
--- a/hotspot/src/share/vm/gc_implementation/includeDB_gc_parallelScavenge	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/gc_implementation/includeDB_gc_parallelScavenge	Fri Oct 16 18:02:31 2009 -0700
@@ -373,6 +373,7 @@
 psScavenge.inline.hpp                   psPromotionManager.hpp
 psScavenge.inline.hpp                   psScavenge.hpp
 
+pcTasks.cpp                             codeCache.hpp
 pcTasks.cpp                             collectedHeap.hpp
 pcTasks.cpp                             fprofiler.hpp
 pcTasks.cpp                             jniHandles.hpp
@@ -392,6 +393,7 @@
 pcTasks.hpp				psTasks.hpp
 
 psTasks.cpp                             cardTableExtension.hpp
+psTasks.cpp                             codeCache.hpp
 psTasks.cpp                             fprofiler.hpp
 psTasks.cpp                             gcTaskManager.hpp
 psTasks.cpp                             iterator.hpp
--- a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -480,12 +480,14 @@
 
   par_scan_state.start_strong_roots();
   gch->gen_process_strong_roots(_gen->level(),
-                                true, // Process younger gens, if any,
-                                      // as strong roots.
-                                false,// not collecting perm generation.
+                                true,  // Process younger gens, if any,
+                                       // as strong roots.
+                                false, // no scope; this is parallel code
+                                false, // not collecting perm generation.
                                 SharedHeap::SO_AllClasses,
-                                &par_scan_state.older_gen_closure(),
-                                &par_scan_state.to_space_root_closure());
+                                &par_scan_state.to_space_root_closure(),
+                                true,   // walk *all* scavengable nmethods
+                                &par_scan_state.older_gen_closure());
   par_scan_state.end_strong_roots();
 
   // "evacuate followers".
@@ -799,15 +801,16 @@
   ParNewGenTask tsk(this, _next_gen, reserved().end(), &thread_state_set);
   int n_workers = workers->total_workers();
   gch->set_par_threads(n_workers);
-  gch->change_strong_roots_parity();
   gch->rem_set()->prepare_for_younger_refs_iterate(true);
   // It turns out that even when we're using 1 thread, doing the work in a
   // separate thread causes wide variance in run times.  We can't help this
   // in the multi-threaded case, but we special-case n=1 here to get
   // repeatable measurements of the 1-thread overhead of the parallel code.
   if (n_workers > 1) {
+    GenCollectedHeap::StrongRootsScope srs(gch);
     workers->run_task(&tsk);
   } else {
+    GenCollectedHeap::StrongRootsScope srs(gch);
     tsk.work(0);
   }
   thread_state_set.reset();
--- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -962,6 +962,14 @@
   _old_gen->resize(desired_free_space);
 }
 
+ParallelScavengeHeap::ParStrongRootsScope::ParStrongRootsScope() {
+  // nothing particular
+}
+
+ParallelScavengeHeap::ParStrongRootsScope::~ParStrongRootsScope() {
+  // nothing particular
+}
+
 #ifndef PRODUCT
 void ParallelScavengeHeap::record_gen_tops_before_GC() {
   if (ZapUnusedHeapArea) {
--- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -234,6 +234,13 @@
 
   // Mangle the unused parts of all spaces in the heap
   void gen_mangle_unused_area() PRODUCT_RETURN;
+
+  // Call these in sequential code around the processing of strong roots.
+  class ParStrongRootsScope : public MarkingCodeBlobClosure::MarkScope {
+  public:
+    ParStrongRootsScope();
+    ~ParStrongRootsScope();
+  };
 };
 
 inline size_t ParallelScavengeHeap::set_alignment(size_t& var, size_t val)
--- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/pcTasks.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/pcTasks.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -39,12 +39,13 @@
   ParCompactionManager* cm =
     ParCompactionManager::gc_thread_compaction_manager(which);
   PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm);
+  CodeBlobToOopClosure mark_and_push_in_blobs(&mark_and_push_closure, /*do_marking=*/ true);
 
   if (_java_thread != NULL)
-    _java_thread->oops_do(&mark_and_push_closure);
+    _java_thread->oops_do(&mark_and_push_closure, &mark_and_push_in_blobs);
 
   if (_vm_thread != NULL)
-    _vm_thread->oops_do(&mark_and_push_closure);
+    _vm_thread->oops_do(&mark_and_push_closure, &mark_and_push_in_blobs);
 
   // Do the real work
   cm->drain_marking_stacks(&mark_and_push_closure);
@@ -78,7 +79,8 @@
     case threads:
     {
       ResourceMark rm;
-      Threads::oops_do(&mark_and_push_closure);
+      CodeBlobToOopClosure each_active_code_blob(&mark_and_push_closure, /*do_marking=*/ true);
+      Threads::oops_do(&mark_and_push_closure, &each_active_code_blob);
     }
     break;
 
@@ -106,6 +108,11 @@
       vmSymbols::oops_do(&mark_and_push_closure);
       break;
 
+    case code_cache:
+      // Do not treat nmethods as strong roots for mark/sweep, since we can unload them.
+      //CodeCache::scavenge_root_nmethods_do(CodeBlobToOopClosure(&mark_and_push_closure));
+      break;
+
     default:
       fatal("Unknown root type");
   }
--- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/pcTasks.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/pcTasks.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -92,7 +92,8 @@
     jvmti                 = 7,
     system_dictionary     = 8,
     vm_symbols            = 9,
-    reference_processing  = 10
+    reference_processing  = 10,
+    code_cache            = 11
   };
  private:
   RootType _root_type;
--- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psMarkSweep.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psMarkSweep.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -511,16 +511,22 @@
   assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
 
   // General strong roots.
-  Universe::oops_do(mark_and_push_closure());
-  ReferenceProcessor::oops_do(mark_and_push_closure());
-  JNIHandles::oops_do(mark_and_push_closure());   // Global (strong) JNI handles
-  Threads::oops_do(mark_and_push_closure());
-  ObjectSynchronizer::oops_do(mark_and_push_closure());
-  FlatProfiler::oops_do(mark_and_push_closure());
-  Management::oops_do(mark_and_push_closure());
-  JvmtiExport::oops_do(mark_and_push_closure());
-  SystemDictionary::always_strong_oops_do(mark_and_push_closure());
-  vmSymbols::oops_do(mark_and_push_closure());
+  {
+    ParallelScavengeHeap::ParStrongRootsScope psrs;
+    Universe::oops_do(mark_and_push_closure());
+    ReferenceProcessor::oops_do(mark_and_push_closure());
+    JNIHandles::oops_do(mark_and_push_closure());   // Global (strong) JNI handles
+    CodeBlobToOopClosure each_active_code_blob(mark_and_push_closure(), /*do_marking=*/ true);
+    Threads::oops_do(mark_and_push_closure(), &each_active_code_blob);
+    ObjectSynchronizer::oops_do(mark_and_push_closure());
+    FlatProfiler::oops_do(mark_and_push_closure());
+    Management::oops_do(mark_and_push_closure());
+    JvmtiExport::oops_do(mark_and_push_closure());
+    SystemDictionary::always_strong_oops_do(mark_and_push_closure());
+    vmSymbols::oops_do(mark_and_push_closure());
+    // Do not treat nmethods as strong roots for mark/sweep, since we can unload them.
+    //CodeCache::scavenge_root_nmethods_do(CodeBlobToOopClosure(mark_and_push_closure()));
+  }
 
   // Flush marking stack.
   follow_stack();
@@ -617,7 +623,7 @@
   Universe::oops_do(adjust_root_pointer_closure());
   ReferenceProcessor::oops_do(adjust_root_pointer_closure());
   JNIHandles::oops_do(adjust_root_pointer_closure());   // Global (strong) JNI handles
-  Threads::oops_do(adjust_root_pointer_closure());
+  Threads::oops_do(adjust_root_pointer_closure(), NULL);
   ObjectSynchronizer::oops_do(adjust_root_pointer_closure());
   FlatProfiler::oops_do(adjust_root_pointer_closure());
   Management::oops_do(adjust_root_pointer_closure());
@@ -625,6 +631,7 @@
   // SO_AllClasses
   SystemDictionary::oops_do(adjust_root_pointer_closure());
   vmSymbols::oops_do(adjust_root_pointer_closure());
+  //CodeCache::scavenge_root_nmethods_oops_do(adjust_root_pointer_closure());
 
   // Now adjust pointers in remaining weak roots.  (All of which should
   // have been cleared if they pointed to non-surviving objects.)
--- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -2322,6 +2322,7 @@
 
   {
     TraceTime tm_m("par mark", print_phases(), true, gclog_or_tty);
+    ParallelScavengeHeap::ParStrongRootsScope psrs;
 
     GCTaskQueue* q = GCTaskQueue::create();
 
@@ -2335,6 +2336,7 @@
     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::system_dictionary));
     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::jvmti));
     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::vm_symbols));
+    q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::code_cache));
 
     if (parallel_gc_threads > 1) {
       for (uint j = 0; j < parallel_gc_threads; j++) {
@@ -2408,7 +2410,7 @@
   Universe::oops_do(adjust_root_pointer_closure());
   ReferenceProcessor::oops_do(adjust_root_pointer_closure());
   JNIHandles::oops_do(adjust_root_pointer_closure());   // Global (strong) JNI handles
-  Threads::oops_do(adjust_root_pointer_closure());
+  Threads::oops_do(adjust_root_pointer_closure(), NULL);
   ObjectSynchronizer::oops_do(adjust_root_pointer_closure());
   FlatProfiler::oops_do(adjust_root_pointer_closure());
   Management::oops_do(adjust_root_pointer_closure());
--- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -799,8 +799,7 @@
     FollowRootClosure(ParCompactionManager* cm) : _compaction_manager(cm) { }
     virtual void do_oop(oop* p);
     virtual void do_oop(narrowOop* p);
-    virtual const bool do_nmethods() const { return true; }
-  };
+ };
 
   class FollowStackClosure: public VoidClosure {
    private:
@@ -817,6 +816,8 @@
     AdjustPointerClosure(bool is_root) : _is_root(is_root) { }
     virtual void do_oop(oop* p);
     virtual void do_oop(narrowOop* p);
+    // do not walk from thread stacks to the code cache on this phase
+    virtual void do_code_blob(CodeBlob* cb) const { }
   };
 
   // Closure for verifying update of pointers.  Does not
@@ -1063,7 +1064,6 @@
     MarkAndPushClosure(ParCompactionManager* cm) : _compaction_manager(cm) { }
     virtual void do_oop(oop* p);
     virtual void do_oop(narrowOop* p);
-    virtual const bool do_nmethods() const { return true; }
   };
 
   PSParallelCompact();
--- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -358,6 +358,7 @@
     PSPromotionManager* promotion_manager = PSPromotionManager::vm_thread_promotion_manager();
     {
       // TraceTime("Roots");
+      ParallelScavengeHeap::ParStrongRootsScope psrs;
 
       GCTaskQueue* q = GCTaskQueue::create();
 
@@ -376,6 +377,7 @@
       q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::management));
       q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::system_dictionary));
       q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::jvmti));
+      q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::code_cache));
 
       ParallelTaskTerminator terminator(
         gc_task_manager()->workers(),
--- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psTasks.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psTasks.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -66,7 +66,7 @@
     case threads:
     {
       ResourceMark rm;
-      Threads::oops_do(&roots_closure);
+      Threads::oops_do(&roots_closure, NULL);
     }
     break;
 
@@ -90,6 +90,14 @@
       JvmtiExport::oops_do(&roots_closure);
       break;
 
+
+    case code_cache:
+      {
+        CodeBlobToOopClosure each_scavengable_code_blob(&roots_closure, /*do_marking=*/ true);
+        CodeCache::scavenge_root_nmethods_do(&each_scavengable_code_blob);
+      }
+      break;
+
     default:
       fatal("Unknown root type");
   }
@@ -107,12 +115,13 @@
 
   PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which);
   PSScavengeRootsClosure roots_closure(pm);
+  CodeBlobToOopClosure roots_in_blobs(&roots_closure, /*do_marking=*/ true);
 
   if (_java_thread != NULL)
-    _java_thread->oops_do(&roots_closure);
+    _java_thread->oops_do(&roots_closure, &roots_in_blobs);
 
   if (_vm_thread != NULL)
-    _vm_thread->oops_do(&roots_closure);
+    _vm_thread->oops_do(&roots_closure, &roots_in_blobs);
 
   // Do the real work
   pm->drain_stacks(false);
--- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psTasks.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psTasks.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -54,7 +54,8 @@
     flat_profiler         = 5,
     system_dictionary     = 6,
     management            = 7,
-    jvmti                 = 8
+    jvmti                 = 8,
+    code_cache            = 9
   };
  private:
   RootType _root_type;
--- a/hotspot/src/share/vm/gc_implementation/shared/markSweep.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/gc_implementation/shared/markSweep.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -93,6 +93,7 @@
 }
 
 MarkSweep::FollowRootClosure  MarkSweep::follow_root_closure;
+CodeBlobToOopClosure MarkSweep::follow_code_root_closure(&MarkSweep::follow_root_closure, /*do_marking=*/ true);
 
 void MarkSweep::FollowRootClosure::do_oop(oop* p)       { follow_root(p); }
 void MarkSweep::FollowRootClosure::do_oop(narrowOop* p) { follow_root(p); }
--- a/hotspot/src/share/vm/gc_implementation/shared/markSweep.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/gc_implementation/shared/markSweep.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -58,14 +58,12 @@
    public:
     virtual void do_oop(oop* p);
     virtual void do_oop(narrowOop* p);
-    virtual const bool do_nmethods() const { return true; }
   };
 
   class MarkAndPushClosure: public OopClosure {
    public:
     virtual void do_oop(oop* p);
     virtual void do_oop(narrowOop* p);
-    virtual const bool do_nmethods() const { return true; }
     virtual const bool should_remember_mdo() const { return true; }
     virtual void remember_mdo(DataLayout* p) { MarkSweep::revisit_mdo(p); }
   };
@@ -173,6 +171,7 @@
  public:
   // Public closures
   static FollowRootClosure    follow_root_closure;
+  static CodeBlobToOopClosure follow_code_root_closure; // => follow_root_closure
   static MarkAndPushClosure   mark_and_push_closure;
   static FollowStackClosure   follow_stack_closure;
   static AdjustPointerClosure adjust_root_pointer_closure;
--- a/hotspot/src/share/vm/gc_interface/collectedHeap.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/gc_interface/collectedHeap.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -263,6 +263,14 @@
     return p == NULL || is_permanent(p);
   }
 
+  // An object is scavengable if its location may move during a scavenge.
+  // (A scavenge is a GC which is not a full GC.)
+  // Currently, this just means it is not perm (and not null).
+  // This could change if we rethink what's in perm-gen.
+  bool is_scavengable(const void *p) const {
+    return !is_in_permanent_or_null(p);
+  }
+
   // Returns "TRUE" if "p" is a method oop in the
   // current heap, with high probability. This predicate
   // is not stable, in general.
--- a/hotspot/src/share/vm/memory/defNewGeneration.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/memory/defNewGeneration.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -555,12 +555,14 @@
          "save marks have not been newly set.");
 
   gch->gen_process_strong_roots(_level,
-                                true, // Process younger gens, if any, as
-                                      // strong roots.
-                                false,// not collecting permanent generation.
+                                true,  // Process younger gens, if any,
+                                       // as strong roots.
+                                true,  // activate StrongRootsScope
+                                false, // not collecting perm generation.
                                 SharedHeap::SO_AllClasses,
-                                &fsc_with_gc_barrier,
-                                &fsc_with_no_gc_barrier);
+                                &fsc_with_no_gc_barrier,
+                                true,   // walk *all* scavengable nmethods
+                                &fsc_with_gc_barrier);
 
   // "evacuate followers".
   evacuate_followers.do_void();
--- a/hotspot/src/share/vm/memory/genCollectedHeap.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/memory/genCollectedHeap.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -677,13 +677,23 @@
 void GenCollectedHeap::
 gen_process_strong_roots(int level,
                          bool younger_gens_as_roots,
+                         bool activate_scope,
                          bool collecting_perm_gen,
                          SharedHeap::ScanningOption so,
-                         OopsInGenClosure* older_gens,
-                         OopsInGenClosure* not_older_gens) {
+                         OopsInGenClosure* not_older_gens,
+                         bool do_code_roots,
+                         OopsInGenClosure* older_gens) {
   // General strong roots.
-  SharedHeap::process_strong_roots(collecting_perm_gen, so,
-                                   not_older_gens, older_gens);
+
+  if (!do_code_roots) {
+    SharedHeap::process_strong_roots(activate_scope, collecting_perm_gen, so,
+                                     not_older_gens, NULL, older_gens);
+  } else {
+    bool do_code_marking = (activate_scope || nmethod::oops_do_marking_is_active());
+    CodeBlobToOopClosure code_roots(not_older_gens, /*do_marking=*/ do_code_marking);
+    SharedHeap::process_strong_roots(activate_scope, collecting_perm_gen, so,
+                                     not_older_gens, &code_roots, older_gens);
+  }
 
   if (younger_gens_as_roots) {
     if (!_gen_process_strong_tasks->is_task_claimed(GCH_PS_younger_gens)) {
@@ -706,8 +716,9 @@
 }
 
 void GenCollectedHeap::gen_process_weak_roots(OopClosure* root_closure,
+                                              CodeBlobClosure* code_roots,
                                               OopClosure* non_root_closure) {
-  SharedHeap::process_weak_roots(root_closure, non_root_closure);
+  SharedHeap::process_weak_roots(root_closure, code_roots, non_root_closure);
   // "Local" "weak" refs
   for (int i = 0; i < _n_gens; i++) {
     _gens[i]->ref_processor()->weak_oops_do(root_closure);
--- a/hotspot/src/share/vm/memory/genCollectedHeap.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/memory/genCollectedHeap.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -408,16 +408,22 @@
   // "SO_SystemClasses" to all the "system" classes and loaders;
   // "SO_Symbols_and_Strings" applies the closure to all entries in
   // SymbolsTable and StringTable.
-  void gen_process_strong_roots(int level, bool younger_gens_as_roots,
+  void gen_process_strong_roots(int level,
+                                bool younger_gens_as_roots,
+                                // The remaining arguments are in an order
+                                // consistent with SharedHeap::process_strong_roots:
+                                bool activate_scope,
                                 bool collecting_perm_gen,
                                 SharedHeap::ScanningOption so,
-                                OopsInGenClosure* older_gens,
-                                OopsInGenClosure* not_older_gens);
+                                OopsInGenClosure* not_older_gens,
+                                bool do_code_roots,
+                                OopsInGenClosure* older_gens);
 
   // Apply "blk" to all the weak roots of the system.  These include
   // JNI weak roots, the code cache, system dictionary, symbol table,
   // string table, and referents of reachable weak refs.
   void gen_process_weak_roots(OopClosure* root_closure,
+                              CodeBlobClosure* code_roots,
                               OopClosure* non_root_closure);
 
   // Set the saved marks of generations, if that makes sense.
--- a/hotspot/src/share/vm/memory/genMarkSweep.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/memory/genMarkSweep.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -244,9 +244,12 @@
 
   gch->gen_process_strong_roots(level,
                                 false, // Younger gens are not roots.
+                                true,  // activate StrongRootsScope
                                 true,  // Collecting permanent generation.
                                 SharedHeap::SO_SystemClasses,
-                                &follow_root_closure, &follow_root_closure);
+                                &follow_root_closure,
+                                true,   // walk code active on stacks
+                                &follow_root_closure);
 
   // Process reference objects found during marking
   {
@@ -338,14 +341,19 @@
 
   gch->gen_process_strong_roots(level,
                                 false, // Younger gens are not roots.
+                                true,  // activate StrongRootsScope
                                 true,  // Collecting permanent generation.
                                 SharedHeap::SO_AllClasses,
                                 &adjust_root_pointer_closure,
+                                false, // do not walk code
                                 &adjust_root_pointer_closure);
 
   // Now adjust pointers in remaining weak roots.  (All of which should
   // have been cleared if they pointed to non-surviving objects.)
+  CodeBlobToOopClosure adjust_code_pointer_closure(&adjust_pointer_closure,
+                                                   /*do_marking=*/ false);
   gch->gen_process_weak_roots(&adjust_root_pointer_closure,
+                              &adjust_code_pointer_closure,
                               &adjust_pointer_closure);
 
   adjust_marks();
--- a/hotspot/src/share/vm/memory/iterator.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/memory/iterator.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -46,3 +46,42 @@
 }
 #endif
 
+
+MarkingCodeBlobClosure::MarkScope::MarkScope(bool activate)
+  : _active(activate)
+{
+  if (_active)  nmethod::oops_do_marking_prologue();
+}
+
+MarkingCodeBlobClosure::MarkScope::~MarkScope() {
+  if (_active)  nmethod::oops_do_marking_epilogue();
+}
+
+void MarkingCodeBlobClosure::do_code_blob(CodeBlob* cb) {
+  if (!cb->is_nmethod())  return;
+  nmethod* nm = (nmethod*) cb;
+  if (!nm->test_set_oops_do_mark()) {
+    NOT_PRODUCT(if (TraceScavenge)  nm->print_on(tty, "oops_do, 1st visit\n"));
+    do_newly_marked_nmethod(nm);
+  } else {
+    NOT_PRODUCT(if (TraceScavenge)  nm->print_on(tty, "oops_do, skipped on 2nd visit\n"));
+  }
+}
+
+void CodeBlobToOopClosure::do_newly_marked_nmethod(nmethod* nm) {
+  nm->oops_do(_cl, /*do_strong_roots_only=*/ true);
+}
+
+void CodeBlobToOopClosure::do_code_blob(CodeBlob* cb) {
+  if (!_do_marking) {
+    NOT_PRODUCT(if (TraceScavenge && Verbose && cb->is_nmethod())  ((nmethod*)cb)->print_on(tty, "oops_do, unmarked visit\n"));
+    // This assert won't work, since there are lots of mini-passes
+    // (mostly in debug mode) that co-exist with marking phases.
+    //assert(!(cb->is_nmethod() && ((nmethod*)cb)->test_oops_do_mark()), "found marked nmethod during mark-free phase");
+    cb->oops_do(_cl);
+  } else {
+    MarkingCodeBlobClosure::do_code_blob(cb);
+  }
+}
+
+
--- a/hotspot/src/share/vm/memory/iterator.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/memory/iterator.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -24,6 +24,8 @@
 
 // The following classes are C++ `closures` for iterating over objects, roots and spaces
 
+class CodeBlob;
+class nmethod;
 class ReferenceProcessor;
 class DataLayout;
 
@@ -69,9 +71,6 @@
   virtual const bool should_remember_mdo() const { return false; }
   virtual void remember_mdo(DataLayout* v) { /* do nothing */ }
 
-  // If "true", invoke on nmethods (when scanning compiled frames).
-  virtual const bool do_nmethods() const { return false; }
-
   // The methods below control how object iterations invoking this closure
   // should be performed:
 
@@ -176,6 +175,51 @@
 };
 
 
+// CodeBlobClosure is used for iterating through code blobs
+// in the code cache or on thread stacks
+
+class CodeBlobClosure : public Closure {
+ public:
+  // Called for each code blob.
+  virtual void do_code_blob(CodeBlob* cb) = 0;
+};
+
+
+class MarkingCodeBlobClosure : public CodeBlobClosure {
+ public:
+  // Called for each code blob, but at most once per unique blob.
+  virtual void do_newly_marked_nmethod(nmethod* nm) = 0;
+
+  virtual void do_code_blob(CodeBlob* cb);
+    // = { if (!nmethod(cb)->test_set_oops_do_mark())  do_newly_marked_nmethod(cb); }
+
+  class MarkScope : public StackObj {
+  protected:
+    bool _active;
+  public:
+    MarkScope(bool activate = true);
+      // = { if (active) nmethod::oops_do_marking_prologue(); }
+    ~MarkScope();
+      // = { if (active) nmethod::oops_do_marking_epilogue(); }
+  };
+};
+
+
+// Applies an oop closure to all ref fields in code blobs
+// iterated over in an object iteration.
+class CodeBlobToOopClosure: public MarkingCodeBlobClosure {
+  OopClosure* _cl;
+  bool _do_marking;
+public:
+  virtual void do_newly_marked_nmethod(nmethod* cb);
+    // = { cb->oops_do(_cl); }
+  virtual void do_code_blob(CodeBlob* cb);
+    // = { if (_do_marking)  super::do_code_blob(cb); else cb->oops_do(_cl); }
+  CodeBlobToOopClosure(OopClosure* cl, bool do_marking)
+    : _cl(cl), _do_marking(do_marking) {}
+};
+
+
 
 // MonitorClosure is used for iterating over monitors in the monitors cache
 
--- a/hotspot/src/share/vm/memory/sharedHeap.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/memory/sharedHeap.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -100,12 +100,27 @@
          "Not in range.");
 }
 
-void SharedHeap::process_strong_roots(bool collecting_perm_gen,
+SharedHeap::StrongRootsScope::StrongRootsScope(SharedHeap* outer, bool activate)
+  : MarkScope(activate)
+{
+  if (_active) {
+    outer->change_strong_roots_parity();
+  }
+}
+
+SharedHeap::StrongRootsScope::~StrongRootsScope() {
+  // nothing particular
+}
+
+void SharedHeap::process_strong_roots(bool activate_scope,
+                                      bool collecting_perm_gen,
                                       ScanningOption so,
                                       OopClosure* roots,
+                                      CodeBlobClosure* code_roots,
                                       OopsInGenClosure* perm_blk) {
+  StrongRootsScope srs(this, activate_scope);
   // General strong roots.
-  if (n_par_threads() == 0) change_strong_roots_parity();
+  assert(_strong_roots_parity != 0, "must have called prologue code");
   if (!_process_strong_tasks->is_task_claimed(SH_PS_Universe_oops_do)) {
     Universe::oops_do(roots);
     ReferenceProcessor::oops_do(roots);
@@ -117,9 +132,9 @@
     JNIHandles::oops_do(roots);
   // All threads execute this; the individual threads are task groups.
   if (ParallelGCThreads > 0) {
-    Threads::possibly_parallel_oops_do(roots);
+    Threads::possibly_parallel_oops_do(roots, code_roots);
   } else {
-    Threads::oops_do(roots);
+    Threads::oops_do(roots, code_roots);
   }
   if (!_process_strong_tasks-> is_task_claimed(SH_PS_ObjectSynchronizer_oops_do))
     ObjectSynchronizer::oops_do(roots);
@@ -156,11 +171,29 @@
   }
 
   if (!_process_strong_tasks->is_task_claimed(SH_PS_CodeCache_oops_do)) {
-     if (so & SO_CodeCache) {
-       CodeCache::oops_do(roots);
-     }
+    if (so & SO_CodeCache) {
+      // (Currently, CMSCollector uses this to do intermediate-strength collections.)
+      assert(collecting_perm_gen, "scanning all of code cache");
+      assert(code_roots != NULL, "must supply closure for code cache");
+      if (code_roots != NULL) {
+        CodeCache::blobs_do(code_roots);
+      }
+    } else if (so & (SO_SystemClasses|SO_AllClasses)) {
+      if (!collecting_perm_gen) {
+        // If we are collecting from class statics, but we are not going to
+        // visit all of the CodeCache, collect from the non-perm roots if any.
+        // This makes the code cache function temporarily as a source of strong
+        // roots for oops, until the next major collection.
+        //
+        // If collecting_perm_gen is true, we require that this phase will call
+        // CodeCache::do_unloading.  This will kill off nmethods with expired
+        // weak references, such as stale invokedynamic targets.
+        CodeCache::scavenge_root_nmethods_do(code_roots);
+      }
+    }
     // Verify if the code cache contents are in the perm gen
-    NOT_PRODUCT(CodeCache::oops_do(&assert_is_perm_closure));
+    NOT_PRODUCT(CodeBlobToOopClosure assert_code_is_perm(&assert_is_perm_closure, /*do_marking=*/ false));
+    NOT_PRODUCT(CodeCache::asserted_non_scavengable_nmethods_do(&assert_code_is_perm));
   }
 
   // Roots that should point only into permanent generation.
@@ -220,11 +253,12 @@
 // just skip adjusting any shared entries in the string table.
 
 void SharedHeap::process_weak_roots(OopClosure* root_closure,
+                                    CodeBlobClosure* code_roots,
                                     OopClosure* non_root_closure) {
   // Global (weak) JNI handles
   JNIHandles::weak_oops_do(&always_true, root_closure);
 
-  CodeCache::oops_do(non_root_closure);
+  CodeCache::blobs_do(code_roots);
   SymbolTable::oops_do(root_closure);
   if (UseSharedSpaces && !DumpSharedSpaces) {
     SkipAdjustingSharedStrings skip_closure(root_closure);
--- a/hotspot/src/share/vm/memory/sharedHeap.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/memory/sharedHeap.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -165,9 +165,21 @@
   //   c) to never return a distinguished value (zero) with which such
   //      task-claiming variables may be initialized, to indicate "never
   //      claimed".
+ private:
   void change_strong_roots_parity();
+ public:
   int strong_roots_parity() { return _strong_roots_parity; }
 
+  // Call these in sequential code around process_strong_roots.
+  // strong_roots_prologue calls change_strong_roots_parity, if
+  // parallel tasks are enabled.
+  class StrongRootsScope : public MarkingCodeBlobClosure::MarkScope {
+  public:
+    StrongRootsScope(SharedHeap* outer, bool activate = true);
+    ~StrongRootsScope();
+  };
+  friend class StrongRootsScope;
+
   enum ScanningOption {
     SO_None                = 0x0,
     SO_AllClasses          = 0x1,
@@ -198,15 +210,18 @@
   // "SO_Symbols" applies the closure to all entries in SymbolsTable;
   // "SO_Strings" applies the closure to all entries in StringTable;
   // "SO_CodeCache" applies the closure to all elements of the CodeCache.
-  void process_strong_roots(bool collecting_perm_gen,
+  void process_strong_roots(bool activate_scope,
+                            bool collecting_perm_gen,
                             ScanningOption so,
                             OopClosure* roots,
+                            CodeBlobClosure* code_roots,
                             OopsInGenClosure* perm_blk);
 
   // Apply "blk" to all the weak roots of the system.  These include
   // JNI weak roots, the code cache, system dictionary, symbol table,
   // string table.
   void process_weak_roots(OopClosure* root_closure,
+                          CodeBlobClosure* code_roots,
                           OopClosure* non_root_closure);
 
 
--- a/hotspot/src/share/vm/oops/instanceKlass.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/oops/instanceKlass.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -2152,7 +2152,7 @@
   // This is a short non-blocking critical region, so the no safepoint check is ok.
   OsrList_lock->lock_without_safepoint_check();
   assert(n->is_osr_method(), "wrong kind of nmethod");
-  n->set_link(osr_nmethods_head());
+  n->set_osr_link(osr_nmethods_head());
   set_osr_nmethods_head(n);
   // Remember to unlock again
   OsrList_lock->unlock();
@@ -2168,17 +2168,17 @@
   // Search for match
   while(cur != NULL && cur != n) {
     last = cur;
-    cur = cur->link();
+    cur = cur->osr_link();
   }
   if (cur == n) {
     if (last == NULL) {
       // Remove first element
-      set_osr_nmethods_head(osr_nmethods_head()->link());
+      set_osr_nmethods_head(osr_nmethods_head()->osr_link());
     } else {
-      last->set_link(cur->link());
+      last->set_osr_link(cur->osr_link());
     }
   }
-  n->set_link(NULL);
+  n->set_osr_link(NULL);
   // Remember to unlock again
   OsrList_lock->unlock();
 }
@@ -2195,7 +2195,7 @@
       OsrList_lock->unlock();
       return osr;
     }
-    osr = osr->link();
+    osr = osr->osr_link();
   }
   OsrList_lock->unlock();
   return NULL;
--- a/hotspot/src/share/vm/oops/oop.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/oops/oop.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -330,6 +330,7 @@
 
   bool is_perm() const;
   bool is_perm_or_null() const;
+  bool is_scavengable() const;
   bool is_shared() const;
   bool is_shared_readonly() const;
   bool is_shared_readwrite() const;
--- a/hotspot/src/share/vm/oops/oop.inline2.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/oops/oop.inline2.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -34,3 +34,7 @@
 inline bool oopDesc::is_perm_or_null() const {
   return this == NULL || is_perm();
 }
+
+inline bool oopDesc::is_scavengable() const {
+  return Universe::heap()->is_scavengable(this);
+}
--- a/hotspot/src/share/vm/opto/connode.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/opto/connode.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -1085,6 +1085,9 @@
   switch (op) {
   case Op_SubX:
     x = in(1)->in(1);
+    // Avoid ideal transformations ping-pong between this and AddP for raw pointers.
+    if (phase->find_intptr_t_con(x, -1) == 0)
+      break;
     y = in(1)->in(2);
     if (fits_in_int(phase->type(y), true)) {
       return addP_of_X2P(phase, x, y, true);
--- a/hotspot/src/share/vm/opto/escape.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/opto/escape.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -524,12 +524,15 @@
   // inlining) which was not eliminated during parsing since the exactness
   // of the allocation type was not propagated to the subclass type check.
   //
+  // Or the type 't' could be not related to 'base_t' at all.
+  // It could happened when CHA type is different from MDO type on a dead path
+  // (for example, from instanceof check) which is not collapsed during parsing.
+  //
   // Do nothing for such AddP node and don't process its users since
   // this code branch will go away.
   //
   if (!t->is_known_instance() &&
-      !t->klass()->equals(base_t->klass()) &&
-      t->klass()->is_subtype_of(base_t->klass())) {
+      !base_t->klass()->is_subtype_of(t->klass())) {
      return false; // bail out
   }
 
--- a/hotspot/src/share/vm/opto/graphKit.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/opto/graphKit.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -1450,7 +1450,7 @@
 
     case BarrierSet::CardTableModRef:
     case BarrierSet::CardTableExtension:
-      write_barrier_post(store, obj, adr, val, use_precise);
+      write_barrier_post(store, obj, adr, adr_idx, val, use_precise);
       break;
 
     case BarrierSet::ModRef:
@@ -3165,6 +3165,7 @@
 void GraphKit::write_barrier_post(Node* oop_store,
                                   Node* obj,
                                   Node* adr,
+                                  uint  adr_idx,
                                   Node* val,
                                   bool use_precise) {
   // No store check needed if we're storing a NULL or an old object
@@ -3214,7 +3215,7 @@
     __ store(__ ctrl(), card_adr, zero, bt, adr_type);
   } else {
     // Specialized path for CM store barrier
-    __ storeCM(__ ctrl(), card_adr, zero, oop_store, bt, adr_type);
+    __ storeCM(__ ctrl(), card_adr, zero, oop_store, adr_idx, bt, adr_type);
   }
 
   // Final sync IdealKit and GraphKit.
@@ -3314,6 +3315,7 @@
 void GraphKit::g1_mark_card(IdealKit& ideal,
                             Node* card_adr,
                             Node* oop_store,
+                            uint oop_alias_idx,
                             Node* index,
                             Node* index_adr,
                             Node* buffer,
@@ -3323,7 +3325,7 @@
   Node* no_base = __ top();
   BasicType card_bt = T_BYTE;
   // Smash zero into card. MUST BE ORDERED WRT TO STORE
-  __ storeCM(__ ctrl(), card_adr, zero, oop_store, card_bt, Compile::AliasIdxRaw);
+  __ storeCM(__ ctrl(), card_adr, zero, oop_store, oop_alias_idx, card_bt, Compile::AliasIdxRaw);
 
   //  Now do the queue work
   __ if_then(index, BoolTest::ne, zero); {
@@ -3435,13 +3437,13 @@
         Node* card_val = __ load(__ ctrl(), card_adr, TypeInt::INT, T_BYTE, Compile::AliasIdxRaw);
 
         __ if_then(card_val, BoolTest::ne, zero); {
-          g1_mark_card(ideal, card_adr, oop_store, index, index_adr, buffer, tf);
+          g1_mark_card(ideal, card_adr, oop_store, alias_idx, index, index_adr, buffer, tf);
         } __ end_if();
       } __ end_if();
     } __ end_if();
   } else {
     // Object.clone() instrinsic uses this path.
-    g1_mark_card(ideal, card_adr, oop_store, index, index_adr, buffer, tf);
+    g1_mark_card(ideal, card_adr, oop_store, alias_idx, index, index_adr, buffer, tf);
   }
 
   // Final sync IdealKit and GraphKit.
--- a/hotspot/src/share/vm/opto/graphKit.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/opto/graphKit.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -603,7 +603,8 @@
   void sync_kit(IdealKit& ideal);
 
   // vanilla/CMS post barrier
-  void write_barrier_post(Node *store, Node* obj, Node* adr, Node* val, bool use_precise);
+  void write_barrier_post(Node *store, Node* obj,
+                          Node* adr,  uint adr_idx, Node* val, bool use_precise);
 
   // G1 pre/post barriers
   void g1_write_barrier_pre(Node* obj,
@@ -622,7 +623,8 @@
                              bool use_precise);
   // Helper function for g1
   private:
-  void g1_mark_card(IdealKit& ideal, Node* card_adr, Node* store,  Node* index, Node* index_adr,
+  void g1_mark_card(IdealKit& ideal, Node* card_adr, Node* store, uint oop_alias_idx,
+                    Node* index, Node* index_adr,
                     Node* buffer, const TypeFunc* tf);
 
   public:
--- a/hotspot/src/share/vm/opto/idealKit.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/opto/idealKit.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -378,7 +378,7 @@
 
 // Card mark store. Must be ordered so that it will come after the store of
 // the oop.
-Node* IdealKit::storeCM(Node* ctl, Node* adr, Node *val, Node* oop_store,
+Node* IdealKit::storeCM(Node* ctl, Node* adr, Node *val, Node* oop_store, int oop_adr_idx,
                         BasicType bt,
                         int adr_idx) {
   assert(adr_idx != Compile::AliasIdxTop, "use other store_to_memory factory" );
@@ -388,7 +388,7 @@
 
   // Add required edge to oop_store, optimizer does not support precedence edges.
   // Convert required edge to precedence edge before allocation.
-  Node* st = new (C, 5) StoreCMNode(ctl, mem, adr, adr_type, val, oop_store);
+  Node* st = new (C, 5) StoreCMNode(ctl, mem, adr, adr_type, val, oop_store, oop_adr_idx);
 
   st = transform(st);
   set_memory(st, adr_idx);
--- a/hotspot/src/share/vm/opto/idealKit.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/opto/idealKit.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -216,6 +216,7 @@
                 Node* adr,
                 Node* val,
                 Node* oop_store,
+                int oop_adr_idx,
                 BasicType bt,
                 int adr_idx);
 
--- a/hotspot/src/share/vm/opto/library_call.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/opto/library_call.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -133,6 +133,7 @@
     return generate_method_call(method_id, true, false);
   }
 
+  Node* make_string_method_node(int opcode, Node* str1, Node* cnt1, Node* str2, Node* cnt2);
   bool inline_string_compareTo();
   bool inline_string_indexOf();
   Node* string_indexOf(Node* string_object, ciTypeArray* target_array, jint offset, jint cache_i, jint md2_i);
@@ -796,6 +797,64 @@
 }
 
 
+//------------------------------make_string_method_node------------------------
+// Helper method for String intrinsic finctions.
+Node* LibraryCallKit::make_string_method_node(int opcode, Node* str1, Node* cnt1, Node* str2, Node* cnt2) {
+  const int value_offset  = java_lang_String::value_offset_in_bytes();
+  const int count_offset  = java_lang_String::count_offset_in_bytes();
+  const int offset_offset = java_lang_String::offset_offset_in_bytes();
+
+  Node* no_ctrl = NULL;
+
+  ciInstanceKlass* klass = env()->String_klass();
+  const TypeInstPtr* string_type =
+        TypeInstPtr::make(TypePtr::BotPTR, klass, false, NULL, 0);
+
+  const TypeAryPtr* value_type =
+        TypeAryPtr::make(TypePtr::NotNull,
+                         TypeAry::make(TypeInt::CHAR,TypeInt::POS),
+                         ciTypeArrayKlass::make(T_CHAR), true, 0);
+
+  // Get start addr of string and substring
+  Node* str1_valuea  = basic_plus_adr(str1, str1, value_offset);
+  Node* str1_value   = make_load(no_ctrl, str1_valuea, value_type, T_OBJECT, string_type->add_offset(value_offset));
+  Node* str1_offseta = basic_plus_adr(str1, str1, offset_offset);
+  Node* str1_offset  = make_load(no_ctrl, str1_offseta, TypeInt::INT, T_INT, string_type->add_offset(offset_offset));
+  Node* str1_start   = array_element_address(str1_value, str1_offset, T_CHAR);
+
+  // Pin loads from String::equals() argument since it could be NULL.
+  Node* str2_ctrl = (opcode == Op_StrEquals) ? control() : no_ctrl;
+  Node* str2_valuea  = basic_plus_adr(str2, str2, value_offset);
+  Node* str2_value   = make_load(str2_ctrl, str2_valuea, value_type, T_OBJECT, string_type->add_offset(value_offset));
+  Node* str2_offseta = basic_plus_adr(str2, str2, offset_offset);
+  Node* str2_offset  = make_load(str2_ctrl, str2_offseta, TypeInt::INT, T_INT, string_type->add_offset(offset_offset));
+  Node* str2_start   = array_element_address(str2_value, str2_offset, T_CHAR);
+
+  Node* result = NULL;
+  switch (opcode) {
+  case Op_StrIndexOf:
+    result = new (C, 6) StrIndexOfNode(control(), memory(TypeAryPtr::CHARS),
+                                       str1_start, cnt1, str2_start, cnt2);
+    break;
+  case Op_StrComp:
+    result = new (C, 6) StrCompNode(control(), memory(TypeAryPtr::CHARS),
+                                    str1_start, cnt1, str2_start, cnt2);
+    break;
+  case Op_StrEquals:
+    result = new (C, 5) StrEqualsNode(control(), memory(TypeAryPtr::CHARS),
+                                      str1_start, str2_start, cnt1);
+    break;
+  default:
+    ShouldNotReachHere();
+    return NULL;
+  }
+
+  // All these intrinsics have checks.
+  C->set_has_split_ifs(true); // Has chance for split-if optimization
+
+  return _gvn.transform(result);
+}
+
 //------------------------------inline_string_compareTo------------------------
 bool LibraryCallKit::inline_string_compareTo() {
 
@@ -824,16 +883,16 @@
   ciInstanceKlass* klass = env()->String_klass();
   const TypeInstPtr* string_type =
     TypeInstPtr::make(TypePtr::BotPTR, klass, false, NULL, 0);
-
-  Node* compare =
-    _gvn.transform(new (C, 7) StrCompNode(
-                        control(),
-                        memory(TypeAryPtr::CHARS),
-                        memory(string_type->add_offset(value_offset)),
-                        memory(string_type->add_offset(count_offset)),
-                        memory(string_type->add_offset(offset_offset)),
-                        receiver,
-                        argument));
+  Node* no_ctrl = NULL;
+
+  // Get counts for string and argument
+  Node* receiver_cnta = basic_plus_adr(receiver, receiver, count_offset);
+  Node* receiver_cnt  = make_load(no_ctrl, receiver_cnta, TypeInt::INT, T_INT, string_type->add_offset(count_offset));
+
+  Node* argument_cnta = basic_plus_adr(argument, argument, count_offset);
+  Node* argument_cnt  = make_load(no_ctrl, argument_cnta, TypeInt::INT, T_INT, string_type->add_offset(count_offset));
+
+  Node* compare = make_string_method_node(Op_StrComp, receiver, receiver_cnt, argument, argument_cnt);
   push(compare);
   return true;
 }
@@ -865,45 +924,71 @@
     return true;
   }
 
+  // paths (plus control) merge
+  RegionNode* region = new (C, 5) RegionNode(5);
+  Node* phi = new (C, 5) PhiNode(region, TypeInt::BOOL);
+
+  // does source == target string?
+  Node* cmp = _gvn.transform(new (C, 3) CmpPNode(receiver, argument));
+  Node* bol = _gvn.transform(new (C, 2) BoolNode(cmp, BoolTest::eq));
+
+  Node* if_eq = generate_slow_guard(bol, NULL);
+  if (if_eq != NULL) {
+    // receiver == argument
+    phi->init_req(2, intcon(1));
+    region->init_req(2, if_eq);
+  }
+
   // get String klass for instanceOf
   ciInstanceKlass* klass = env()->String_klass();
 
-  // two paths (plus control) merge
-  RegionNode* region = new (C, 3) RegionNode(3);
-  Node* phi = new (C, 3) PhiNode(region, TypeInt::BOOL);
-
-  Node* inst = gen_instanceof(argument, makecon(TypeKlassPtr::make(klass)));
-  Node* cmp  = _gvn.transform(new (C, 3) CmpINode(inst, intcon(1)));
-  Node* bol  = _gvn.transform(new (C, 2) BoolNode(cmp, BoolTest::eq));
-
-  IfNode* iff = create_and_map_if(control(), bol, PROB_MAX, COUNT_UNKNOWN);
-
-  Node* if_true  = _gvn.transform(new (C, 1) IfTrueNode(iff));
-  set_control(if_true);
+  if (!stopped()) {
+    Node* inst = gen_instanceof(argument, makecon(TypeKlassPtr::make(klass)));
+    Node* cmp  = _gvn.transform(new (C, 3) CmpINode(inst, intcon(1)));
+    Node* bol  = _gvn.transform(new (C, 2) BoolNode(cmp, BoolTest::ne));
+
+    Node* inst_false = generate_guard(bol, NULL, PROB_MIN);
+    //instanceOf == true, fallthrough
+
+    if (inst_false != NULL) {
+      phi->init_req(3, intcon(0));
+      region->init_req(3, inst_false);
+    }
+  }
 
   const TypeInstPtr* string_type =
     TypeInstPtr::make(TypePtr::BotPTR, klass, false, NULL, 0);
 
-  // instanceOf == true
-  Node* equals =
-    _gvn.transform(new (C, 7) StrEqualsNode(
-                        control(),
-                        memory(TypeAryPtr::CHARS),
-                        memory(string_type->add_offset(value_offset)),
-                        memory(string_type->add_offset(count_offset)),
-                        memory(string_type->add_offset(offset_offset)),
-                        receiver,
-                        argument));
-
-  phi->init_req(1, _gvn.transform(equals));
-  region->init_req(1, if_true);
-
-  //instanceOf == false, fallthrough
-  Node* if_false = _gvn.transform(new (C, 1) IfFalseNode(iff));
-  set_control(if_false);
-
-  phi->init_req(2, _gvn.transform(intcon(0)));
-  region->init_req(2, if_false);
+  Node* no_ctrl = NULL;
+  Node* receiver_cnt;
+  Node* argument_cnt;
+
+  if (!stopped()) {
+    // Get counts for string and argument
+    Node* receiver_cnta = basic_plus_adr(receiver, receiver, count_offset);
+    receiver_cnt  = make_load(no_ctrl, receiver_cnta, TypeInt::INT, T_INT, string_type->add_offset(count_offset));
+
+    // Pin load from argument string since it could be NULL.
+    Node* argument_cnta = basic_plus_adr(argument, argument, count_offset);
+    argument_cnt  = make_load(control(), argument_cnta, TypeInt::INT, T_INT, string_type->add_offset(count_offset));
+
+    // Check for receiver count != argument count
+    Node* cmp = _gvn.transform( new(C, 3) CmpINode(receiver_cnt, argument_cnt) );
+    Node* bol = _gvn.transform( new(C, 2) BoolNode(cmp, BoolTest::ne) );
+    Node* if_ne = generate_slow_guard(bol, NULL);
+    if (if_ne != NULL) {
+      phi->init_req(4, intcon(0));
+      region->init_req(4, if_ne);
+    }
+  }
+
+  // Check for count == 0 is done by mach node StrEquals.
+
+  if (!stopped()) {
+    Node* equals = make_string_method_node(Op_StrEquals, receiver, receiver_cnt, argument, argument_cnt);
+    phi->init_req(1, equals);
+    region->init_req(1, control());
+  }
 
   // post merge
   set_control(_gvn.transform(region));
@@ -924,10 +1009,8 @@
   Node *argument1 = pop();
 
   Node* equals =
-    _gvn.transform(new (C, 3) AryEqNode(control(),
-                                        argument1,
-                                        argument2)
-                   );
+    _gvn.transform(new (C, 4) AryEqNode(control(), memory(TypeAryPtr::CHARS),
+                                        argument1, argument2) );
   push(equals);
   return true;
 }
@@ -1108,19 +1191,40 @@
       return true;
     }
 
+    // Make the merge point
+    RegionNode* result_rgn = new (C, 3) RegionNode(3);
+    Node*       result_phi = new (C, 3) PhiNode(result_rgn, TypeInt::INT);
+    Node* no_ctrl  = NULL;
+
     ciInstanceKlass* klass = env()->String_klass();
     const TypeInstPtr* string_type =
       TypeInstPtr::make(TypePtr::BotPTR, klass, false, NULL, 0);
 
-    result =
-      _gvn.transform(new (C, 7)
-                     StrIndexOfNode(control(),
-                                    memory(TypeAryPtr::CHARS),
-                                    memory(string_type->add_offset(value_offset)),
-                                    memory(string_type->add_offset(count_offset)),
-                                    memory(string_type->add_offset(offset_offset)),
-                                    receiver,
-                                    argument));
+    // Get counts for string and substr
+    Node* source_cnta = basic_plus_adr(receiver, receiver, count_offset);
+    Node* source_cnt  = make_load(no_ctrl, source_cnta, TypeInt::INT, T_INT, string_type->add_offset(count_offset));
+
+    Node* substr_cnta = basic_plus_adr(argument, argument, count_offset);
+    Node* substr_cnt  = make_load(no_ctrl, substr_cnta, TypeInt::INT, T_INT, string_type->add_offset(count_offset));
+
+    // Check for substr count > string count
+    Node* cmp = _gvn.transform( new(C, 3) CmpINode(substr_cnt, source_cnt) );
+    Node* bol = _gvn.transform( new(C, 2) BoolNode(cmp, BoolTest::gt) );
+    Node* if_gt = generate_slow_guard(bol, NULL);
+    if (if_gt != NULL) {
+      result_phi->init_req(2, intcon(-1));
+      result_rgn->init_req(2, if_gt);
+    }
+
+    if (!stopped()) {
+      result = make_string_method_node(Op_StrIndexOf, receiver, source_cnt, argument, substr_cnt);
+      result_phi->init_req(1, result);
+      result_rgn->init_req(1, control());
+    }
+    set_control(_gvn.transform(result_rgn));
+    record_for_igvn(result_rgn);
+    result = _gvn.transform(result_phi);
+
   } else { //Use LibraryCallKit::string_indexOf
     // don't intrinsify is argument isn't a constant string.
     if (!argument->is_Con()) {
--- a/hotspot/src/share/vm/opto/matcher.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/opto/matcher.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -2032,6 +2032,23 @@
         n->del_req(3);
         break;
       }
+      case Op_StrEquals: {
+        Node *pair1 = new (C, 3) BinaryNode(n->in(2),n->in(3));
+        n->set_req(2,pair1);
+        n->set_req(3,n->in(4));
+        n->del_req(4);
+        break;
+      }
+      case Op_StrComp:
+      case Op_StrIndexOf: {
+        Node *pair1 = new (C, 3) BinaryNode(n->in(2),n->in(3));
+        n->set_req(2,pair1);
+        Node *pair2 = new (C, 3) BinaryNode(n->in(4),n->in(5));
+        n->set_req(3,pair2);
+        n->del_req(5);
+        n->del_req(4);
+        break;
+      }
       default:
         break;
       }
--- a/hotspot/src/share/vm/opto/memnode.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/opto/memnode.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -2313,6 +2313,22 @@
   return this;
 }
 
+//=============================================================================
+//------------------------------Ideal---------------------------------------
+Node *StoreCMNode::Ideal(PhaseGVN *phase, bool can_reshape){
+  Node* progress = StoreNode::Ideal(phase, can_reshape);
+  if (progress != NULL) return progress;
+
+  Node* my_store = in(MemNode::OopStore);
+  if (my_store->is_MergeMem()) {
+    Node* mem = my_store->as_MergeMem()->memory_at(oop_alias_idx());
+    set_req(MemNode::OopStore, mem);
+    return this;
+  }
+
+  return NULL;
+}
+
 //------------------------------Value-----------------------------------------
 const Type *StoreCMNode::Value( PhaseTransform *phase ) const {
   // Either input is TOP ==> the result is TOP
@@ -2498,7 +2514,7 @@
 //=============================================================================
 // Do we match on this edge? No memory edges
 uint StrCompNode::match_edge(uint idx) const {
-  return idx == 5 || idx == 6;
+  return idx == 2 || idx == 3; // StrComp (Binary str1 cnt1) (Binary str2 cnt2)
 }
 
 //------------------------------Ideal------------------------------------------
@@ -2508,9 +2524,10 @@
   return remove_dead_region(phase, can_reshape) ? this : NULL;
 }
 
+//=============================================================================
 // Do we match on this edge? No memory edges
 uint StrEqualsNode::match_edge(uint idx) const {
-  return idx == 5 || idx == 6;
+  return idx == 2 || idx == 3; // StrEquals (Binary str1 str2) cnt
 }
 
 //------------------------------Ideal------------------------------------------
@@ -2523,7 +2540,7 @@
 //=============================================================================
 // Do we match on this edge? No memory edges
 uint StrIndexOfNode::match_edge(uint idx) const {
-  return idx == 5 || idx == 6;
+  return idx == 2 || idx == 3; // StrIndexOf (Binary str1 cnt1) (Binary str2 cnt2)
 }
 
 //------------------------------Ideal------------------------------------------
@@ -2533,6 +2550,11 @@
   return remove_dead_region(phase, can_reshape) ? this : NULL;
 }
 
+//=============================================================================
+// Do we match on this edge? No memory edges
+uint AryEqNode::match_edge(uint idx) const {
+  return idx == 2 || idx == 3; // StrEquals ary1 ary2
+}
 //------------------------------Ideal------------------------------------------
 // Return a node which is more "ideal" than the current node.  Strip out
 // control copies
--- a/hotspot/src/share/vm/opto/memnode.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/opto/memnode.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -582,12 +582,16 @@
 // The last StoreCM before a SafePoint must be preserved and occur after its "oop" store
 // Preceeding equivalent StoreCMs may be eliminated.
 class StoreCMNode : public StoreNode {
+ private:
+  int _oop_alias_idx;   // The alias_idx of OopStore
 public:
-  StoreCMNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, Node *oop_store ) : StoreNode(c,mem,adr,at,val,oop_store) {}
+  StoreCMNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, Node *oop_store, int oop_alias_idx ) : StoreNode(c,mem,adr,at,val,oop_store), _oop_alias_idx(oop_alias_idx) {}
   virtual int Opcode() const;
   virtual Node *Identity( PhaseTransform *phase );
+  virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   virtual const Type *Value( PhaseTransform *phase ) const;
   virtual BasicType memory_type() const { return T_VOID; } // unspecific
+  int oop_alias_idx() const { return _oop_alias_idx; }
 };
 
 //------------------------------LoadPLockedNode---------------------------------
@@ -744,22 +748,15 @@
 //------------------------------StrComp-------------------------------------
 class StrCompNode: public Node {
 public:
-  StrCompNode(Node *control,
-              Node* char_array_mem,
-              Node* value_mem,
-              Node* count_mem,
-              Node* offset_mem,
-              Node* s1, Node* s2): Node(control,
-                                        char_array_mem,
-                                        value_mem,
-                                        count_mem,
-                                        offset_mem,
-                                        s1, s2) {};
+  StrCompNode(Node* control, Node* char_array_mem,
+              Node* s1, Node* c1,
+              Node* s2, Node* c2): Node(control, char_array_mem,
+                                        s1, c1,
+                                        s2, c2) {};
   virtual int Opcode() const;
   virtual bool depends_only_on_test() const { return false; }
   virtual const Type* bottom_type() const { return TypeInt::INT; }
-  // a StrCompNode (conservatively) aliases with everything:
-  virtual const TypePtr* adr_type() const { return TypePtr::BOTTOM; }
+  virtual const TypePtr* adr_type() const { return TypeAryPtr::CHARS; }
   virtual uint match_edge(uint idx) const;
   virtual uint ideal_reg() const { return Op_RegI; }
   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
@@ -768,22 +765,13 @@
 //------------------------------StrEquals-------------------------------------
 class StrEqualsNode: public Node {
 public:
-  StrEqualsNode(Node *control,
-                Node* char_array_mem,
-                Node* value_mem,
-                Node* count_mem,
-                Node* offset_mem,
-                Node* s1, Node* s2): Node(control,
-                                          char_array_mem,
-                                          value_mem,
-                                          count_mem,
-                                          offset_mem,
-                                          s1, s2) {};
+  StrEqualsNode(Node* control, Node* char_array_mem,
+                Node* s1, Node* s2, Node* c): Node(control, char_array_mem,
+                                                   s1, s2, c) {};
   virtual int Opcode() const;
   virtual bool depends_only_on_test() const { return false; }
   virtual const Type* bottom_type() const { return TypeInt::BOOL; }
-  // a StrEqualsNode (conservatively) aliases with everything:
-  virtual const TypePtr* adr_type() const { return TypePtr::BOTTOM; }
+  virtual const TypePtr* adr_type() const { return TypeAryPtr::CHARS; }
   virtual uint match_edge(uint idx) const;
   virtual uint ideal_reg() const { return Op_RegI; }
   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
@@ -792,22 +780,15 @@
 //------------------------------StrIndexOf-------------------------------------
 class StrIndexOfNode: public Node {
 public:
-  StrIndexOfNode(Node *control,
-                 Node* char_array_mem,
-                 Node* value_mem,
-                 Node* count_mem,
-                 Node* offset_mem,
-                 Node* s1, Node* s2): Node(control,
-                                           char_array_mem,
-                                           value_mem,
-                                           count_mem,
-                                           offset_mem,
-                                           s1, s2) {};
+  StrIndexOfNode(Node* control, Node* char_array_mem,
+                 Node* s1, Node* c1,
+                 Node* s2, Node* c2): Node(control, char_array_mem,
+                                           s1, c1,
+                                           s2, c2) {};
   virtual int Opcode() const;
   virtual bool depends_only_on_test() const { return false; }
   virtual const Type* bottom_type() const { return TypeInt::INT; }
-  // a StrIndexOfNode (conservatively) aliases with everything:
-  virtual const TypePtr* adr_type() const { return TypePtr::BOTTOM; }
+  virtual const TypePtr* adr_type() const { return TypeAryPtr::CHARS; }
   virtual uint match_edge(uint idx) const;
   virtual uint ideal_reg() const { return Op_RegI; }
   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
@@ -816,11 +797,13 @@
 //------------------------------AryEq---------------------------------------
 class AryEqNode: public Node {
 public:
-  AryEqNode(Node *control, Node* s1, Node* s2): Node(control, s1, s2) {};
+  AryEqNode(Node* control, Node* char_array_mem,
+            Node* s1, Node* s2): Node(control, char_array_mem, s1, s2) {};
   virtual int Opcode() const;
   virtual bool depends_only_on_test() const { return false; }
   virtual const Type* bottom_type() const { return TypeInt::BOOL; }
   virtual const TypePtr* adr_type() const { return TypeAryPtr::CHARS; }
+  virtual uint match_edge(uint idx) const;
   virtual uint ideal_reg() const { return Op_RegI; }
   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
 };
--- a/hotspot/src/share/vm/opto/output.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/opto/output.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -611,7 +611,7 @@
       assert(cik->is_instance_klass() ||
              cik->is_array_klass(), "Not supported allocation.");
       sv = new ObjectValue(spobj->_idx,
-                           new ConstantOopWriteValue(cik->encoding()));
+                           new ConstantOopWriteValue(cik->constant_encoding()));
       Compile::set_sv_for_object_node(objs, sv);
 
       uint first_ind = spobj->first_index();
@@ -702,13 +702,13 @@
   case Type::AryPtr:
   case Type::InstPtr:
   case Type::KlassPtr:          // fall through
-    array->append(new ConstantOopWriteValue(t->isa_oopptr()->const_oop()->encoding()));
+    array->append(new ConstantOopWriteValue(t->isa_oopptr()->const_oop()->constant_encoding()));
     break;
   case Type::NarrowOop:
     if (t == TypeNarrowOop::NULL_PTR) {
       array->append(new ConstantOopWriteValue(NULL));
     } else {
-      array->append(new ConstantOopWriteValue(t->make_ptr()->isa_oopptr()->const_oop()->encoding()));
+      array->append(new ConstantOopWriteValue(t->make_ptr()->isa_oopptr()->const_oop()->constant_encoding()));
     }
     break;
   case Type::Int:
@@ -871,7 +871,7 @@
           assert(cik->is_instance_klass() ||
                  cik->is_array_klass(), "Not supported allocation.");
           ObjectValue* sv = new ObjectValue(spobj->_idx,
-                                new ConstantOopWriteValue(cik->encoding()));
+                                new ConstantOopWriteValue(cik->constant_encoding()));
           Compile::set_sv_for_object_node(objs, sv);
 
           uint first_ind = spobj->first_index();
@@ -890,7 +890,7 @@
         }
       } else {
         const TypePtr *tp = obj_node->bottom_type()->make_ptr();
-        scval = new ConstantOopWriteValue(tp->is_instptr()->const_oop()->encoding());
+        scval = new ConstantOopWriteValue(tp->is_instptr()->const_oop()->constant_encoding());
       }
 
       OptoReg::Name box_reg = BoxLockNode::stack_slot(box_node);
--- a/hotspot/src/share/vm/opto/parse.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/opto/parse.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -469,7 +469,7 @@
 
   // loading from a constant field or the constant pool
   // returns false if push failed (non-perm field constants only, not ldcs)
-  bool push_constant(ciConstant con);
+  bool push_constant(ciConstant con, bool require_constant = false);
 
   // implementation of object creation bytecodes
   void do_new();
--- a/hotspot/src/share/vm/opto/parse1.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/opto/parse1.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -229,7 +229,9 @@
     }
   }
 
-  MethodLivenessResult live_locals = method()->liveness_at_bci(osr_bci());
+  // Use the raw liveness computation to make sure that unexpected
+  // values don't propagate into the OSR frame.
+  MethodLivenessResult live_locals = method()->raw_liveness_at_bci(osr_bci());
   if (!live_locals.is_valid()) {
     // Degenerate or breakpointed method.
     C->record_method_not_compilable("OSR in empty or breakpointed method");
--- a/hotspot/src/share/vm/opto/parse2.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/opto/parse2.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -1325,7 +1325,8 @@
           }
         }
       }
-      push_constant(constant);
+      bool pushed = push_constant(constant, true);
+      guarantee(pushed, "must be possible to push this constant");
     }
 
     break;
--- a/hotspot/src/share/vm/opto/parse3.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/opto/parse3.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -267,7 +267,7 @@
 }
 
 
-bool Parse::push_constant(ciConstant constant) {
+bool Parse::push_constant(ciConstant constant, bool require_constant) {
   switch (constant.basic_type()) {
   case T_BOOLEAN:  push( intcon(constant.as_boolean()) ); break;
   case T_INT:      push( intcon(constant.as_int())     ); break;
@@ -279,13 +279,16 @@
   case T_LONG:     push_pair( longcon(constant.as_long()) ); break;
   case T_ARRAY:
   case T_OBJECT: {
-    // the oop is in perm space if the ciObject "has_encoding"
+    // cases:
+    //   can_be_constant    = (oop not scavengable || ScavengeRootsInCode != 0)
+    //   should_be_constant = (oop not scavengable || ScavengeRootsInCode >= 2)
+    // An oop is not scavengable if it is in the perm gen.
     ciObject* oop_constant = constant.as_object();
     if (oop_constant->is_null_object()) {
       push( zerocon(T_OBJECT) );
       break;
-    } else if (oop_constant->has_encoding()) {
-      push( makecon(TypeOopPtr::make_from_constant(oop_constant)) );
+    } else if (require_constant || oop_constant->should_be_constant()) {
+      push( makecon(TypeOopPtr::make_from_constant(oop_constant, require_constant)) );
       break;
     } else {
       // we cannot inline the oop, but we can use it later to narrow a type
--- a/hotspot/src/share/vm/opto/superword.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/opto/superword.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -457,10 +457,6 @@
         } else if (out->Opcode() == Op_StoreCM && out->in(MemNode::OopStore) == n) {
           // StoreCM has an input edge used as a precedence edge.
           // Maybe an issue when oop stores are vectorized.
-        } else if( out->is_MergeMem() && prev &&
-                   prev->Opcode() == Op_StoreCM && out == prev->in(MemNode::OopStore)) {
-          // Oop store is a MergeMem! This should not happen. Temporarily remove the assertion
-          // for this case because it could not be superwordized anyway.
         } else {
           assert(out == prev || prev == NULL, "no branches off of store slice");
         }
@@ -477,6 +473,12 @@
 // Can s1 and s2 be in a pack with s1 immediately preceding s2 and
 // s1 aligned at "align"
 bool SuperWord::stmts_can_pack(Node* s1, Node* s2, int align) {
+
+  // Do not use superword for non-primitives
+  if((s1->is_Mem() && !is_java_primitive(s1->as_Mem()->memory_type())) ||
+     (s2->is_Mem() && !is_java_primitive(s2->as_Mem()->memory_type())))
+    return false;
+
   if (isomorphic(s1, s2)) {
     if (independent(s1, s2)) {
       if (!exists_at(s1, 0) && !exists_at(s2, 1)) {
--- a/hotspot/src/share/vm/opto/type.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/opto/type.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -296,7 +296,7 @@
                                            false, 0, oopDesc::mark_offset_in_bytes());
   TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
                                            false, 0, oopDesc::klass_offset_in_bytes());
-  TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot);
+  TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot);
 
   TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
   TypeNarrowOop::BOTTOM   = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
@@ -492,8 +492,13 @@
 bool Type::interface_vs_oop(const Type *t) const {
   bool result = false;
 
-  const TypeInstPtr* this_inst = this->isa_instptr();
-  const TypeInstPtr*    t_inst =    t->isa_instptr();
+  const TypePtr* this_ptr = this->make_ptr(); // In case it is narrow_oop
+  const TypePtr*    t_ptr =    t->make_ptr();
+  if( this_ptr == NULL || t_ptr == NULL )
+    return result;
+
+  const TypeInstPtr* this_inst = this_ptr->isa_instptr();
+  const TypeInstPtr*    t_inst =    t_ptr->isa_instptr();
   if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) {
     bool this_interface = this_inst->klass()->is_interface();
     bool    t_interface =    t_inst->klass()->is_interface();
@@ -2249,7 +2254,7 @@
 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
   if( ptr == _ptr ) return this;
-  return make(ptr, _offset);
+  return make(ptr, _offset, _instance_id);
 }
 
 //-----------------------------cast_to_instance_id----------------------------
@@ -2319,8 +2324,10 @@
       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset);
       // else fall through:
     case TopPTR:
-    case AnyNull:
-      return make(ptr, offset);
+    case AnyNull: {
+      int instance_id = meet_instance_id(InstanceTop);
+      return make(ptr, offset, instance_id);
+    }
     case BotPTR:
     case NotNull:
       return TypePtr::make(AnyPtr, ptr, offset);
@@ -2411,14 +2418,13 @@
 
 //------------------------------make_from_constant-----------------------------
 // Make a java pointer from an oop constant
-const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o) {
+const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
   if (o->is_method_data() || o->is_method()) {
     // Treat much like a typeArray of bytes, like below, but fake the type...
-    assert(o->has_encoding(), "must be a perm space object");
     const Type* etype = (Type*)get_const_basic_type(T_BYTE);
     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
     ciKlass *klass = ciTypeArrayKlass::make((BasicType) T_BYTE);
-    assert(o->has_encoding(), "method data oops should be tenured");
+    assert(o->can_be_constant(), "method data oops should be tenured");
     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
     return arr;
   } else {
@@ -2427,8 +2433,9 @@
     ciKlass *klass = o->klass();
     if (klass->is_instance_klass()) {
       // Element is an instance
-      if (!o->has_encoding()) {  // not a perm-space constant
-        // %%% remove this restriction by rewriting non-perm ConPNodes in a later phase
+      if (require_constant) {
+        if (!o->can_be_constant())  return NULL;
+      } else if (!o->should_be_constant()) {
         return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
       }
       return TypeInstPtr::make(o);
@@ -2440,8 +2447,9 @@
       // We used to pass NotNull in here, asserting that the sub-arrays
       // are all not-null.  This is not true in generally, as code can
       // slam NULLs down in the subarrays.
-      if (!o->has_encoding()) {  // not a perm-space constant
-        // %%% remove this restriction by rewriting non-perm ConPNodes in a later phase
+      if (require_constant) {
+        if (!o->can_be_constant())  return NULL;
+      } else if (!o->should_be_constant()) {
         return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
       }
       const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
@@ -2453,8 +2461,9 @@
       const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
       // We used to pass NotNull in here, asserting that the array pointer
       // is not-null. That was not true in general.
-      if (!o->has_encoding()) {  // not a perm-space constant
-        // %%% remove this restriction by rewriting non-perm ConPNodes in a later phase
+      if (require_constant) {
+        if (!o->can_be_constant())  return NULL;
+      } else if (!o->should_be_constant()) {
         return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
       }
       const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
@@ -2483,7 +2492,7 @@
     ShouldNotReachHere();
   }
 
-  return (intptr_t)const_oop()->encoding();
+  return (intptr_t)const_oop()->constant_encoding();
 }
 
 
@@ -2591,7 +2600,7 @@
 
 //------------------------------add_offset-------------------------------------
 const TypePtr *TypeOopPtr::add_offset( intptr_t offset ) const {
-  return make( _ptr, xadd_offset(offset) );
+  return make( _ptr, xadd_offset(offset), _instance_id);
 }
 
 //------------------------------meet_instance_id--------------------------------
@@ -2694,6 +2703,7 @@
 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
     int off = meet_offset(tinst->offset());
     PTR ptr = meet_ptr(tinst->ptr());
+    int instance_id = meet_instance_id(tinst->instance_id());
 
     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
@@ -2714,7 +2724,7 @@
       assert(loaded->ptr() != TypePtr::Null, "insanity check");
       //
       if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
-      else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make( ptr, unloaded->klass() ); }
+      else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make( ptr, unloaded->klass(), false, NULL, off, instance_id ); }
       else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
       else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
         if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
@@ -3338,14 +3348,19 @@
       ciObject* o = const_oop();
       if( _ptr == Constant ) {
         if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
+          xk = (klass() == tap->klass());
           ptr = NotNull;
           o = NULL;
           instance_id = InstanceBot;
+        } else {
+          xk = true;
         }
       } else if( above_centerline(_ptr) ) {
         o = tap->const_oop();
+        xk = true;
+      } else {
+        xk = this->_klass_is_exact;
       }
-      xk = true;
       return TypeAryPtr::make( ptr, o, tary, tap->_klass, xk, off, instance_id );
     }
     case NotNull:
--- a/hotspot/src/share/vm/opto/type.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/opto/type.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -711,10 +711,13 @@
     return make_from_klass_common(klass, false, false);
   }
   // Creates a singleton type given an object.
-  static const TypeOopPtr* make_from_constant(ciObject* o);
+  // If the object cannot be rendered as a constant,
+  // may return a non-singleton type.
+  // If require_constant, produce a NULL if a singleton is not possible.
+  static const TypeOopPtr* make_from_constant(ciObject* o, bool require_constant = false);
 
   // Make a generic (unclassed) pointer to an oop.
-  static const TypeOopPtr* make(PTR ptr, int offset, int instance_id = InstanceBot);
+  static const TypeOopPtr* make(PTR ptr, int offset, int instance_id);
 
   ciObject* const_oop()    const { return _const_oop; }
   virtual ciKlass* klass() const { return _klass;     }
--- a/hotspot/src/share/vm/prims/jvmtiTagMap.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/prims/jvmtiTagMap.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -3126,6 +3126,12 @@
   // exceptions) will be visible.
   blk.set_kind(JVMTI_HEAP_REFERENCE_OTHER);
   Universe::oops_do(&blk);
+
+  // If there are any non-perm roots in the code cache, visit them.
+  blk.set_kind(JVMTI_HEAP_REFERENCE_OTHER);
+  CodeBlobToOopClosure look_in_blobs(&blk, false);
+  CodeCache::scavenge_root_nmethods_do(&look_in_blobs);
+
   return true;
 }
 
--- a/hotspot/src/share/vm/runtime/arguments.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/runtime/arguments.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -2648,16 +2648,22 @@
 
   if (EnableInvokeDynamic && !EnableMethodHandles) {
     if (!FLAG_IS_DEFAULT(EnableMethodHandles)) {
-      warning("forcing EnableMethodHandles true to allow EnableInvokeDynamic");
+      warning("forcing EnableMethodHandles true because EnableInvokeDynamic is true");
     }
     EnableMethodHandles = true;
   }
   if (EnableMethodHandles && !AnonymousClasses) {
     if (!FLAG_IS_DEFAULT(AnonymousClasses)) {
-      warning("forcing AnonymousClasses true to enable EnableMethodHandles");
+      warning("forcing AnonymousClasses true because EnableMethodHandles is true");
     }
     AnonymousClasses = true;
   }
+  if ((EnableMethodHandles || AnonymousClasses) && ScavengeRootsInCode == 0) {
+    if (!FLAG_IS_DEFAULT(ScavengeRootsInCode)) {
+      warning("forcing ScavengeRootsInCode non-zero because EnableMethodHandles or AnonymousClasses is true");
+    }
+    ScavengeRootsInCode = 1;
+  }
 
   if (PrintGCDetails) {
     // Turn on -verbose:gc options as well
--- a/hotspot/src/share/vm/runtime/frame.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/runtime/frame.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -1043,7 +1043,7 @@
   finder.oops_do();
 }
 
-void frame::oops_code_blob_do(OopClosure* f, const RegisterMap* reg_map) {
+void frame::oops_code_blob_do(OopClosure* f, CodeBlobClosure* cf, const RegisterMap* reg_map) {
   assert(_cb != NULL, "sanity check");
   if (_cb->oop_maps() != NULL) {
     OopMapSet::oops_do(this, reg_map, f);
@@ -1058,21 +1058,9 @@
   // oops referenced from nmethods active on thread stacks so as to
   // prevent them from being collected. However, this visit should be
   // restricted to certain phases of the collection only. The
-  // closure answers whether it wants nmethods to be traced.
-  // (All CodeBlob subtypes other than NMethod currently have
-  // an empty oops_do() method.
-  if (f->do_nmethods()) {
-    _cb->oops_do(f);
-  }
-}
-
-void frame::nmethods_code_blob_do() {
-  assert(_cb != NULL, "sanity check");
-
-  // If we see an activation belonging to a non_entrant nmethod, we mark it.
-  if (_cb->is_nmethod() && ((nmethod *)_cb)->is_not_entrant()) {
-    ((nmethod*)_cb)->mark_as_seen_on_stack();
-  }
+  // closure decides how it wants nmethods to be traced.
+  if (cf != NULL)
+    cf->do_code_blob(_cb);
 }
 
 class CompiledArgumentOopFinder: public SignatureInfo {
@@ -1201,18 +1189,18 @@
 }
 
 
-void frame::oops_do_internal(OopClosure* f, RegisterMap* map, bool use_interpreter_oop_map_cache) {
+void frame::oops_do_internal(OopClosure* f, CodeBlobClosure* cf, RegisterMap* map, bool use_interpreter_oop_map_cache) {
          if (is_interpreted_frame())    { oops_interpreted_do(f, map, use_interpreter_oop_map_cache);
   } else if (is_entry_frame())          { oops_entry_do      (f, map);
-  } else if (CodeCache::contains(pc())) { oops_code_blob_do  (f, map);
+  } else if (CodeCache::contains(pc())) { oops_code_blob_do  (f, cf, map);
   } else {
     ShouldNotReachHere();
   }
 }
 
-void frame::nmethods_do() {
+void frame::nmethods_do(CodeBlobClosure* cf) {
   if (_cb != NULL && _cb->is_nmethod()) {
-    nmethods_code_blob_do();
+    cf->do_code_blob(_cb);
   }
 }
 
@@ -1358,7 +1346,7 @@
     }
   }
   COMPILER2_PRESENT(assert(DerivedPointerTable::is_empty(), "must be empty before verify");)
-  oops_do_internal(&VerifyOopClosure::verify_oop, (RegisterMap*)map, false);
+  oops_do_internal(&VerifyOopClosure::verify_oop, NULL, (RegisterMap*)map, false);
 }
 
 
--- a/hotspot/src/share/vm/runtime/frame.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/runtime/frame.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -384,16 +384,14 @@
   void oops_interpreted_arguments_do(symbolHandle signature, bool is_static, OopClosure* f);
 
   // Iteration of oops
-  void oops_do_internal(OopClosure* f, RegisterMap* map, bool use_interpreter_oop_map_cache);
+  void oops_do_internal(OopClosure* f, CodeBlobClosure* cf, RegisterMap* map, bool use_interpreter_oop_map_cache);
   void oops_entry_do(OopClosure* f, const RegisterMap* map);
-  void oops_code_blob_do(OopClosure* f, const RegisterMap* map);
+  void oops_code_blob_do(OopClosure* f, CodeBlobClosure* cf, const RegisterMap* map);
   int adjust_offset(methodOop method, int index); // helper for above fn
-  // Iteration of nmethods
-  void nmethods_code_blob_do();
  public:
   // Memory management
-  void oops_do(OopClosure* f, RegisterMap* map) { oops_do_internal(f, map, true); }
-  void nmethods_do();
+  void oops_do(OopClosure* f, CodeBlobClosure* cf, RegisterMap* map) { oops_do_internal(f, cf, map, true); }
+  void nmethods_do(CodeBlobClosure* cf);
 
   void gc_prologue();
   void gc_epilogue();
--- a/hotspot/src/share/vm/runtime/globals.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/runtime/globals.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -714,6 +714,11 @@
   diagnostic(bool, TraceNMethodInstalls, false,                             \
              "Trace nmethod intallation")                                   \
                                                                             \
+  diagnostic(intx, ScavengeRootsInCode, 0,                                  \
+             "0: do not allow scavengable oops in the code cache; "         \
+             "1: allow scavenging from the code cache; "                    \
+             "2: emit as many constants as the compiler can see")           \
+                                                                            \
   diagnostic(bool, TraceOSRBreakpoint, false,                               \
              "Trace OSR Breakpoint ")                                       \
                                                                             \
--- a/hotspot/src/share/vm/runtime/sweeper.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/runtime/sweeper.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -34,6 +34,17 @@
 jint      NMethodSweeper::_not_entrant_seen_on_stack = 0;
 bool      NMethodSweeper::_rescan = false;
 
+class MarkActivationClosure: public CodeBlobClosure {
+public:
+  virtual void do_code_blob(CodeBlob* cb) {
+    // If we see an activation belonging to a non_entrant nmethod, we mark it.
+    if (cb->is_nmethod() && ((nmethod*)cb)->is_not_entrant()) {
+      ((nmethod*)cb)->mark_as_seen_on_stack();
+    }
+  }
+};
+static MarkActivationClosure mark_activation_closure;
+
 void NMethodSweeper::sweep() {
   assert(SafepointSynchronize::is_at_safepoint(), "must be executed at a safepoint");
   if (!MethodFlushing) return;
@@ -57,7 +68,7 @@
     if (PrintMethodFlushing) {
       tty->print_cr("### Sweep: stack traversal %d", _traversals);
     }
-    Threads::nmethods_do();
+    Threads::nmethods_do(&mark_activation_closure);
 
     // reset the flags since we started a scan from the beginning.
     _rescan = false;
--- a/hotspot/src/share/vm/runtime/thread.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/runtime/thread.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -683,14 +683,15 @@
   return false;
 }
 
-void Thread::oops_do(OopClosure* f) {
+void Thread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
   active_handles()->oops_do(f);
   // Do oop for ThreadShadow
   f->do_oop((oop*)&_pending_exception);
   handle_area()->oops_do(f);
 }
 
-void Thread::nmethods_do() {
+void Thread::nmethods_do(CodeBlobClosure* cf) {
+  // no nmethods in a generic thread...
 }
 
 void Thread::print_on(outputStream* st) const {
@@ -2316,12 +2317,12 @@
 }
 
 
-void JavaThread::oops_do(OopClosure* f) {
+void JavaThread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
   // The ThreadProfiler oops_do is done from FlatProfiler::oops_do
   // since there may be more than one thread using each ThreadProfiler.
 
   // Traverse the GCHandles
-  Thread::oops_do(f);
+  Thread::oops_do(f, cf);
 
   assert( (!has_last_Java_frame() && java_call_counter() == 0) ||
           (has_last_Java_frame() && java_call_counter() > 0), "wrong java_sp info!");
@@ -2347,7 +2348,7 @@
 
     // Traverse the execution stack
     for(StackFrameStream fst(this); !fst.is_done(); fst.next()) {
-      fst.current()->oops_do(f, fst.register_map());
+      fst.current()->oops_do(f, cf, fst.register_map());
     }
   }
 
@@ -2379,9 +2380,8 @@
   }
 }
 
-void JavaThread::nmethods_do() {
-  // Traverse the GCHandles
-  Thread::nmethods_do();
+void JavaThread::nmethods_do(CodeBlobClosure* cf) {
+  Thread::nmethods_do(cf);  // (super method is a no-op)
 
   assert( (!has_last_Java_frame() && java_call_counter() == 0) ||
           (has_last_Java_frame() && java_call_counter() > 0), "wrong java_sp info!");
@@ -2389,7 +2389,7 @@
   if (has_last_Java_frame()) {
     // Traverse the execution stack
     for(StackFrameStream fst(this); !fst.is_done(); fst.next()) {
-      fst.current()->nmethods_do();
+      fst.current()->nmethods_do(cf);
     }
   }
 }
@@ -2463,7 +2463,7 @@
 
 void JavaThread::verify() {
   // Verify oops in the thread.
-  oops_do(&VerifyOopClosure::verify_oop);
+  oops_do(&VerifyOopClosure::verify_oop, NULL);
 
   // Verify the stack frames.
   frames_do(frame_verify);
@@ -3602,14 +3602,14 @@
 // uses the Threads_lock to gurantee this property. It also makes sure that
 // all threads gets blocked when exiting or starting).
 
-void Threads::oops_do(OopClosure* f) {
+void Threads::oops_do(OopClosure* f, CodeBlobClosure* cf) {
   ALL_JAVA_THREADS(p) {
-    p->oops_do(f);
+    p->oops_do(f, cf);
   }
-  VMThread::vm_thread()->oops_do(f);
+  VMThread::vm_thread()->oops_do(f, cf);
 }
 
-void Threads::possibly_parallel_oops_do(OopClosure* f) {
+void Threads::possibly_parallel_oops_do(OopClosure* f, CodeBlobClosure* cf) {
   // Introduce a mechanism allowing parallel threads to claim threads as
   // root groups.  Overhead should be small enough to use all the time,
   // even in sequential code.
@@ -3618,12 +3618,12 @@
   int cp = SharedHeap::heap()->strong_roots_parity();
   ALL_JAVA_THREADS(p) {
     if (p->claim_oops_do(is_par, cp)) {
-      p->oops_do(f);
+      p->oops_do(f, cf);
     }
   }
   VMThread* vmt = VMThread::vm_thread();
   if (vmt->claim_oops_do(is_par, cp))
-    vmt->oops_do(f);
+    vmt->oops_do(f, cf);
 }
 
 #ifndef SERIALGC
@@ -3644,11 +3644,11 @@
 }
 #endif // SERIALGC
 
-void Threads::nmethods_do() {
+void Threads::nmethods_do(CodeBlobClosure* cf) {
   ALL_JAVA_THREADS(p) {
-    p->nmethods_do();
+    p->nmethods_do(cf);
   }
-  VMThread::vm_thread()->nmethods_do();
+  VMThread::vm_thread()->nmethods_do(cf);
 }
 
 void Threads::gc_epilogue() {
--- a/hotspot/src/share/vm/runtime/thread.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/runtime/thread.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -374,7 +374,8 @@
 
   // GC support
   // Apply "f->do_oop" to all root oops in "this".
-  void oops_do(OopClosure* f);
+  // Apply "cf->do_code_blob" (if !NULL) to all code blobs active in frames
+  void oops_do(OopClosure* f, CodeBlobClosure* cf);
 
   // Handles the parallel case for the method below.
 private:
@@ -398,7 +399,7 @@
   }
 
   // Sweeper support
-  void nmethods_do();
+  void nmethods_do(CodeBlobClosure* cf);
 
   // Tells if adr belong to this thread. This is used
   // for checking if a lock is owned by the running thread.
@@ -1229,10 +1230,10 @@
   void frames_do(void f(frame*, const RegisterMap*));
 
   // Memory operations
-  void oops_do(OopClosure* f);
+  void oops_do(OopClosure* f, CodeBlobClosure* cf);
 
   // Sweeper operations
-  void nmethods_do();
+  void nmethods_do(CodeBlobClosure* cf);
 
   // Memory management operations
   void gc_epilogue();
@@ -1620,9 +1621,9 @@
 
   // Apply "f->do_oop" to all root oops in all threads.
   // This version may only be called by sequential code.
-  static void oops_do(OopClosure* f);
+  static void oops_do(OopClosure* f, CodeBlobClosure* cf);
   // This version may be called by sequential or parallel code.
-  static void possibly_parallel_oops_do(OopClosure* f);
+  static void possibly_parallel_oops_do(OopClosure* f, CodeBlobClosure* cf);
   // This creates a list of GCTasks, one per thread.
   static void create_thread_roots_tasks(GCTaskQueue* q);
   // This creates a list of GCTasks, one per thread, for marking objects.
@@ -1630,13 +1631,13 @@
 
   // Apply "f->do_oop" to roots in all threads that
   // are part of compiled frames
-  static void compiled_frame_oops_do(OopClosure* f);
+  static void compiled_frame_oops_do(OopClosure* f, CodeBlobClosure* cf);
 
   static void convert_hcode_pointers();
   static void restore_hcode_pointers();
 
   // Sweeper
-  static void nmethods_do();
+  static void nmethods_do(CodeBlobClosure* cf);
 
   static void gc_epilogue();
   static void gc_prologue();
--- a/hotspot/src/share/vm/runtime/vmStructs.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/runtime/vmStructs.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -549,6 +549,7 @@
   /********************************/                                                                                                 \
                                                                                                                                      \
      static_field(CodeCache,                   _heap,                                         CodeHeap*)                             \
+     static_field(CodeCache,                   _scavenge_root_nmethods,                       nmethod*)                              \
                                                                                                                                      \
   /*******************************/                                                                                                  \
   /* CodeHeap (NOTE: incomplete) */                                                                                                  \
@@ -618,7 +619,9 @@
      static_field(nmethod,             _zombie_instruction_size,                      int)                                   \
   nonstatic_field(nmethod,             _method,                                       methodOop)                             \
   nonstatic_field(nmethod,             _entry_bci,                                    int)                                   \
-  nonstatic_field(nmethod,             _link,                                         nmethod*)                              \
+  nonstatic_field(nmethod,             _osr_link,                                     nmethod*)                              \
+  nonstatic_field(nmethod,             _scavenge_root_link,                           nmethod*)                              \
+  nonstatic_field(nmethod,             _scavenge_root_state,                          jbyte)                                 \
   nonstatic_field(nmethod,             _exception_offset,                             int)                                   \
   nonstatic_field(nmethod,             _deoptimize_offset,                            int)                                   \
   nonstatic_field(nmethod,             _orig_pc_offset,                               int)                                   \
--- a/hotspot/src/share/vm/runtime/vmThread.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/runtime/vmThread.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -619,8 +619,8 @@
 }
 
 
-void VMThread::oops_do(OopClosure* f) {
-  Thread::oops_do(f);
+void VMThread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
+  Thread::oops_do(f, cf);
   _vm_queue->oops_do(f);
 }
 
@@ -652,5 +652,5 @@
 #endif
 
 void VMThread::verify() {
-  oops_do(&VerifyOopClosure::verify_oop);
+  oops_do(&VerifyOopClosure::verify_oop, NULL);
 }
--- a/hotspot/src/share/vm/runtime/vmThread.hpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/runtime/vmThread.hpp	Fri Oct 16 18:02:31 2009 -0700
@@ -121,7 +121,7 @@
   static VMThread* vm_thread()                    { return _vm_thread; }
 
   // GC support
-  void oops_do(OopClosure* f);
+  void oops_do(OopClosure* f, CodeBlobClosure* cf);
 
   // Debugging
   void print_on(outputStream* st) const;
--- a/hotspot/src/share/vm/utilities/debug.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/src/share/vm/utilities/debug.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -702,11 +702,14 @@
   tty->print_cr("Searching strong roots:");
   Universe::oops_do(&lookFor, false);
   JNIHandles::oops_do(&lookFor);   // Global (strong) JNI handles
-  Threads::oops_do(&lookFor);
+  Threads::oops_do(&lookFor, NULL);
   ObjectSynchronizer::oops_do(&lookFor);
   //FlatProfiler::oops_do(&lookFor);
   SystemDictionary::oops_do(&lookFor);
 
+  tty->print_cr("Searching code cache:");
+  CodeCache::oops_do(&lookFor);
+
   tty->print_cr("Done.");
 }
 
--- a/hotspot/test/compiler/6823453/Test.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/test/compiler/6823453/Test.java	Fri Oct 16 18:02:31 2009 -0700
@@ -26,7 +26,7 @@
  * @test
  * @bug 6823453
  * @summary DeoptimizeALot causes fastdebug server jvm to fail with assert(false,"unscheduable graph")
- * @run main/othervm -Xcomp -XX:CompileOnly=Test -XX:+DeoptimizeALot Test
+ * @run main/othervm -Xcomp -XX:+IgnoreUnrecognizedVMOptions -XX:CompileOnly=Test -XX:+DeoptimizeALot Test
  */
 
 public class Test {
--- a/hotspot/test/compiler/6833129/Test.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/hotspot/test/compiler/6833129/Test.java	Fri Oct 16 18:02:31 2009 -0700
@@ -25,7 +25,7 @@
  * @test
  * @bug 6833129
  * @summary Object.clone() and Arrays.copyOf ignore coping with -XX:+DeoptimizeALot
- * @run main/othervm -Xbatch -XX:+DeoptimizeALot Test
+ * @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:+DeoptimizeALot Test
  */
 
 public class Test{
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/6875866/Test.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6875866
+ * @summary Intrinsic for String.indexOf() is broken on x86 with SSE4.2
+ *
+ * @run main/othervm -Xcomp Test
+ */
+
+public class Test {
+
+  static int IndexOfTest(String str) {
+    return str.indexOf("11111xx1x");
+  }
+
+  public static void main(String args[]) {
+    String str = "11111xx11111xx1x";
+    int idx = IndexOfTest(str);
+    System.out.println("IndexOf = " + idx);
+    if (idx != 7) {
+      System.exit(97);
+    }
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/6877254/Test.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6877254
+ * @summary Implement StoreCMNode::Ideal to promote its OopStore above the MergeMem
+ *
+ * @run main/othervm -server -Xcomp -XX:+UseConcMarkSweepGC Test
+ */
+
+public class Test {
+    static byte var_1;
+    static String var_2 = "";
+    static byte var_3;
+    static float var_4 = 0;
+
+    public static void main(String[] args) {
+        int i = 0;
+
+        for (String var_tmp = var_2; i < 11; var_1 = 0, i++) {
+            var_2 = var_2;
+            var_4 *= (var_4 *= (var_3 = 0));
+        }
+
+        System.out.println("var_1 = " + var_1);
+        System.out.println("var_2 = " + var_2);
+        System.out.println("var_3 = " + var_3);
+        System.out.println("var_4 = " + var_4);
+    }
+}
--- a/jaxp/.hgtags	Fri Oct 16 09:32:29 2009 -0700
+++ b/jaxp/.hgtags	Fri Oct 16 18:02:31 2009 -0700
@@ -47,3 +47,4 @@
 c83f0106b78a85c7e614d27a328675460b2081cf jdk7-b70
 ff94d8ce0daded647bb326630e643d010357afce jdk7-b71
 37c805b6156fd492c12301688b54a6bcca39e729 jdk7-b72
+feb05980f9f2964e6bc2b3a8532f9b3054c2289b jdk7-b73
--- a/jaxws/.hgtags	Fri Oct 16 09:32:29 2009 -0700
+++ b/jaxws/.hgtags	Fri Oct 16 18:02:31 2009 -0700
@@ -47,3 +47,4 @@
 dd3c5f3ec28d5d5e5c0dc3229fdd52d85d04274d jdk7-b70
 03314cf56a7212bbb6c186dbc9f15aca988a48ec jdk7-b71
 4c990aa99bc037fd81dd1b1b269690e9bea8a0b4 jdk7-b72
+558985e26fe16f5a6ebb2edb9180a42e1c8e8202 jdk7-b73
--- a/jdk/.hgtags	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/.hgtags	Fri Oct 16 18:02:31 2009 -0700
@@ -47,3 +47,5 @@
 893bcca951b747ddcf6986362b877f0e1dbb835b jdk7-b70
 b3f3240135f0c10b9f2481c174b81b7fcf0daa60 jdk7-b71
 460639b036f327282832a4fe52b7aa45688afd50 jdk7-b72
+f708138c9aca4b389872838fe6773872fce3609e jdk7-b73
+eacb36e30327e7ae33baa068e82ddccbd91eaae2 jdk7-b74
--- a/jdk/make/common/shared/Defs-java.gmk	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/make/common/shared/Defs-java.gmk	Fri Oct 16 18:02:31 2009 -0700
@@ -165,6 +165,11 @@
   JAVADOC_CMD   = $(JAVA_TOOLS_DIR)/javadoc $(JAVA_TOOLS_FLAGS:%=-J%)
 endif
 
+#always use the bootstrap javah until bug-ID 6889255 is fixed.  These
+#five lines should be removed as part of that fix:
+JAVAH_CMD     = $(JAVA_TOOLS_DIR)/javah \
+		  $(JAVAHFLAGS)
+
 # Override of what javac to use (see deploy workspace)
 ifdef JAVAC
   JAVAC_CMD     = $(JAVAC)
--- a/jdk/make/sun/jkernel/Makefile	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/make/sun/jkernel/Makefile	Fri Oct 16 18:02:31 2009 -0700
@@ -35,10 +35,6 @@
 #
 _OPT = $(CC_HIGHEST_OPT)
 
-# This re-directs all the class files to a separate location
-CLASSDESTDIR = $(TEMPDIR)/classes
-
-
 #
 # Java source files
 #
--- a/jdk/src/share/classes/com/sun/net/ssl/internal/www/protocol/https/DelegateHttpsURLConnection.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/com/sun/net/ssl/internal/www/protocol/https/DelegateHttpsURLConnection.java	Fri Oct 16 18:02:31 2009 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001-2005 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2001-2009 Sun Microsystems, Inc.  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
@@ -116,7 +116,10 @@
         try {
             String serverName;
             Principal principal = getPeerPrincipal(session);
-            if (principal instanceof KerberosPrincipal) {
+            // X.500 principal or Kerberos principal.
+            // (Use ciphersuite check to determine whether Kerberos is present.)
+            if (session.getCipherSuite().startsWith("TLS_KRB5") &&
+                    principal instanceof KerberosPrincipal) {
                 serverName =
                     HostnameChecker.getServerName((KerberosPrincipal)principal);
             } else {
--- a/jdk/src/share/classes/java/awt/Component.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/awt/Component.java	Fri Oct 16 18:02:31 2009 -0700
@@ -94,7 +94,17 @@
  * the nonmenu-related Abstract Window Toolkit components. Class
  * <code>Component</code> can also be extended directly to create a
  * lightweight component. A lightweight component is a component that is
- * not associated with a native opaque window.
+ * not associated with a native window. On the contrary, a heavyweight
+ * component is associated with a native window. The {@link #isLightweight()}
+ * method may be used to distinguish between the two kinds of the components.
+ * <p>
+ * Lightweight and heavyweight components may be mixed in a single component
+ * hierarchy. However, for correct operating of such a mixed hierarchy of
+ * components, the whole hierarchy must be valid. When the hierarchy gets
+ * invalidated, like after changing the bounds of components, or
+ * adding/removing components to/from containers, the whole hierarchy must be
+ * validated afterwards by means of the {@link Container#validate()} method
+ * invoked on the top-most invalid container of the hierarchy.
  * <p>
  * <h3>Serialization</h3>
  * It is important to note that only AWT listeners which conform
@@ -1492,9 +1502,14 @@
     /**
      * Shows or hides this component depending on the value of parameter
      * <code>b</code>.
+     * <p>
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy.
+     *
      * @param b  if <code>true</code>, shows this component;
      * otherwise, hides this component
      * @see #isVisible
+     * @see #invalidate
      * @since JDK1.1
      */
     public void setVisible(boolean b) {
@@ -1753,10 +1768,15 @@
 
     /**
      * Sets the font of this component.
+     * <p>
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy.
+     *
      * @param f the font to become this component's font;
      *          if this parameter is <code>null</code> then this
      *          component will inherit the font of its parent
      * @see #getFont
+     * @see #invalidate
      * @since JDK1.0
      * @beaninfo
      *       bound: true
@@ -1830,8 +1850,13 @@
 
     /**
      * Sets the locale of this component.  This is a bound property.
+     * <p>
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy.
+     *
      * @param l the locale to become this component's locale
      * @see #getLocale
+     * @see #invalidate
      * @since JDK1.1
      */
     public void setLocale(Locale l) {
@@ -1951,12 +1976,17 @@
      * Moves this component to a new location. The top-left corner of
      * the new location is specified by the <code>x</code> and <code>y</code>
      * parameters in the coordinate space of this component's parent.
+     * <p>
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy.
+     *
      * @param x the <i>x</i>-coordinate of the new location's
      *          top-left corner in the parent's coordinate space
      * @param y the <i>y</i>-coordinate of the new location's
      *          top-left corner in the parent's coordinate space
      * @see #getLocation
      * @see #setBounds
+     * @see #invalidate
      * @since JDK1.1
      */
     public void setLocation(int x, int y) {
@@ -1979,11 +2009,16 @@
      * Moves this component to a new location. The top-left corner of
      * the new location is specified by point <code>p</code>. Point
      * <code>p</code> is given in the parent's coordinate space.
+     * <p>
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy.
+     *
      * @param p the point defining the top-left corner
      *          of the new location, given in the coordinate space of this
      *          component's parent
      * @see #getLocation
      * @see #setBounds
+     * @see #invalidate
      * @since JDK1.1
      */
     public void setLocation(Point p) {
@@ -2018,10 +2053,15 @@
     /**
      * Resizes this component so that it has width <code>width</code>
      * and height <code>height</code>.
+     * <p>
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy.
+     *
      * @param width the new width of this component in pixels
      * @param height the new height of this component in pixels
      * @see #getSize
      * @see #setBounds
+     * @see #invalidate
      * @since JDK1.1
      */
     public void setSize(int width, int height) {
@@ -2043,10 +2083,15 @@
     /**
      * Resizes this component so that it has width <code>d.width</code>
      * and height <code>d.height</code>.
+     * <p>
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy.
+     *
      * @param d the dimension specifying the new size
      *          of this component
      * @see #setSize
      * @see #setBounds
+     * @see #invalidate
      * @since JDK1.1
      */
     public void setSize(Dimension d) {
@@ -2089,6 +2134,10 @@
      * Moves and resizes this component. The new location of the top-left
      * corner is specified by <code>x</code> and <code>y</code>, and the
      * new size is specified by <code>width</code> and <code>height</code>.
+     * <p>
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy.
+     *
      * @param x the new <i>x</i>-coordinate of this component
      * @param y the new <i>y</i>-coordinate of this component
      * @param width the new <code>width</code> of this component
@@ -2099,6 +2148,7 @@
      * @see #setLocation(Point)
      * @see #setSize(int, int)
      * @see #setSize(Dimension)
+     * @see #invalidate
      * @since JDK1.1
      */
     public void setBounds(int x, int y, int width, int height) {
@@ -2231,12 +2281,17 @@
      * position is specified by <code>r.x</code> and <code>r.y</code>,
      * and its new size is specified by <code>r.width</code> and
      * <code>r.height</code>
+     * <p>
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy.
+     *
      * @param r the new bounding rectangle for this component
      * @see       #getBounds
      * @see       #setLocation(int, int)
      * @see       #setLocation(Point)
      * @see       #setSize(int, int)
      * @see       #setSize(Dimension)
+     * @see #invalidate
      * @since     JDK1.1
      */
     public void setBounds(Rectangle r) {
@@ -6625,8 +6680,13 @@
      * native screen resource.
      * This method is called internally by the toolkit and should
      * not be called directly by programs.
+     * <p>
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy.
+     *
      * @see       #isDisplayable
      * @see       #removeNotify
+     * @see #invalidate
      * @since JDK1.0
      */
     public void addNotify() {
@@ -8593,8 +8653,13 @@
      * To set the orientation of an entire component
      * hierarchy, use
      * {@link #applyComponentOrientation applyComponentOrientation}.
+     * <p>
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy.
+     *
      *
      * @see ComponentOrientation
+     * @see #invalidate
      *
      * @author Laura Werner, IBM
      * @beaninfo
@@ -8630,12 +8695,17 @@
     /**
      * Sets the <code>ComponentOrientation</code> property of this component
      * and all components contained within it.
+     * <p>
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy.
+     *
      *
      * @param orientation the new component orientation of this component and
      *        the components contained within it.
      * @exception NullPointerException if <code>orientation</code> is null.
      * @see #setComponentOrientation
      * @see #getComponentOrientation
+     * @see #invalidate
      * @since 1.4
      */
     public void applyComponentOrientation(ComponentOrientation orientation) {
--- a/jdk/src/share/classes/java/awt/Container.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/awt/Container.java	Fri Oct 16 18:02:31 2009 -0700
@@ -381,16 +381,15 @@
      * Appends the specified component to the end of this container.
      * This is a convenience method for {@link #addImpl}.
      * <p>
-     * Note: If a component has been added to a container that
-     * has been displayed, <code>validate</code> must be
-     * called on that container to display the new component.
-     * If multiple components are being added, you can improve
-     * efficiency by calling <code>validate</code> only once,
-     * after all the components have been added.
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy. If the container has already been
+     * displayed, the hierarchy must be validated thereafter in order to
+     * display the added component.
      *
      * @param     comp   the component to be added
      * @exception NullPointerException if {@code comp} is {@code null}
      * @see #addImpl
+     * @see #invalidate
      * @see #validate
      * @see javax.swing.JComponent#revalidate()
      * @return    the component argument
@@ -406,8 +405,15 @@
      * <p>
      * This method is obsolete as of 1.1.  Please use the
      * method <code>add(Component, Object)</code> instead.
+     * <p>
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy. If the container has already been
+     * displayed, the hierarchy must be validated thereafter in order to
+     * display the added component.
+     *
      * @exception NullPointerException if {@code comp} is {@code null}
      * @see #add(Component, Object)
+     * @see #invalidate
      */
     public Component add(String name, Component comp) {
         addImpl(comp, name, -1);
@@ -419,12 +425,11 @@
      * position.
      * This is a convenience method for {@link #addImpl}.
      * <p>
-     * Note: If a component has been added to a container that
-     * has been displayed, <code>validate</code> must be
-     * called on that container to display the new component.
-     * If multiple components are being added, you can improve
-     * efficiency by calling <code>validate</code> only once,
-     * after all the components have been added.
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy. If the container has already been
+     * displayed, the hierarchy must be validated thereafter in order to
+     * display the added component.
+     *
      *
      * @param     comp   the component to be added
      * @param     index    the position at which to insert the component,
@@ -435,6 +440,7 @@
      * @return    the component <code>comp</code>
      * @see #addImpl
      * @see #remove
+     * @see #invalidate
      * @see #validate
      * @see javax.swing.JComponent#revalidate()
      */
@@ -700,6 +706,9 @@
      * This property is guaranteed to apply only to lightweight
      * non-<code>Container</code> components.
      * <p>
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy.
+     * <p>
      * <b>Note</b>: Not all platforms support changing the z-order of
      * heavyweight components from one container into another without
      * the call to <code>removeNotify</code>. There is no way to detect
@@ -723,6 +732,7 @@
      * @exception IllegalArgumentException if adding a <code>Window</code>
      *            to a container
      * @see #getComponentZOrder(java.awt.Component)
+     * @see #invalidate
      * @since 1.5
      */
     public void setComponentZOrder(Component comp, int index) {
@@ -923,18 +933,18 @@
      * this container's layout using the specified constraints object.
      * This is a convenience method for {@link #addImpl}.
      * <p>
-     * Note: If a component has been added to a container that
-     * has been displayed, <code>validate</code> must be
-     * called on that container to display the new component.
-     * If multiple components are being added, you can improve
-     * efficiency by calling <code>validate</code> only once,
-     * after all the components have been added.
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy. If the container has already been
+     * displayed, the hierarchy must be validated thereafter in order to
+     * display the added component.
+     *
      *
      * @param     comp the component to be added
      * @param     constraints an object expressing
      *                  layout contraints for this component
      * @exception NullPointerException if {@code comp} is {@code null}
      * @see #addImpl
+     * @see #invalidate
      * @see #validate
      * @see javax.swing.JComponent#revalidate()
      * @see       LayoutManager
@@ -951,12 +961,11 @@
      * the specified constraints object.
      * This is a convenience method for {@link #addImpl}.
      * <p>
-     * Note: If a component has been added to a container that
-     * has been displayed, <code>validate</code> must be
-     * called on that container to display the new component.
-     * If multiple components are being added, you can improve
-     * efficiency by calling <code>validate</code> only once,
-     * after all the components have been added.
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy. If the container has already been
+     * displayed, the hierarchy must be validated thereafter in order to
+     * display the added component.
+     *
      *
      * @param comp the component to be added
      * @param constraints an object expressing layout contraints for this
@@ -967,6 +976,7 @@
      * @exception IllegalArgumentException if {@code index} is invalid (see
      *            {@link #addImpl} for details)
      * @see #addImpl
+     * @see #invalidate
      * @see #validate
      * @see javax.swing.JComponent#revalidate()
      * @see #remove
@@ -1014,6 +1024,11 @@
      * <code>super.addImpl(comp, constraints, index)</code>
      * </blockquote>
      * <p>
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy. If the container has already been
+     * displayed, the hierarchy must be validated thereafter in order to
+     * display the added component.
+     *
      * @param     comp       the component to be added
      * @param     constraints an object expressing layout constraints
      *                 for this component
@@ -1033,6 +1048,7 @@
      * @see       #add(Component)
      * @see       #add(Component, int)
      * @see       #add(Component, java.lang.Object)
+     * @see #invalidate
      * @see       LayoutManager
      * @see       LayoutManager2
      * @since     JDK1.1
@@ -1145,19 +1161,18 @@
      * This method also notifies the layout manager to remove the
      * component from this container's layout via the
      * <code>removeLayoutComponent</code> method.
+     * <p>
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy. If the container has already been
+     * displayed, the hierarchy must be validated thereafter in order to
+     * reflect the changes.
      *
-     * <p>
-     * Note: If a component has been removed from a container that
-     * had been displayed, {@link #validate} must be
-     * called on that container to reflect changes.
-     * If multiple components are being removed, you can improve
-     * efficiency by calling {@link #validate} only once,
-     * after all the components have been removed.
      *
      * @param     index   the index of the component to be removed
      * @throws ArrayIndexOutOfBoundsException if {@code index} is not in
      *         range {@code [0, getComponentCount()-1]}
      * @see #add
+     * @see #invalidate
      * @see #validate
      * @see #getComponentCount
      * @since JDK1.1
@@ -1209,17 +1224,15 @@
      * This method also notifies the layout manager to remove the
      * component from this container's layout via the
      * <code>removeLayoutComponent</code> method.
-     *
      * <p>
-     * Note: If a component has been removed from a container that
-     * had been displayed, {@link #validate} must be
-     * called on that container to reflect changes.
-     * If multiple components are being removed, you can improve
-     * efficiency by calling {@link #validate} only once,
-     * after all the components have been removed.
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy. If the container has already been
+     * displayed, the hierarchy must be validated thereafter in order to
+     * reflect the changes.
      *
      * @param comp the component to be removed
      * @see #add
+     * @see #invalidate
      * @see #validate
      * @see #remove(int)
      */
@@ -1239,8 +1252,15 @@
      * This method also notifies the layout manager to remove the
      * components from this container's layout via the
      * <code>removeLayoutComponent</code> method.
+     * <p>
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy. If the container has already been
+     * displayed, the hierarchy must be validated thereafter in order to
+     * reflect the changes.
+     *
      * @see #add
      * @see #remove
+     * @see #invalidate
      */
     public void removeAll() {
         synchronized (getTreeLock()) {
@@ -1432,9 +1452,14 @@
 
     /**
      * Sets the layout manager for this container.
+     * <p>
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy.
+     *
      * @param mgr the specified layout manager
      * @see #doLayout
      * @see #getLayout
+     * @see #invalidate
      */
     public void setLayout(LayoutManager mgr) {
         layoutMgr = mgr;
@@ -1502,9 +1527,17 @@
      * <p>If this {@code Container} is not valid, this method invokes
      * the {@code validateTree} method and marks this {@code Container}
      * as valid. Otherwise, no action is performed.
+     * <p>
+     * Note that the {@code invalidate()} method may invalidate not only the
+     * component it is called upon, but also the parents of the component.
+     * Therefore, to restore the validity of the hierarchy, the {@code
+     * validate()} method must be invoked on the top-most invalid container of
+     * the hierarchy. For performance reasons a developer may postpone the
+     * validation of the hierarchy till a bunch of layout-related operations
+     * completes, e.g. after adding all the children to the container.
      *
      * @see #add(java.awt.Component)
-     * @see Component#invalidate
+     * @see #invalidate
      * @see javax.swing.JComponent#revalidate()
      * @see #validateTree
      */
@@ -1588,8 +1621,13 @@
 
     /**
      * Sets the font of this container.
+     * <p>
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy.
+     *
      * @param f The font to become this container's font.
      * @see Component#getFont
+     * @see #invalidate
      * @since JDK1.0
      */
     public void setFont(Font f) {
@@ -3386,12 +3424,16 @@
     /**
      * Sets the <code>ComponentOrientation</code> property of this container
      * and all components contained within it.
+     * <p>
+     * This method changes layout-related information, and therefore,
+     * invalidates the component hierarchy.
      *
      * @param o the new component orientation of this container and
      *        the components contained within it.
      * @exception NullPointerException if <code>orientation</code> is null.
      * @see Component#setComponentOrientation
      * @see Component#getComponentOrientation
+     * @see #invalidate
      * @since 1.4
      */
     public void applyComponentOrientation(ComponentOrientation o) {
@@ -4069,16 +4111,16 @@
                 mixingLog.fine("this = " + this);
             }
 
-            if (!isMixingNeeded()) {
-                return;
-            }
-
             boolean isLightweight = isLightweight();
 
             if (isLightweight && isRecursivelyVisibleUpToHeavyweightContainer()) {
                 recursiveShowHeavyweightChildren();
             }
 
+            if (!isMixingNeeded()) {
+                return;
+            }
+
             if (!isLightweight || (isLightweight && hasHeavyweightDescendants())) {
                 recursiveApplyCurrentShape();
             }
--- a/jdk/src/share/classes/java/awt/Dialog.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/awt/Dialog.java	Fri Oct 16 18:02:31 2009 -0700
@@ -856,7 +856,7 @@
         if (type == ModalityType.TOOLKIT_MODAL) {
             SecurityManager sm = System.getSecurityManager();
             if (sm != null) {
-                sm.checkPermission(SecurityConstants.TOOLKIT_MODALITY_PERMISSION);
+                sm.checkPermission(SecurityConstants.AWT.TOOLKIT_MODALITY_PERMISSION);
             }
         }
         modalityType = type;
--- a/jdk/src/share/classes/java/awt/EventQueue.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/awt/EventQueue.java	Fri Oct 16 18:02:31 2009 -0700
@@ -843,7 +843,8 @@
 
     final void initDispatchThread() {
         synchronized (this) {
-            if (dispatchThread == null && !threadGroup.isDestroyed()) {
+            AppContext appContext = AppContext.getAppContext();
+            if (dispatchThread == null && !threadGroup.isDestroyed() && !appContext.isDisposed()) {
                 dispatchThread = (EventDispatchThread)
                     AccessController.doPrivileged(new PrivilegedAction() {
                         public Object run() {
--- a/jdk/src/share/classes/java/awt/MouseInfo.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/awt/MouseInfo.java	Fri Oct 16 18:02:31 2009 -0700
@@ -76,7 +76,7 @@
 
         SecurityManager security = System.getSecurityManager();
         if (security != null) {
-            security.checkPermission(SecurityConstants.WATCH_MOUSE_PERMISSION);
+            security.checkPermission(SecurityConstants.AWT.WATCH_MOUSE_PERMISSION);
         }
 
         Point point = new Point(0, 0);
--- a/jdk/src/share/classes/java/awt/Robot.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/awt/Robot.java	Fri Oct 16 18:02:31 2009 -0700
@@ -167,7 +167,7 @@
     private void checkRobotAllowed() {
         SecurityManager security = System.getSecurityManager();
         if (security != null) {
-            security.checkPermission(SecurityConstants.CREATE_ROBOT_PERMISSION);
+            security.checkPermission(SecurityConstants.AWT.CREATE_ROBOT_PERMISSION);
         }
     }
 
@@ -466,7 +466,7 @@
         SecurityManager security = System.getSecurityManager();
         if (security != null) {
             security.checkPermission(
-                SecurityConstants.READ_DISPLAY_PIXELS_PERMISSION);
+                SecurityConstants.AWT.READ_DISPLAY_PIXELS_PERMISSION);
         }
     }
 
--- a/jdk/src/share/classes/java/awt/SystemTray.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/awt/SystemTray.java	Fri Oct 16 18:02:31 2009 -0700
@@ -490,7 +490,7 @@
     static void checkSystemTrayAllowed() {
         SecurityManager security = System.getSecurityManager();
         if (security != null) {
-            security.checkPermission(SecurityConstants.ACCESS_SYSTEM_TRAY_PERMISSION);
+            security.checkPermission(SecurityConstants.AWT.ACCESS_SYSTEM_TRAY_PERMISSION);
         }
     }
 
--- a/jdk/src/share/classes/java/awt/Toolkit.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/awt/Toolkit.java	Fri Oct 16 18:02:31 2009 -0700
@@ -2025,7 +2025,7 @@
         }
         SecurityManager security = System.getSecurityManager();
         if (security != null) {
-          security.checkPermission(SecurityConstants.ALL_AWT_EVENTS_PERMISSION);
+          security.checkPermission(SecurityConstants.AWT.ALL_AWT_EVENTS_PERMISSION);
         }
         synchronized (this) {
             SelectiveAWTEventListener selectiveListener =
@@ -2094,7 +2094,7 @@
         }
         SecurityManager security = System.getSecurityManager();
         if (security != null) {
-            security.checkPermission(SecurityConstants.ALL_AWT_EVENTS_PERMISSION);
+            security.checkPermission(SecurityConstants.AWT.ALL_AWT_EVENTS_PERMISSION);
         }
 
         synchronized (this) {
@@ -2165,7 +2165,7 @@
     public AWTEventListener[] getAWTEventListeners() {
         SecurityManager security = System.getSecurityManager();
         if (security != null) {
-            security.checkPermission(SecurityConstants.ALL_AWT_EVENTS_PERMISSION);
+            security.checkPermission(SecurityConstants.AWT.ALL_AWT_EVENTS_PERMISSION);
         }
         synchronized (this) {
             EventListener[] la = ToolkitEventMulticaster.getListeners(eventListener,AWTEventListener.class);
@@ -2217,7 +2217,7 @@
     public AWTEventListener[] getAWTEventListeners(long eventMask) {
         SecurityManager security = System.getSecurityManager();
         if (security != null) {
-            security.checkPermission(SecurityConstants.ALL_AWT_EVENTS_PERMISSION);
+            security.checkPermission(SecurityConstants.AWT.ALL_AWT_EVENTS_PERMISSION);
         }
         synchronized (this) {
             EventListener[] la = ToolkitEventMulticaster.getListeners(eventListener,AWTEventListener.class);
--- a/jdk/src/share/classes/java/awt/Window.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/awt/Window.java	Fri Oct 16 18:02:31 2009 -0700
@@ -1580,7 +1580,7 @@
         if (exclusionType == Dialog.ModalExclusionType.TOOLKIT_EXCLUDE) {
             SecurityManager sm = System.getSecurityManager();
             if (sm != null) {
-                sm.checkPermission(SecurityConstants.TOOLKIT_MODALITY_PERMISSION);
+                sm.checkPermission(SecurityConstants.AWT.TOOLKIT_MODALITY_PERMISSION);
             }
         }
         modalExclusionType = exclusionType;
@@ -2128,7 +2128,7 @@
     public final void setAlwaysOnTop(boolean alwaysOnTop) throws SecurityException {
         SecurityManager security = System.getSecurityManager();
         if (security != null) {
-            security.checkPermission(SecurityConstants.SET_WINDOW_ALWAYS_ON_TOP_PERMISSION);
+            security.checkPermission(SecurityConstants.AWT.SET_WINDOW_ALWAYS_ON_TOP_PERMISSION);
         }
 
         boolean oldAlwaysOnTop;
--- a/jdk/src/share/classes/java/awt/color/ICC_Profile.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/awt/color/ICC_Profile.java	Fri Oct 16 18:02:31 2009 -0700
@@ -58,6 +58,8 @@
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 
+import sun.misc.BootClassLoaderHook;
+
 /**
  * A representation of color profile data for device independent and
  * device dependent color spaces based on the International Color
@@ -1850,11 +1852,10 @@
                 f = new File(fullPath);
                 if (!f.isFile()) {
                     //make sure file was installed in the kernel mode
-                    try {
-                        //kernel uses platform independent paths =>
-                        //   should not use platform separator char
-                        sun.jkernel.DownloadManager.downloadFile("lib/cmm/"+fileName);
-                    } catch (IOException ioe) {}
+                    BootClassLoaderHook hook = BootClassLoaderHook.getHook();
+                    if (hook.getHook() != null) {
+                        hook.prefetchFile("lib/cmm/"+fileName);
+                    }
                 }
             }
 
--- a/jdk/src/share/classes/java/lang/Boolean.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/lang/Boolean.java	Fri Oct 16 18:02:31 2009 -0700
@@ -255,7 +255,25 @@
      * @since  1.5
      */
     public int compareTo(Boolean b) {
-        return (b.value == value ? 0 : (value ? 1 : -1));
+        return compare(this.value, b.value);
+    }
+
+    /**
+     * Compares two {@code boolean} values.
+     * The value returned is identical to what would be returned by:
+     * <pre>
+     *    Boolean.valueOf(x).compareTo(Boolean.valueOf(y))
+     * </pre>
+     *
+     * @param  x the first {@code boolean} to compare
+     * @param  y the second {@code boolean} to compare
+     * @return the value {@code 0} if {@code x == y};
+     *         a value less than {@code 0} if {@code !x && y}; and
+     *         a value greater than {@code 0} if {@code x && !y}
+     * @since 1.7
+     */
+    public static int compare(boolean x, boolean y) {
+        return (x == y) ? 0 : (x ? 1 : -1);
     }
 
     private static boolean toBoolean(String name) {
--- a/jdk/src/share/classes/java/lang/Byte.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/lang/Byte.java	Fri Oct 16 18:02:31 2009 -0700
@@ -201,7 +201,7 @@
      */
     public static Byte valueOf(String s, int radix)
         throws NumberFormatException {
-        return new Byte(parseByte(s, radix));
+        return valueOf(parseByte(s, radix));
     }
 
     /**
@@ -277,7 +277,7 @@
         if (i < MIN_VALUE || i > MAX_VALUE)
             throw new NumberFormatException(
                     "Value " + i + " out of range from input " + nm);
-        return (byte)i;
+        return valueOf((byte)i);
     }
 
     /**
@@ -374,11 +374,14 @@
      *          base&nbsp;10.
      */
     public String toString() {
-        return String.valueOf((int)value);
+        return Integer.toString((int)value);
     }
 
     /**
-     * Returns a hash code for this {@code Byte}.
+     * Returns a hash code for this {@code Byte}; equal to the result
+     * of invoking {@code intValue()}.
+     *
+     * @return a hash code value for this {@code Byte}
      */
     public int hashCode() {
         return (int)value;
@@ -415,7 +418,25 @@
      * @since   1.2
      */
     public int compareTo(Byte anotherByte) {
-        return this.value - anotherByte.value;
+        return compare(this.value, anotherByte.value);
+    }
+
+    /**
+     * Compares two {@code byte} values numerically.
+     * The value returned is identical to what would be returned by:
+     * <pre>
+     *    Byte.valueOf(x).compareTo(Byte.valueOf(y))
+     * </pre>
+     *
+     * @param  x the first {@code byte} to compare
+     * @param  y the second {@code byte} to compare
+     * @return the value {@code 0} if {@code x == y};
+     *         a value less than {@code 0} if {@code x < y}; and
+     *         a value greater than {@code 0} if {@code x > y}
+     * @since 1.7
+     */
+    public static int compare(byte x, byte y) {
+        return x - y;
     }
 
     /**
--- a/jdk/src/share/classes/java/lang/Character.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/lang/Character.java	Fri Oct 16 18:02:31 2009 -0700
@@ -2612,8 +2612,10 @@
     }
 
     /**
-     * Returns a hash code for this <code>Character</code>.
-     * @return  a hash code value for this object.
+     * Returns a hash code for this {@code Character}; equal to the result
+     * of invoking {@code charValue()}.
+     *
+     * @return a hash code value for this {@code Character}
      */
     public int hashCode() {
         return (int)value;
@@ -4962,7 +4964,25 @@
      * @since   1.2
      */
     public int compareTo(Character anotherCharacter) {
-        return this.value - anotherCharacter.value;
+        return compare(this.value, anotherCharacter.value);
+    }
+
+    /**
+     * Compares two {@code char} values numerically.
+     * The value returned is identical to what would be returned by:
+     * <pre>
+     *    Character.valueOf(x).compareTo(Character.valueOf(y))
+     * </pre>
+     *
+     * @param  x the first {@code char} to compare
+     * @param  y the second {@code char} to compare
+     * @return the value {@code 0} if {@code x == y};
+     *         a value less than {@code 0} if {@code x < y}; and
+     *         a value greater than {@code 0} if {@code x > y}
+     * @since 1.7
+     */
+    public static int compare(char x, char y) {
+        return x - y;
     }
 
     /**
--- a/jdk/src/share/classes/java/lang/Class.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/lang/Class.java	Fri Oct 16 18:02:31 2009 -0700
@@ -265,7 +265,7 @@
     }
 
     /** Called after security checks have been made. */
-    private static native Class forName0(String name, boolean initialize,
+    private static native Class<?> forName0(String name, boolean initialize,
                                             ClassLoader loader)
         throws ClassNotFoundException;
 
@@ -339,7 +339,7 @@
                 );
             }
             try {
-                Class[] empty = {};
+                Class<?>[] empty = {};
                 final Constructor<T> c = getConstructor0(empty, Member.DECLARED);
                 // Disable accessibility checks on the constructor
                 // since we have to do the security check here anyway
@@ -361,7 +361,7 @@
         // Security check (same as in java.lang.reflect.Constructor)
         int modifiers = tmpConstructor.getModifiers();
         if (!Reflection.quickCheckMemberAccess(this, modifiers)) {
-            Class caller = Reflection.getCallerClass(3);
+            Class<?> caller = Reflection.getCallerClass(3);
             if (newInstanceCallerCache != caller) {
                 Reflection.ensureMemberAccess(caller, this, null, modifiers);
                 newInstanceCallerCache = caller;
@@ -377,7 +377,7 @@
         }
     }
     private volatile transient Constructor<T> cachedConstructor;
-    private volatile transient Class       newInstanceCallerCache;
+    private volatile transient Class<?>       newInstanceCallerCache;
 
 
     /**
@@ -638,7 +638,7 @@
         if (getGenericSignature() != null)
             return (TypeVariable<Class<T>>[])getGenericInfo().getTypeParameters();
         else
-            return (TypeVariable<Class<T>>[])new TypeVariable[0];
+            return (TypeVariable<Class<T>>[])new TypeVariable<?>[0];
     }
 
 
@@ -901,7 +901,7 @@
 
             MethodRepository typeInfo = MethodRepository.make(enclosingInfo.getDescriptor(),
                                                               getFactory());
-            Class      returnType       = toClass(typeInfo.getReturnType());
+            Class<?>   returnType       = toClass(typeInfo.getReturnType());
             Type []    parameterTypes   = typeInfo.getParameterTypes();
             Class<?>[] parameterClasses = new Class<?>[parameterTypes.length];
 
@@ -996,12 +996,12 @@
 
     }
 
-    private static Class toClass(Type o) {
+    private static Class<?> toClass(Type o) {
         if (o instanceof GenericArrayType)
             return Array.newInstance(toClass(((GenericArrayType)o).getGenericComponentType()),
                                      0)
                 .getClass();
-        return (Class)o;
+        return (Class<?>)o;
      }
 
     /**
@@ -1042,7 +1042,7 @@
              * Loop over all declared constructors; match number
              * of and type of parameters.
              */
-            for(Constructor c: enclosingInfo.getEnclosingClass().getDeclaredConstructors()) {
+            for(Constructor<?> c: enclosingInfo.getEnclosingClass().getDeclaredConstructors()) {
                 Class<?>[] candidateParamClasses = c.getParameterTypes();
                 if (candidateParamClasses.length == parameterClasses.length) {
                     boolean matches = true;
@@ -1304,12 +1304,12 @@
         // has already been ok'd by the SecurityManager.
 
         return java.security.AccessController.doPrivileged(
-            new java.security.PrivilegedAction<Class[]>() {
+            new java.security.PrivilegedAction<Class<?>[]>() {
                 public Class[] run() {
-                    List<Class> list = new ArrayList<Class>();
-                    Class currentClass = Class.this;
+                    List<Class<?>> list = new ArrayList<Class<?>>();
+                    Class<?> currentClass = Class.this;
                     while (currentClass != null) {
-                        Class[] members = currentClass.getDeclaredClasses();
+                        Class<?>[] members = currentClass.getDeclaredClasses();
                         for (int i = 0; i < members.length; i++) {
                             if (Modifier.isPublic(members[i].getModifiers())) {
                                 list.add(members[i]);
@@ -2191,7 +2191,7 @@
             return name;
         }
         if (!name.startsWith("/")) {
-            Class c = this;
+            Class<?> c = this;
             while (c.isArray()) {
                 c = c.getComponentType();
             }
@@ -2565,12 +2565,12 @@
         // out concrete implementations inherited from superclasses at
         // the end.
         MethodArray inheritedMethods = new MethodArray();
-        Class[] interfaces = getInterfaces();
+        Class<?>[] interfaces = getInterfaces();
         for (int i = 0; i < interfaces.length; i++) {
             inheritedMethods.addAll(interfaces[i].privateGetPublicMethods());
         }
         if (!isInterface()) {
-            Class c = getSuperclass();
+            Class<?> c = getSuperclass();
             if (c != null) {
                 MethodArray supers = new MethodArray();
                 supers.addAll(c.privateGetPublicMethods());
@@ -2632,16 +2632,16 @@
             return res;
         }
         // Direct superinterfaces, recursively
-        Class[] interfaces = getInterfaces();
+        Class<?>[] interfaces = getInterfaces();
         for (int i = 0; i < interfaces.length; i++) {
-            Class c = interfaces[i];
+            Class<?> c = interfaces[i];
             if ((res = c.getField0(name)) != null) {
                 return res;
             }
         }
         // Direct superclass, recursively
         if (!isInterface()) {
-            Class c = getSuperclass();
+            Class<?> c = getSuperclass();
             if (c != null) {
                 if ((res = c.getField0(name)) != null) {
                     return res;
@@ -2653,7 +2653,7 @@
 
     private static Method searchMethods(Method[] methods,
                                         String name,
-                                        Class[] parameterTypes)
+                                        Class<?>[] parameterTypes)
     {
         Method res = null;
         String internedName = name.intern();
@@ -2670,7 +2670,7 @@
     }
 
 
-    private Method getMethod0(String name, Class[] parameterTypes) {
+    private Method getMethod0(String name, Class<?>[] parameterTypes) {
         // Note: the intent is that the search algorithm this routine
         // uses be equivalent to the ordering imposed by
         // privateGetPublicMethods(). It fetches only the declared
@@ -2687,7 +2687,7 @@
         }
         // Search superclass's methods
         if (!isInterface()) {
-            Class c = getSuperclass();
+            Class<? super T> c = getSuperclass();
             if (c != null) {
                 if ((res = c.getMethod0(name, parameterTypes)) != null) {
                     return res;
@@ -2695,9 +2695,9 @@
             }
         }
         // Search superinterfaces' methods
-        Class[] interfaces = getInterfaces();
+        Class<?>[] interfaces = getInterfaces();
         for (int i = 0; i < interfaces.length; i++) {
-            Class c = interfaces[i];
+            Class<?> c = interfaces[i];
             if ((res = c.getMethod0(name, parameterTypes)) != null) {
                 return res;
             }
@@ -2706,7 +2706,7 @@
         return null;
     }
 
-    private Constructor<T> getConstructor0(Class[] parameterTypes,
+    private Constructor<T> getConstructor0(Class<?>[] parameterTypes,
                                         int which) throws NoSuchMethodException
     {
         Constructor<T>[] constructors = privateGetDeclaredConstructors((which == Member.PUBLIC));
@@ -2775,9 +2775,9 @@
     private native Field[]       getDeclaredFields0(boolean publicOnly);
     private native Method[]      getDeclaredMethods0(boolean publicOnly);
     private native Constructor<T>[] getDeclaredConstructors0(boolean publicOnly);
-    private native Class[]   getDeclaredClasses0();
+    private native Class<?>[]   getDeclaredClasses0();
 
-    private static String        argumentTypesToString(Class[] argTypes) {
+    private static String        argumentTypesToString(Class<?>[] argTypes) {
         StringBuilder buf = new StringBuilder();
         buf.append("(");
         if (argTypes != null) {
@@ -2785,7 +2785,7 @@
                 if (i > 0) {
                     buf.append(", ");
                 }
-                Class c = argTypes[i];
+                Class<?> c = argTypes[i];
                 buf.append((c == null) ? "null" : c.getName());
             }
         }
@@ -2858,7 +2858,7 @@
     }
 
     // Retrieves the desired assertion status of this class from the VM
-    private static native boolean desiredAssertionStatus0(Class clazz);
+    private static native boolean desiredAssertionStatus0(Class<?> clazz);
 
     /**
      * Returns true if and only if this class was declared as an enum in the
@@ -2979,7 +2979,7 @@
                     getName() + " is not an enum type");
             Map<String, T> m = new HashMap<String, T>(2 * universe.length);
             for (T constant : universe)
-                m.put(((Enum)constant).name(), constant);
+                m.put(((Enum<?>)constant).name(), constant);
             enumConstantDirectory = m;
         }
         return enumConstantDirectory;
@@ -3077,8 +3077,8 @@
     }
 
     // Annotations cache
-    private transient Map<Class, Annotation> annotations;
-    private transient Map<Class, Annotation> declaredAnnotations;
+    private transient Map<Class<? extends Annotation>, Annotation> annotations;
+    private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
 
     private synchronized void initAnnotationsIfNecessary() {
         clearCachesOnClassRedefinition();
@@ -3090,10 +3090,10 @@
         if (superClass == null) {
             annotations = declaredAnnotations;
         } else {
-            annotations = new HashMap<Class, Annotation>();
+            annotations = new HashMap<Class<? extends Annotation>, Annotation>();
             superClass.initAnnotationsIfNecessary();
-            for (Map.Entry<Class, Annotation> e : superClass.annotations.entrySet()) {
-                Class annotationClass = e.getKey();
+            for (Map.Entry<Class<? extends Annotation>, Annotation> e : superClass.annotations.entrySet()) {
+                Class<? extends Annotation> annotationClass = e.getKey();
                 if (AnnotationType.getInstance(annotationClass).isInherited())
                     annotations.put(annotationClass, e.getValue());
             }
--- a/jdk/src/share/classes/java/lang/ClassLoader.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/lang/ClassLoader.java	Fri Oct 16 18:02:31 2009 -0700
@@ -51,6 +51,7 @@
 import java.util.Hashtable;
 import java.util.WeakHashMap;
 import java.util.concurrent.ConcurrentHashMap;
+import sun.misc.BootClassLoaderHook;
 import sun.misc.ClassFileTransformer;
 import sun.misc.CompoundEnumeration;
 import sun.misc.Resource;
@@ -58,7 +59,6 @@
 import sun.misc.VM;
 import sun.reflect.Reflection;
 import sun.security.util.SecurityConstants;
-import sun.jkernel.DownloadManager;
 
 /**
  * A class loader is an object that is responsible for loading classes. The
@@ -1300,21 +1300,7 @@
      * Find resources from the VM's built-in classloader.
      */
     private static URL getBootstrapResource(String name) {
-        try {
-            // If this is a known JRE resource, ensure that its bundle is
-            // downloaded.  If it isn't known, we just ignore the download
-            // failure and check to see if we can find the resource anyway
-            // (which is possible if the boot class path has been modified).
-            if (sun.misc.VM.isBootedKernelVM()) {
-                sun.jkernel.DownloadManager.getBootClassPathEntryForResource(
-                    name);
-            }
-        } catch (NoClassDefFoundError e) {
-            // This happens while Java itself is being compiled; DownloadManager
-            // isn't accessible when this code is first invoked.  It isn't an
-            // issue, as if we can't find DownloadManager, we can safely assume
-            // that additional code is not available for download.
-        }
+        BootClassLoaderHook.preLoadResource(name);
         URLClassPath ucp = getBootstrapClassPath();
         Resource res = ucp.getResource(name);
         return res != null ? res.getURL() : null;
@@ -1831,24 +1817,7 @@
     // Invoked in the java.lang.Runtime class to implement load and loadLibrary.
     static void loadLibrary(Class fromClass, String name,
                             boolean isAbsolute) {
-        try {
-            if (VM.isBootedKernelVM() && !DownloadManager.isJREComplete() &&
-                    !DownloadManager.isCurrentThreadDownloading()) {
-                DownloadManager.downloadFile("bin/" +
-                    System.mapLibraryName(name));
-                // it doesn't matter if the downloadFile call returns false --
-                // it probably just means that this is a user library, as
-                // opposed to a JRE library
-            }
-        } catch (IOException e) {
-            throw new UnsatisfiedLinkError("Error downloading library " +
-                                                name + ": " + e);
-        } catch (NoClassDefFoundError e) {
-            // This happens while Java itself is being compiled; DownloadManager
-            // isn't accessible when this code is first invoked.  It isn't an
-            // issue, as if we can't find DownloadManager, we can safely assume
-            // that additional code is not available for download.
-        }
+        BootClassLoaderHook.preLoadLibrary(name);
         ClassLoader loader =
             (fromClass == null) ? null : fromClass.getClassLoader();
         if (sys_paths == null) {
--- a/jdk/src/share/classes/java/lang/Double.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/lang/Double.java	Fri Oct 16 18:02:31 2009 -0700
@@ -629,7 +629,7 @@
      * @see java.lang.Double#toString(double)
      */
     public String toString() {
-        return String.valueOf(value);
+        return toString(value);
     }
 
     /**
--- a/jdk/src/share/classes/java/lang/Float.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/lang/Float.java	Fri Oct 16 18:02:31 2009 -0700
@@ -551,7 +551,7 @@
      * @see java.lang.Float#toString(float)
      */
     public String toString() {
-        return String.valueOf(value);
+        return Float.toString(value);
     }
 
     /**
--- a/jdk/src/share/classes/java/lang/Integer.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/lang/Integer.java	Fri Oct 16 18:02:31 2009 -0700
@@ -746,7 +746,7 @@
      *          base&nbsp;10.
      */
     public String toString() {
-        return String.valueOf(value);
+        return toString(value);
     }
 
     /**
@@ -1010,9 +1010,25 @@
      * @since   1.2
      */
     public int compareTo(Integer anotherInteger) {
-        int thisVal = this.value;
-        int anotherVal = anotherInteger.value;
-        return (thisVal<anotherVal ? -1 : (thisVal==anotherVal ? 0 : 1));
+        return compare(this.value, anotherInteger.value);
+    }
+
+    /**
+     * Compares two {@code int} values numerically.
+     * The value returned is identical to what would be returned by:
+     * <pre>
+     *    Integer.valueOf(x).compareTo(Integer.valueOf(y))
+     * </pre>
+     *
+     * @param  x the first {@code int} to compare
+     * @param  y the second {@code int} to compare
+     * @return the value {@code 0} if {@code x == y};
+     *         a value less than {@code 0} if {@code x < y}; and
+     *         a value greater than {@code 0} if {@code x > y}
+     * @since 1.7
+     */
+    public static int compare(int x, int y) {
+        return (x < y) ? -1 : ((x == y) ? 0 : 1);
     }
 
 
--- a/jdk/src/share/classes/java/lang/Long.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/lang/Long.java	Fri Oct 16 18:02:31 2009 -0700
@@ -761,7 +761,7 @@
      *          base&nbsp;10.
      */
     public String toString() {
-        return String.valueOf(value);
+        return toString(value);
     }
 
     /**
@@ -950,9 +950,25 @@
      * @since   1.2
      */
     public int compareTo(Long anotherLong) {
-        long thisVal = this.value;
-        long anotherVal = anotherLong.value;
-        return (thisVal<anotherVal ? -1 : (thisVal==anotherVal ? 0 : 1));
+        return compare(this.value, anotherLong.value);
+    }
+
+    /**
+     * Compares two {@code long} values numerically.
+     * The value returned is identical to what would be returned by:
+     * <pre>
+     *    Long.valueOf(x).compareTo(Long.valueOf(y))
+     * </pre>
+     *
+     * @param  x the first {@code long} to compare
+     * @param  y the second {@code long} to compare
+     * @return the value {@code 0} if {@code x == y};
+     *         a value less than {@code 0} if {@code x < y}; and
+     *         a value greater than {@code 0} if {@code x > y}
+     * @since 1.7
+     */
+    public static int compare(long x, long y) {
+        return (x < y) ? -1 : ((x == y) ? 0 : 1);
     }
 
 
--- a/jdk/src/share/classes/java/lang/Package.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/lang/Package.java	Fri Oct 16 18:02:31 2009 -0700
@@ -320,7 +320,7 @@
      * @param class the class to get the package of.
      * @return the package of the class. It may be null if no package
      *          information is available from the archive or codebase.  */
-    static Package getPackage(Class c) {
+    static Package getPackage(Class<?> c) {
         String name = c.getName();
         int i = name.lastIndexOf('.');
         if (i != -1) {
--- a/jdk/src/share/classes/java/lang/SecurityManager.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/lang/SecurityManager.java	Fri Oct 16 18:02:31 2009 -0700
@@ -1341,7 +1341,7 @@
             throw new NullPointerException("window can't be null");
         }
         try {
-            checkPermission(SecurityConstants.TOPLEVEL_WINDOW_PERMISSION);
+            checkPermission(SecurityConstants.AWT.TOPLEVEL_WINDOW_PERMISSION);
             return true;
         } catch (SecurityException se) {
             // just return false
@@ -1391,7 +1391,7 @@
      * @see        #checkPermission(java.security.Permission) checkPermission
      */
     public void checkSystemClipboardAccess() {
-        checkPermission(SecurityConstants.ACCESS_CLIPBOARD_PERMISSION);
+        checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
     }
 
     /**
@@ -1412,7 +1412,7 @@
      * @see        #checkPermission(java.security.Permission) checkPermission
      */
     public void checkAwtEventQueueAccess() {
-        checkPermission(SecurityConstants.CHECK_AWT_EVENTQUEUE_PERMISSION);
+        checkPermission(SecurityConstants.AWT.CHECK_AWT_EVENTQUEUE_PERMISSION);
     }
 
     /*
--- a/jdk/src/share/classes/java/lang/Short.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/lang/Short.java	Fri Oct 16 18:02:31 2009 -0700
@@ -170,7 +170,7 @@
      */
     public static Short valueOf(String s, int radix)
         throws NumberFormatException {
-        return new Short(parseShort(s, radix));
+        return valueOf(parseShort(s, radix));
     }
 
     /**
@@ -282,7 +282,7 @@
         if (i < MIN_VALUE || i > MAX_VALUE)
             throw new NumberFormatException(
                     "Value " + i + " out of range from input " + nm);
-        return (short)i;
+        return valueOf((short)i);
     }
 
     /**
@@ -379,11 +379,14 @@
      *          base&nbsp;10.
      */
     public String toString() {
-        return String.valueOf((int)value);
+        return Integer.toString((int)value);
     }
 
     /**
-     * Returns a hash code for this {@code Short}.
+     * Returns a hash code for this {@code Short}; equal to the result
+     * of invoking {@code intValue()}.
+     *
+     * @return a hash code value for this {@code Short}
      */
     public int hashCode() {
         return (int)value;
@@ -420,7 +423,25 @@
      * @since   1.2
      */
     public int compareTo(Short anotherShort) {
-        return this.value - anotherShort.value;
+        return compare(this.value, anotherShort.value);
+    }
+
+    /**
+     * Compares two {@code short} values numerically.
+     * The value returned is identical to what would be returned by:
+     * <pre>
+     *    Short.valueOf(x).compareTo(Short.valueOf(y))
+     * </pre>
+     *
+     * @param  x the first {@code short} to compare
+     * @param  y the second {@code short} to compare
+     * @return the value {@code 0} if {@code x == y};
+     *         a value less than {@code 0} if {@code x < y}; and
+     *         a value greater than {@code 0} if {@code x > y}
+     * @since 1.7
+     */
+    public static int compare(short x, short y) {
+        return x - y;
     }
 
     /**
--- a/jdk/src/share/classes/java/lang/String.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/lang/String.java	Fri Oct 16 18:02:31 2009 -0700
@@ -2995,7 +2995,7 @@
      * @see     java.lang.Integer#toString(int, int)
      */
     public static String valueOf(int i) {
-        return Integer.toString(i, 10);
+        return Integer.toString(i);
     }
 
     /**
@@ -3009,7 +3009,7 @@
      * @see     java.lang.Long#toString(long)
      */
     public static String valueOf(long l) {
-        return Long.toString(l, 10);
+        return Long.toString(l);
     }
 
     /**
--- a/jdk/src/share/classes/java/lang/reflect/AccessibleObject.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/lang/reflect/AccessibleObject.java	Fri Oct 16 18:02:31 2009 -0700
@@ -131,7 +131,7 @@
         throws SecurityException
     {
         if (obj instanceof Constructor && flag == true) {
-            Constructor c = (Constructor)obj;
+            Constructor<?> c = (Constructor<?>)obj;
             if (c.getDeclaringClass() == Class.class) {
                 throw new SecurityException("Can not make a java.lang.Class" +
                                             " constructor accessible");
--- a/jdk/src/share/classes/java/lang/reflect/Constructor.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/lang/reflect/Constructor.java	Fri Oct 16 18:02:31 2009 -0700
@@ -64,8 +64,8 @@
 
     private Class<T>            clazz;
     private int                 slot;
-    private Class[]             parameterTypes;
-    private Class[]             exceptionTypes;
+    private Class<?>[]          parameterTypes;
+    private Class<?>[]          exceptionTypes;
     private int                 modifiers;
     // Generics and annotations support
     private transient String    signature;
@@ -80,7 +80,7 @@
     // always succeed (it is not affected by the granting or revoking
     // of permissions); we speed up the check in the common case by
     // remembering the last Class for which the check succeeded.
-    private volatile Class securityCheckCache;
+    private volatile Class<?> securityCheckCache;
 
     // Generics infrastructure
     // Accessor for factory
@@ -113,8 +113,8 @@
      * package via sun.reflect.LangReflectAccess.
      */
     Constructor(Class<T> declaringClass,
-                Class[] parameterTypes,
-                Class[] checkedExceptions,
+                Class<?>[] parameterTypes,
+                Class<?>[] checkedExceptions,
                 int modifiers,
                 int slot,
                 String signature,
@@ -275,10 +275,6 @@
      * Returns an array of length 0 if the underlying method declares
      * no exceptions in its {@code throws} clause.
      *
-     * <p>If an exception type is a parameterized type, the {@code Type}
-     * object returned for it must accurately reflect the actual type
-     * parameters used in the source code.
-     *
      * <p>If an exception type is a type variable or a parameterized
      * type, it is created. Otherwise, it is resolved.
      *
@@ -311,11 +307,11 @@
      */
     public boolean equals(Object obj) {
         if (obj != null && obj instanceof Constructor) {
-            Constructor other = (Constructor)obj;
+            Constructor<?> other = (Constructor<?>)obj;
             if (getDeclaringClass() == other.getDeclaringClass()) {
                 /* Avoid unnecessary cloning */
-                Class[] params1 = parameterTypes;
-                Class[] params2 = other.parameterTypes;
+                Class<?>[] params1 = parameterTypes;
+                Class<?>[] params2 = other.parameterTypes;
                 if (params1.length == params2.length) {
                     for (int i = 0; i < params1.length; i++) {
                         if (params1[i] != params2[i])
@@ -361,14 +357,14 @@
             }
             sb.append(Field.getTypeName(getDeclaringClass()));
             sb.append("(");
-            Class[] params = parameterTypes; // avoid clone
+            Class<?>[] params = parameterTypes; // avoid clone
             for (int j = 0; j < params.length; j++) {
                 sb.append(Field.getTypeName(params[j]));
                 if (j < (params.length - 1))
                     sb.append(",");
             }
             sb.append(")");
-            Class[] exceptions = exceptionTypes; // avoid clone
+            Class<?>[] exceptions = exceptionTypes; // avoid clone
             if (exceptions.length > 0) {
                 sb.append(" throws ");
                 for (int k = 0; k < exceptions.length; k++) {
@@ -456,7 +452,7 @@
                 sb.append(" throws ");
                 for (int k = 0; k < exceptions.length; k++) {
                     sb.append((exceptions[k] instanceof Class)?
-                              ((Class)exceptions[k]).getName():
+                              ((Class<?>)exceptions[k]).getName():
                               exceptions[k].toString());
                     if (k < (exceptions.length - 1))
                         sb.append(",");
@@ -522,7 +518,7 @@
     {
         if (!override) {
             if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
-                Class caller = Reflection.getCallerClass(2);
+                Class<?> caller = Reflection.getCallerClass(2);
                 if (securityCheckCache != caller) {
                     Reflection.ensureMemberAccess(caller, clazz, null, modifiers);
                     securityCheckCache = caller;
@@ -629,9 +625,9 @@
         return AnnotationParser.toArray(declaredAnnotations());
     }
 
-    private transient Map<Class, Annotation> declaredAnnotations;
+    private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
 
-    private synchronized  Map<Class, Annotation> declaredAnnotations() {
+    private synchronized  Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
         if (declaredAnnotations == null) {
             declaredAnnotations = AnnotationParser.parseAnnotations(
                 annotations, sun.misc.SharedSecrets.getJavaLangAccess().
--- a/jdk/src/share/classes/java/lang/reflect/Field.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/lang/reflect/Field.java	Fri Oct 16 18:02:31 2009 -0700
@@ -58,12 +58,12 @@
 public final
 class Field extends AccessibleObject implements Member {
 
-    private Class               clazz;
+    private Class<?>            clazz;
     private int                 slot;
     // This is guaranteed to be interned by the VM in the 1.4
     // reflection implementation
     private String              name;
-    private Class               type;
+    private Class<?>            type;
     private int                 modifiers;
     // Generics and annotations support
     private transient String    signature;
@@ -81,8 +81,8 @@
 
     // More complicated security check cache needed here than for
     // Class.newInstance() and Constructor.newInstance()
-    private Class securityCheckCache;
-    private Class securityCheckTargetClassCache;
+    private Class<?> securityCheckCache;
+    private Class<?> securityCheckTargetClassCache;
 
     // Generics infrastructure
 
@@ -112,9 +112,9 @@
      * instantiation of these objects in Java code from the java.lang
      * package via sun.reflect.LangReflectAccess.
      */
-    Field(Class declaringClass,
+    Field(Class<?> declaringClass,
           String name,
-          Class type,
+          Class<?> type,
           int modifiers,
           int slot,
           String signature,
@@ -964,10 +964,10 @@
     private void doSecurityCheck(Object obj) throws IllegalAccessException {
         if (!override) {
             if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
-                Class caller = Reflection.getCallerClass(4);
-                Class targetClass = ((obj == null || !Modifier.isProtected(modifiers))
-                                     ? clazz
-                                     : obj.getClass());
+                Class<?> caller = Reflection.getCallerClass(4);
+                Class<?> targetClass = ((obj == null || !Modifier.isProtected(modifiers))
+                                        ? clazz
+                                        : obj.getClass());
 
                 synchronized (this) {
                     if ((securityCheckCache == caller)
@@ -987,10 +987,10 @@
     /*
      * Utility routine to paper over array type names
      */
-    static String getTypeName(Class type) {
+    static String getTypeName(Class<?> type) {
         if (type.isArray()) {
             try {
-                Class cl = type;
+                Class<?> cl = type;
                 int dimensions = 0;
                 while (cl.isArray()) {
                     dimensions++;
@@ -1025,9 +1025,9 @@
         return AnnotationParser.toArray(declaredAnnotations());
     }
 
-    private transient Map<Class, Annotation> declaredAnnotations;
+    private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
 
-    private synchronized  Map<Class, Annotation> declaredAnnotations() {
+    private synchronized  Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
         if (declaredAnnotations == null) {
             declaredAnnotations = AnnotationParser.parseAnnotations(
                 annotations, sun.misc.SharedSecrets.getJavaLangAccess().
--- a/jdk/src/share/classes/java/lang/reflect/Method.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/lang/reflect/Method.java	Fri Oct 16 18:02:31 2009 -0700
@@ -61,14 +61,14 @@
 public final
     class Method extends AccessibleObject implements GenericDeclaration,
                                                      Member {
-    private Class               clazz;
+    private Class<?>            clazz;
     private int                 slot;
     // This is guaranteed to be interned by the VM in the 1.4
     // reflection implementation
     private String              name;
-    private Class               returnType;
-    private Class[]             parameterTypes;
-    private Class[]             exceptionTypes;
+    private Class<?>            returnType;
+    private Class<?>[]          parameterTypes;
+    private Class<?>[]          exceptionTypes;
     private int                 modifiers;
     // Generics and annotations support
     private transient String              signature;
@@ -85,8 +85,8 @@
 
     // More complicated security check cache needed here than for
     // Class.newInstance() and Constructor.newInstance()
-    private Class securityCheckCache;
-    private Class securityCheckTargetClassCache;
+    private Class<?> securityCheckCache;
+    private Class<?> securityCheckTargetClassCache;
 
    // Generics infrastructure
 
@@ -114,11 +114,11 @@
      * instantiation of these objects in Java code from the java.lang
      * package via sun.reflect.LangReflectAccess.
      */
-    Method(Class declaringClass,
+    Method(Class<?> declaringClass,
            String name,
-           Class[] parameterTypes,
-           Class returnType,
-           Class[] checkedExceptions,
+           Class<?>[] parameterTypes,
+           Class<?> returnType,
+           Class<?>[] checkedExceptions,
            int modifiers,
            int slot,
            String signature,
@@ -317,10 +317,6 @@
      * Returns an array of length 0 if the underlying method declares
      * no exceptions in its {@code throws} clause.
      *
-     * <p>If an exception type is a parameterized type, the {@code Type}
-     * object returned for it must accurately reflect the actual type
-     * parameters used in the source code.
-     *
      * <p>If an exception type is a type variable or a parameterized
      * type, it is created. Otherwise, it is resolved.
      *
@@ -359,8 +355,8 @@
                 if (!returnType.equals(other.getReturnType()))
                     return false;
                 /* Avoid unnecessary cloning */
-                Class[] params1 = parameterTypes;
-                Class[] params2 = other.parameterTypes;
+                Class<?>[] params1 = parameterTypes;
+                Class<?>[] params2 = other.parameterTypes;
                 if (params1.length == params2.length) {
                     for (int i = 0; i < params1.length; i++) {
                         if (params1[i] != params2[i])
@@ -414,14 +410,14 @@
             sb.append(Field.getTypeName(getReturnType()) + " ");
             sb.append(Field.getTypeName(getDeclaringClass()) + ".");
             sb.append(getName() + "(");
-            Class[] params = parameterTypes; // avoid clone
+            Class<?>[] params = parameterTypes; // avoid clone
             for (int j = 0; j < params.length; j++) {
                 sb.append(Field.getTypeName(params[j]));
                 if (j < (params.length - 1))
                     sb.append(",");
             }
             sb.append(")");
-            Class[] exceptions = exceptionTypes; // avoid clone
+            Class<?>[] exceptions = exceptionTypes; // avoid clone
             if (exceptions.length > 0) {
                 sb.append(" throws ");
                 for (int k = 0; k < exceptions.length; k++) {
@@ -594,10 +590,10 @@
     {
         if (!override) {
             if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
-                Class caller = Reflection.getCallerClass(1);
-                Class targetClass = ((obj == null || !Modifier.isProtected(modifiers))
-                                     ? clazz
-                                     : obj.getClass());
+                Class<?> caller = Reflection.getCallerClass(1);
+                Class<?> targetClass = ((obj == null || !Modifier.isProtected(modifiers))
+                                        ? clazz
+                                        : obj.getClass());
 
                 boolean cached;
                 synchronized (this) {
@@ -706,9 +702,9 @@
         return AnnotationParser.toArray(declaredAnnotations());
     }
 
-    private transient Map<Class, Annotation> declaredAnnotations;
+    private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
 
-    private synchronized  Map<Class, Annotation> declaredAnnotations() {
+    private synchronized  Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
         if (declaredAnnotations == null) {
             declaredAnnotations = AnnotationParser.parseAnnotations(
                 annotations, sun.misc.SharedSecrets.getJavaLangAccess().
@@ -735,7 +731,7 @@
     public Object getDefaultValue() {
         if  (annotationDefault == null)
             return null;
-        Class memberType = AnnotationType.invocationHandlerReturnType(
+        Class<?> memberType = AnnotationType.invocationHandlerReturnType(
             getReturnType());
         Object result = AnnotationParser.parseMemberValue(
             memberType, ByteBuffer.wrap(annotationDefault),
--- a/jdk/src/share/classes/java/lang/reflect/Proxy.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/lang/reflect/Proxy.java	Fri Oct 16 18:02:31 2009 -0700
@@ -350,7 +350,7 @@
             throw new IllegalArgumentException("interface limit exceeded");
         }
 
-        Class proxyClass = null;
+        Class<?> proxyClass = null;
 
         /* collect interface names to use as key for proxy class cache */
         String[] interfaceNames = new String[interfaces.length];
@@ -364,7 +364,7 @@
              * interface to the same Class object.
              */
             String interfaceName = interfaces[i].getName();
-            Class interfaceClass = null;
+            Class<?> interfaceClass = null;
             try {
                 interfaceClass = Class.forName(interfaceName, false, loader);
             } catch (ClassNotFoundException e) {
--- a/jdk/src/share/classes/java/lang/reflect/ReflectAccess.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/lang/reflect/ReflectAccess.java	Fri Oct 16 18:02:31 2009 -0700
@@ -33,9 +33,9 @@
     package to instantiate objects in this package. */
 
 class ReflectAccess implements sun.reflect.LangReflectAccess {
-    public Field newField(Class declaringClass,
+    public Field newField(Class<?> declaringClass,
                           String name,
-                          Class type,
+                          Class<?> type,
                           int modifiers,
                           int slot,
                           String signature,
@@ -50,11 +50,11 @@
                          annotations);
     }
 
-    public Method newMethod(Class declaringClass,
+    public Method newMethod(Class<?> declaringClass,
                             String name,
-                            Class[] parameterTypes,
-                            Class returnType,
-                            Class[] checkedExceptions,
+                            Class<?>[] parameterTypes,
+                            Class<?> returnType,
+                            Class<?>[] checkedExceptions,
                             int modifiers,
                             int slot,
                             String signature,
@@ -76,8 +76,8 @@
     }
 
     public <T> Constructor<T> newConstructor(Class<T> declaringClass,
-                                             Class[] parameterTypes,
-                                             Class[] checkedExceptions,
+                                             Class<?>[] parameterTypes,
+                                             Class<?>[] checkedExceptions,
                                              int modifiers,
                                              int slot,
                                              String signature,
@@ -102,29 +102,29 @@
         m.setMethodAccessor(accessor);
     }
 
-    public ConstructorAccessor getConstructorAccessor(Constructor c) {
+    public ConstructorAccessor getConstructorAccessor(Constructor<?> c) {
         return c.getConstructorAccessor();
     }
 
-    public void setConstructorAccessor(Constructor c,
+    public void setConstructorAccessor(Constructor<?> c,
                                        ConstructorAccessor accessor)
     {
         c.setConstructorAccessor(accessor);
     }
 
-    public int getConstructorSlot(Constructor c) {
+    public int getConstructorSlot(Constructor<?> c) {
         return c.getSlot();
     }
 
-    public String getConstructorSignature(Constructor c) {
+    public String getConstructorSignature(Constructor<?> c) {
         return c.getSignature();
     }
 
-    public byte[] getConstructorAnnotations(Constructor c) {
+    public byte[] getConstructorAnnotations(Constructor<?> c) {
         return c.getRawAnnotations();
     }
 
-    public byte[] getConstructorParameterAnnotations(Constructor c) {
+    public byte[] getConstructorParameterAnnotations(Constructor<?> c) {
         return c.getRawParameterAnnotations();
     }
 
--- a/jdk/src/share/classes/java/util/zip/ZipEntry.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/java/util/zip/ZipEntry.java	Fri Oct 16 18:02:31 2009 -0700
@@ -26,6 +26,7 @@
 package java.util.zip;
 
 import java.util.Date;
+import sun.misc.BootClassLoaderHook;
 
 /**
  * This class is used to represent a ZIP file entry.
@@ -109,12 +110,16 @@
      * @see #getTime()
      */
     public void setTime(long time) {
-        // fix for bug 6625963: we bypass time calculations while Kernel is
-        // downloading bundles, since they aren't necessary and would cause
-        // the Kernel core to depend upon the (very large) time zone data
-        if (sun.misc.VM.isBootedKernelVM() &&
-            sun.jkernel.DownloadManager.isCurrentThreadDownloading()) {
-            this.time = sun.jkernel.DownloadManager.KERNEL_STATIC_MODTIME;
+        // Same value as defined in sun.jkernel.DownloadManager.KERNEL_STATIC_MODTIME
+        // to avoid direct reference to DownoadManager class.  Need to revisit
+        // if this is needed any more (see comment in the DownloadManager class)
+        final int KERNEL_STATIC_MODTIME = 10000000;
+        BootClassLoaderHook hook = BootClassLoaderHook.getHook();
+        if (hook != null && hook.isCurrentThreadPrefetching()) {
+            // fix for bug 6625963: we bypass time calculations while Kernel is
+            // downloading bundles, since they aren't necessary and would cause
+            // the Kernel core to depend upon the (very large) time zone data
+            this.time = KERNEL_STATIC_MODTIME;
         } else {
             this.time = javaToDosTime(time);
         }
--- a/jdk/src/share/classes/javax/swing/JFileChooser.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/javax/swing/JFileChooser.java	Fri Oct 16 18:02:31 2009 -0700
@@ -715,7 +715,7 @@
      * <ul>
      * <li>JFileChooser.CANCEL_OPTION
      * <li>JFileChooser.APPROVE_OPTION
-     * <li>JFileCHooser.ERROR_OPTION if an error occurs or the
+     * <li>JFileChooser.ERROR_OPTION if an error occurs or the
      *                  dialog is dismissed
      * </ul>
      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
@@ -724,6 +724,11 @@
      */
     public int showDialog(Component parent, String approveButtonText)
         throws HeadlessException {
+        if (dialog != null) {
+            // Prevent to show second instance of dialog if the previous one still exists
+            return JFileChooser.ERROR_OPTION;
+        }
+
         if(approveButtonText != null) {
             setApproveButtonText(approveButtonText);
             setDialogType(CUSTOM_DIALOG);
--- a/jdk/src/share/classes/javax/swing/JLayer.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/javax/swing/JLayer.java	Fri Oct 16 18:02:31 2009 -0700
@@ -56,28 +56,70 @@
  * {@code JLayer} is a good solution if you only need to do custom painting
  * over compound component or catch input events from its subcomponents.
  * <pre>
+ * import javax.swing.*;
+ * import javax.swing.plaf.LayerUI;
+ * import java.awt.*;
+ *
+ * public class JLayerSample {
+ *
+ *     private static JLayer&lt;JComponent&gt; createLayer() {
+ *         // This custom layerUI will fill the layer with translucent green
+ *         // and print out all mouseMotion events generated within its borders
+ *         LayerUI&lt;JComponent&gt; layerUI = new LayerUI&lt;JComponent&gt;() {
+ *
+ *             public void paint(Graphics g, JComponent c) {
+ *                 // paint the layer as is
+ *                 super.paint(g, c);
+ *                 // fill it with the translucent green
+ *                 g.setColor(new Color(0, 128, 0, 128));
+ *                 g.fillRect(0, 0, c.getWidth(), c.getHeight());
+ *             }
+ *
+ *             public void installUI(JComponent c) {
+ *                 super.installUI(c);
+ *                 // enable mouse motion events for the layer's subcomponents
+ *                 ((JLayer) c).setLayerEventMask(AWTEvent.MOUSE_MOTION_EVENT_MASK);
+ *             }
+ *
+ *             public void uninstallUI(JComponent c) {
+ *                 super.uninstallUI(c);
+ *                 // reset the layer event mask
+ *                 ((JLayer) c).setLayerEventMask(0);
+ *             }
+ *
+ *             // overridden method which catches MouseMotion events
+ *             public void eventDispatched(AWTEvent e, JLayer&lt;? extends JComponent&gt; l) {
+ *                 System.out.println("AWTEvent detected: " + e);
+ *             }
+ *         };
  *         // create a component to be decorated with the layer
- *        JPanel panel = new JPanel();
- *        panel.add(new JButton("JButton"));
- *        // This custom layerUI will fill the layer with translucent green
- *        // and print out all mouseMotion events generated within its borders
- *        LayerUI&lt;JPanel&gt; layerUI = new LayerUI&lt;JPanel&gt;() {
- *            public void paint(Graphics g, JCompo  nent c) {
- *                // paint the layer as is
- *                super.paint(g, c);
- *                // fill it with the translucent green
- *                g.setColor(new Color(0, 128, 0, 128));
- *                g.fillRect(0, 0, c.getWidth(), c.getHeight());
- *            }
- *            // overridden method which catches MouseMotion events
- *            public void eventDispatched(AWTEvent e, JLayer&lt;JPanel&gt; l) {
- *                System.out.println("AWTEvent detected: " + e);
- *            }
- *        };
- *        // create the layer for the panel using our custom layerUI
- *        JLayer&lt;JPanel&gt; layer = new JLayer&lt;JPanel&gt;(panel, layerUI);
- *        // work with the layer as with any other Swing component
- *        frame.add(layer);
+ *         JPanel panel = new JPanel();
+ *         panel.add(new JButton("JButton"));
+ *
+ *         // create the layer for the panel using our custom layerUI
+ *         return new JLayer&lt;JComponent&gt;(panel, layerUI);
+ *     }
+ *
+ *     private static void createAndShowGUI() {
+ *         final JFrame frame = new JFrame();
+ *         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ *
+ *         // work with the layer as with any other Swing component
+ *         frame.add(createLayer());
+ *
+ *         frame.setSize(200, 200);
+ *         frame.setLocationRelativeTo(null);
+ *         frame.setVisible(true);
+ *     }
+ *
+ *     public static void main(String[] args) throws Exception {
+ *         SwingUtilities.invokeAndWait(new Runnable() {
+ *             public void run() {
+ *                 createAndShowGUI();
+ *             }
+ *         });
+ *     }
+ * }
  * </pre>
  *
  * <b>Note:</b> {@code JLayer} doesn't support the following methods:
@@ -291,7 +333,9 @@
      * {@inheritDoc}
      */
     public void remove(Component comp) {
-        if (comp == getView()) {
+        if (comp == null) {
+            super.remove(comp);
+        } else if (comp == getView()) {
             setView(null);
         } else if (comp == getGlassPane()) {
             setGlassPane(null);
--- a/jdk/src/share/classes/javax/swing/JPopupMenu.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/javax/swing/JPopupMenu.java	Fri Oct 16 18:02:31 2009 -0700
@@ -412,7 +412,7 @@
             SecurityManager sm = System.getSecurityManager();
             if (sm != null) {
                 sm.checkPermission(
-                        SecurityConstants.SET_WINDOW_ALWAYS_ON_TOP_PERMISSION);
+                    SecurityConstants.AWT.SET_WINDOW_ALWAYS_ON_TOP_PERMISSION);
             }
         } catch (SecurityException se) {
             // There is no permission to show popups over the task bar
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicComboBoxUI.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicComboBoxUI.java	Fri Oct 16 18:02:31 2009 -0700
@@ -1766,7 +1766,7 @@
         }
 
         private boolean isTypeAheadKey( KeyEvent e ) {
-            return !e.isAltDown() && !e.isControlDown() && !e.isMetaDown();
+            return !e.isAltDown() && !BasicGraphicsUtils.isMenuShortcutKeyDown(e);
         }
 
         //
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicComboPopup.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicComboPopup.java	Fri Oct 16 18:02:31 2009 -0700
@@ -483,11 +483,12 @@
     protected JList createList() {
         return new JList( comboBox.getModel() ) {
             public void processMouseEvent(MouseEvent e)  {
-                if (e.isControlDown())  {
+                if (BasicGraphicsUtils.isMenuShortcutKeyDown(e))  {
                     // Fix for 4234053. Filter out the Control Key from the list.
                     // ie., don't allow CTRL key deselection.
+                    Toolkit toolkit = Toolkit.getDefaultToolkit();
                     e = new MouseEvent((Component)e.getSource(), e.getID(), e.getWhen(),
-                                       e.getModifiers() ^ InputEvent.CTRL_MASK,
+                                       e.getModifiers() ^ toolkit.getMenuShortcutKeyMask(),
                                        e.getX(), e.getY(),
                                        e.getXOnScreen(), e.getYOnScreen(),
                                        e.getClickCount(),
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java	Fri Oct 16 18:02:31 2009 -0700
@@ -924,7 +924,8 @@
                 boolean isTrav = (selectedFile != null && chooser.isTraversable(selectedFile));
                 boolean isDirSelEnabled = chooser.isDirectorySelectionEnabled();
                 boolean isFileSelEnabled = chooser.isFileSelectionEnabled();
-                boolean isCtrl = (e != null && (e.getModifiers() & ActionEvent.CTRL_MASK) != 0);
+                boolean isCtrl = (e != null && (e.getModifiers() &
+                            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0);
 
                 if (isDir && isTrav && (isCtrl || !isDirSelEnabled)) {
                     changeDirectory(selectedFile);
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicGraphicsUtils.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicGraphicsUtils.java	Fri Oct 16 18:02:31 2009 -0700
@@ -33,7 +33,10 @@
 import java.awt.Graphics;
 import java.awt.Insets;
 import java.awt.Rectangle;
+import java.awt.Toolkit;
 import java.awt.event.KeyEvent;
+import java.awt.event.InputEvent;
+
 import sun.swing.SwingUtilities2;
 
 
@@ -303,4 +306,9 @@
     static boolean isLeftToRight( Component c ) {
         return c.getComponentOrientation().isLeftToRight();
     }
+
+    static boolean isMenuShortcutKeyDown(InputEvent event) {
+        return (event.getModifiers() &
+                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0;
+    }
 }
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicListUI.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicListUI.java	Fri Oct 16 18:02:31 2009 -0700
@@ -2371,8 +2371,9 @@
             JList src = (JList)e.getSource();
             ListModel model = src.getModel();
 
-            if (model.getSize() == 0 || e.isAltDown() || e.isControlDown() || e.isMetaDown() ||
-                isNavigationKey(e)) {
+            if (model.getSize() == 0 || e.isAltDown() ||
+                    BasicGraphicsUtils.isMenuShortcutKeyDown(e) ||
+                    isNavigationKey(e)) {
                 // Nothing to select
                 return;
             }
@@ -2665,7 +2666,7 @@
                 if (row != -1 && DragRecognitionSupport.mousePressed(e)) {
                     dragPressDidSelection = false;
 
-                    if (e.isControlDown()) {
+                    if (BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
                         // do nothing for control - will be handled on release
                         // or when drag starts
                         return;
@@ -2717,7 +2718,7 @@
                     anchorSelected = list.isSelectedIndex(anchorIndex);
                 }
 
-                if (e.isControlDown()) {
+                if (BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
                     if (e.isShiftDown()) {
                         if (anchorSelected) {
                             list.addSelectionInterval(anchorIndex, row);
@@ -2742,7 +2743,7 @@
         }
 
         public void dragStarting(MouseEvent me) {
-            if (me.isControlDown()) {
+            if (BasicGraphicsUtils.isMenuShortcutKeyDown(me)) {
                 int row = SwingUtilities2.loc2IndexFileList(list, me.getPoint());
                 list.addSelectionInterval(row, row);
             }
@@ -2758,7 +2759,7 @@
                 return;
             }
 
-            if (e.isShiftDown() || e.isControlDown()) {
+            if (e.isShiftDown() || BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
                 return;
             }
 
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicMenuUI.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicMenuUI.java	Fri Oct 16 18:02:31 2009 -0700
@@ -196,10 +196,6 @@
         return getHandler();
     }
 
-    protected MenuKeyListener createMenuKeyListener(JComponent c) {
-        return (MenuKeyListener)getHandler();
-    }
-
     public Dimension getMaximumSize(JComponent c) {
         if (((JMenu)menuItem).isTopLevelMenu() == true) {
             Dimension d = c.getPreferredSize();
@@ -401,8 +397,7 @@
         public void stateChanged(ChangeEvent e) { }
     }
 
-    private class Handler extends BasicMenuItemUI.Handler implements
-            MenuKeyListener {
+    private class Handler extends BasicMenuItemUI.Handler {
         //
         // PropertyChangeListener
         //
@@ -585,45 +580,5 @@
         }
         public void menuDragMouseExited(MenuDragMouseEvent e) {}
         public void menuDragMouseReleased(MenuDragMouseEvent e) {}
-
-
-        //
-        // MenuKeyListener
-        //
-        /**
-         * Open the Menu
-         */
-        public void menuKeyTyped(MenuKeyEvent e) {
-            if (!crossMenuMnemonic && BasicPopupMenuUI.getLastPopup() != null) {
-                // when crossMenuMnemonic is not set, we don't open a toplevel
-                // menu if another toplevel menu is already open
-                    return;
-                }
-
-            char key = Character.toLowerCase((char)menuItem.getMnemonic());
-            MenuElement path[] = e.getPath();
-            MenuSelectionManager manager = e.getMenuSelectionManager();
-            if (key == Character.toLowerCase(e.getKeyChar())) {
-                JPopupMenu popupMenu = ((JMenu)menuItem).getPopupMenu();
-                ArrayList<MenuElement> newList = new ArrayList<MenuElement>(Arrays.asList(path));
-                newList.add(popupMenu);
-                MenuElement subs[] = popupMenu.getSubElements();
-                MenuElement sub =
-                        BasicPopupMenuUI.findEnabledChild(subs, -1, true);
-                if(sub != null) {
-                    newList.add(sub);
-                }
-                MenuElement newPath[] = new MenuElement[0];
-                newPath = newList.toArray(newPath);
-                manager.setSelectedPath(newPath);
-                e.consume();
-            } else if (((JMenu)menuItem).isTopLevelMenu()
-                    && BasicPopupMenuUI.getLastPopup() == null) {
-                manager.clearSelectedPath();
-            }
-        }
-
-        public void menuKeyPressed(MenuKeyEvent e) {}
-        public void menuKeyReleased(MenuKeyEvent e) {}
     }
 }
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicPopupMenuUI.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicPopupMenuUI.java	Fri Oct 16 18:02:31 2009 -0700
@@ -339,7 +339,7 @@
                         indexes[matches++] = j;
                     }
                 }
-                if (item.isArmed()) {
+                if (item.isArmed() || item.isSelected()) {
                     currentIndex = matches - 1;
                 }
             }
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicTableUI.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicTableUI.java	Fri Oct 16 18:02:31 2009 -0700
@@ -1027,7 +1027,7 @@
                 shouldStartTimer =
                     table.isCellSelected(pressedRow, pressedCol) &&
                     !e.isShiftDown() &&
-                    !e.isControlDown() &&
+                    !BasicGraphicsUtils.isMenuShortcutKeyDown(e) &&
                     !outsidePrefSize;
             }
 
@@ -1051,7 +1051,7 @@
 
                 dragPressDidSelection = false;
 
-                if (e.isControlDown() && isFileList) {
+                if (BasicGraphicsUtils.isMenuShortcutKeyDown(e) && isFileList) {
                     // do nothing for control - will be handled on release
                     // or when drag starts
                     return;
@@ -1115,7 +1115,9 @@
 
             CellEditor editor = table.getCellEditor();
             if (dragEnabled || editor == null || editor.shouldSelectCell(e)) {
-                table.changeSelection(pressedRow, pressedCol, e.isControlDown(), e.isShiftDown());
+                table.changeSelection(pressedRow, pressedCol,
+                        BasicGraphicsUtils.isMenuShortcutKeyDown(e),
+                        e.isShiftDown());
             }
         }
 
@@ -1212,7 +1214,7 @@
         public void dragStarting(MouseEvent me) {
             dragStarted = true;
 
-            if (me.isControlDown() && isFileList) {
+            if (BasicGraphicsUtils.isMenuShortcutKeyDown(me) && isFileList) {
                 table.getSelectionModel().addSelectionInterval(pressedRow,
                                                                pressedRow);
                 table.getColumnModel().getSelectionModel().
@@ -1251,7 +1253,8 @@
                 return;
             }
 
-            table.changeSelection(row, column, e.isControlDown(), true);
+            table.changeSelection(row, column,
+                    BasicGraphicsUtils.isMenuShortcutKeyDown(e), true);
         }
 
 
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicTreeUI.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicTreeUI.java	Fri Oct 16 18:02:31 2009 -0700
@@ -2265,7 +2265,7 @@
      */
     protected boolean isToggleSelectionEvent(MouseEvent event) {
         return (SwingUtilities.isLeftMouseButton(event) &&
-                event.isControlDown());
+                BasicGraphicsUtils.isMenuShortcutKeyDown(event));
     }
 
     /**
@@ -3255,7 +3255,7 @@
             // handle first letter navigation
             if(tree != null && tree.getRowCount()>0 && tree.hasFocus() &&
                tree.isEnabled()) {
-                if (e.isAltDown() || e.isControlDown() || e.isMetaDown() ||
+                if (e.isAltDown() || BasicGraphicsUtils.isMenuShortcutKeyDown(e) ||
                     isNavigationKey(e)) {
                     return;
                 }
@@ -3511,7 +3511,7 @@
 
                 dragPressDidSelection = false;
 
-                if (e.isControlDown()) {
+                if (BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
                     // do nothing for control - will be handled on release
                     // or when drag starts
                     return;
@@ -3565,7 +3565,7 @@
         public void dragStarting(MouseEvent me) {
             dragStarted = true;
 
-            if (me.isControlDown()) {
+            if (BasicGraphicsUtils.isMenuShortcutKeyDown(me)) {
                 tree.addSelectionPath(pressedPath);
                 setAnchorSelectionPath(pressedPath);
                 setLeadSelectionPath(pressedPath, true);
--- a/jdk/src/share/classes/javax/swing/plaf/nimbus/skin.laf	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/javax/swing/plaf/nimbus/skin.laf	Fri Oct 16 18:02:31 2009 -0700
@@ -14824,7 +14824,9 @@
             <background/>
             <cacheSettingsInherited>false</cacheSettingsInherited>
             <cacheMode>NO_CACHING</cacheMode>
-            <uiproperties/>
+            <uiproperties>
+               <uiProperty name="textIconGap" type="INT" value="5"/>
+            </uiproperties>
          </style>
          <backgroundStates>
             <state stateKeys="Disabled">
--- a/jdk/src/share/classes/javax/swing/plaf/synth/SynthGraphicsUtils.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/javax/swing/plaf/synth/SynthGraphicsUtils.java	Fri Oct 16 18:02:31 2009 -0700
@@ -475,11 +475,11 @@
          return result;
      }
 
-    static void applyInsets(Rectangle rect, Insets insets) {
+    static void applyInsets(Rectangle rect, Insets insets, boolean leftToRight) {
         if (insets != null) {
-            rect.x += insets.left;
+            rect.x += (leftToRight ? insets.left : insets.right);
             rect.y += insets.top;
-            rect.width -= (insets.right + rect.x);
+            rect.width -= (leftToRight ? insets.right : insets.left) + rect.x;
             rect.height -= (insets.bottom + rect.y);
         }
     }
@@ -492,12 +492,12 @@
         g.setFont(style.getFont(context));
 
         Rectangle viewRect = new Rectangle(0, 0, mi.getWidth(), mi.getHeight());
-        applyInsets(viewRect, mi.getInsets());
+        boolean leftToRight = SynthLookAndFeel.isLeftToRight(mi);
+        applyInsets(viewRect, mi.getInsets(), leftToRight);
 
         SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper(
-                context, accContext, mi, checkIcon,
-                arrowIcon, viewRect, defaultTextIconGap, acceleratorDelimiter,
-                SynthLookAndFeel.isLeftToRight(mi),
+                context, accContext, mi, checkIcon, arrowIcon, viewRect,
+                defaultTextIconGap, acceleratorDelimiter, leftToRight,
                 MenuItemLayoutHelper.useCheckAndArrow(mi), propertyPrefix);
         MenuItemLayoutHelper.LayoutResult lr = lh.layoutMenuItem();
 
--- a/jdk/src/share/classes/javax/swing/text/DefaultCaret.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/javax/swing/text/DefaultCaret.java	Fri Oct 16 18:02:31 2009 -0700
@@ -510,7 +510,7 @@
         if ((e.getModifiers() & ActionEvent.SHIFT_MASK) != 0 &&
             getDot() != -1) {
             moveCaret(e);
-        } else {
+        } else if (!e.isPopupTrigger()) {
             positionCaret(e);
         }
     }
--- a/jdk/src/share/classes/javax/swing/text/TextLayoutStrategy.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/javax/swing/text/TextLayoutStrategy.java	Fri Oct 16 18:02:31 2009 -0700
@@ -30,6 +30,7 @@
 import java.text.BreakIterator;
 import java.awt.font.*;
 import java.awt.geom.AffineTransform;
+import javax.swing.JComponent;
 import javax.swing.event.DocumentEvent;
 import sun.font.BidiUtils;
 
@@ -301,6 +302,13 @@
             iter = BreakIterator.getLineInstance();
         }
 
+        Object shaper = null;
+        if (c instanceof JComponent) {
+            shaper = ((JComponent) c).getClientProperty(
+                                            TextAttribute.NUMERIC_SHAPING);
+        }
+        text.setShaper(shaper);
+
         measurer = new LineBreakMeasurer(text, iter, frc);
 
         // If the children of the FlowView's logical view are GlyphViews, they
@@ -399,6 +407,10 @@
             return pos - v.getStartOffset() + getBeginIndex();
         }
 
+        private void setShaper(Object shaper) {
+            this.shaper = shaper;
+        }
+
         // --- AttributedCharacterIterator methods -------------------------
 
         /**
@@ -511,6 +523,8 @@
             } else if( attribute == TextAttribute.RUN_DIRECTION ) {
                 return
                     v.getDocument().getProperty(TextAttribute.RUN_DIRECTION);
+            } else if (attribute == TextAttribute.NUMERIC_SHAPING) {
+                return shaper;
             }
             return null;
         }
@@ -532,8 +546,10 @@
             keys = new HashSet<Attribute>();
             keys.add(TextAttribute.FONT);
             keys.add(TextAttribute.RUN_DIRECTION);
+            keys.add(TextAttribute.NUMERIC_SHAPING);
         }
 
+        private Object shaper = null;
     }
 
 }
--- a/jdk/src/share/classes/sun/awt/AWTAutoShutdown.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/awt/AWTAutoShutdown.java	Fri Oct 16 18:02:31 2009 -0700
@@ -154,14 +154,17 @@
 
     /**
      * Add a specified thread to the set of busy event dispatch threads.
-     * If this set already contains the specified thread, the call leaves
-     * this set unchanged and returns silently.
+     * If this set already contains the specified thread or the thread is null,
+     * the call leaves this set unchanged and returns silently.
      *
      * @param thread thread to be added to this set, if not present.
      * @see     AWTAutoShutdown#notifyThreadFree
      * @see     AWTAutoShutdown#isReadyToShutdown
      */
     public void notifyThreadBusy(final Thread thread) {
+        if (thread == null) {
+            return;
+        }
         synchronized (activationLock) {
             synchronized (mainLock) {
                 if (blockerThread == null) {
@@ -177,14 +180,17 @@
 
     /**
      * Remove a specified thread from the set of busy event dispatch threads.
-     * If this set doesn't contain the specified thread, the call leaves
-     * this set unchanged and returns silently.
+     * If this set doesn't contain the specified thread or the thread is null,
+     * the call leaves this set unchanged and returns silently.
      *
      * @param thread thread to be removed from this set, if present.
      * @see     AWTAutoShutdown#notifyThreadBusy
      * @see     AWTAutoShutdown#isReadyToShutdown
      */
     public void notifyThreadFree(final Thread thread) {
+        if (thread == null) {
+            return;
+        }
         synchronized (activationLock) {
             synchronized (mainLock) {
                 busyThreadSet.remove(thread);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/sun/awt/AWTPermissionFactory.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package sun.awt;
+
+import java.awt.AWTPermission;
+import sun.security.util.PermissionFactory;
+
+/**
+ * A factory object for AWTPermission objects.
+ */
+
+public class AWTPermissionFactory
+    implements PermissionFactory<AWTPermission>
+{
+    @Override
+    public AWTPermission newPermission(String name) {
+        return new AWTPermission(name);
+    }
+}
--- a/jdk/src/share/classes/sun/awt/shell/ShellFolderManager.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/awt/shell/ShellFolderManager.java	Fri Oct 16 18:02:31 2009 -0700
@@ -57,8 +57,9 @@
      *    folders, such as Desktop, Documents, History, Network, Home, etc.
      *    This is used in the shortcut panel of the filechooser on Windows 2000
      *    and Windows Me.
-     *  "fileChooserIcon nn":
-     *    Returns an <code>Image</code> - icon nn from resource 124 in comctl32.dll (Windows only).
+     *  "fileChooserIcon <icon>":
+     *    Returns an <code>Image</code> - icon can be ListView, DetailsView, UpFolder, NewFolder or
+     *    ViewMenu (Windows only).
      *
      * @return An Object matching the key string.
      */
--- a/jdk/src/share/classes/sun/jkernel/DownloadManager.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/jkernel/DownloadManager.java	Fri Oct 16 18:02:31 2009 -0700
@@ -31,6 +31,7 @@
 import java.util.jar.*;
 import java.util.zip.*;
 import sun.misc.Launcher;
+import sun.misc.BootClassLoaderHook;
 
 /**
  * Handles the downloading of additional JRE components.  The bootstrap class
@@ -39,7 +40,7 @@
  *
  *@author Ethan Nicholas
  */
-public class DownloadManager {
+public class DownloadManager extends BootClassLoaderHook {
     public static final String KERNEL_DOWNLOAD_URL_PROPERTY =
             "kernel.download.url";
     public static final String KERNEL_DOWNLOAD_ENABLED_PROPERTY =
@@ -1023,7 +1024,8 @@
 
     /**
      * Returns <code>true</code> if the current thread is in the process of
-     * downloading a bundle.  This is called by ClassLoader.loadLibrary(), so
+     * downloading a bundle.  This is called by DownloadManager.loadLibrary()
+     * that is called by System.loadLibrary(), so
      * that when we run into a library required by the download process itself,
      * we don't call back into DownloadManager in an attempt to download it
      * (which would lead to infinite recursion).
@@ -1614,6 +1616,77 @@
 
     static native int getCurrentProcessId();
 
+    private DownloadManager() {
+    }
+
+    // Invoked by jkernel VM after the VM is initialized
+    static void setBootClassLoaderHook() {
+        if (!isJREComplete()) {
+            sun.misc.BootClassLoaderHook.setHook(new DownloadManager());
+        }
+    }
+
+    // Implementation of the BootClassLoaderHook interface
+    public String loadBootstrapClass(String name) {
+        // Check for download before we look for it.  If
+        // DownloadManager ends up downloading it, it will add it to
+        // our search path before we proceed to the findClass().
+        return DownloadManager.getBootClassPathEntryForClass(name);
+    }
+
+    public boolean loadLibrary(String name) {
+       try {
+            if (!DownloadManager.isJREComplete() &&
+                    !DownloadManager.isCurrentThreadDownloading()) {
+                return DownloadManager.downloadFile("bin/" +
+                    System.mapLibraryName(name));
+                // it doesn't matter if the downloadFile call returns false --
+                // it probably just means that this is a user library, as
+                // opposed to a JRE library
+            }
+        } catch (IOException e) {
+            throw new UnsatisfiedLinkError("Error downloading library " +
+                                                name + ": " + e);
+        } catch (NoClassDefFoundError e) {
+            // This happens while Java itself is being compiled; DownloadManager
+            // isn't accessible when this code is first invoked.  It isn't an
+            // issue, as if we can't find DownloadManager, we can safely assume
+            // that additional code is not available for download.
+        }
+        return false;
+    }
+
+    public boolean prefetchFile(String name) {
+        try {
+            return sun.jkernel.DownloadManager.downloadFile(name);
+        } catch (IOException ioe) {
+            return false;
+        }
+    }
+
+    public String getBootstrapResource(String name) {
+        try {
+            // If this is a known JRE resource, ensure that its bundle is
+            // downloaded.  If it isn't known, we just ignore the download
+            // failure and check to see if we can find the resource anyway
+            // (which is possible if the boot class path has been modified).
+            return DownloadManager.getBootClassPathEntryForResource(name);
+        } catch (NoClassDefFoundError e) {
+            // This happens while Java itself is being compiled; DownloadManager
+            // isn't accessible when this code is first invoked.  It isn't an
+            // issue, as if we can't find DownloadManager, we can safely assume
+            // that additional code is not available for download.
+            return null;
+        }
+    }
+
+    public File[] getAdditionalBootstrapPaths() {
+        return DownloadManager.getAdditionalBootStrapPaths();
+    }
+
+    public boolean isCurrentThreadPrefetching() {
+        return DownloadManager.isCurrentThreadDownloading();
+    }
 
     public static void main(String[] arg) throws Exception {
         AccessController.checkPermission(new AllPermission());
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/sun/misc/BootClassLoaderHook.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,153 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package sun.misc;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * BootClassLoaderHook defines an interface for a hook to inject
+ * into the bootstrap class loader.
+ *
+ * In jkernel build, the sun.jkernel.DownloadManager is set as
+ * a BootClassLoaderHook by the jkernel VM after the VM is initialized.
+ *
+ * In other JDK builds, no hook is set.
+ */
+public abstract class BootClassLoaderHook {
+    private static BootClassLoaderHook bootLoaderHook = null;
+    public static synchronized BootClassLoaderHook getHook() {
+        return bootLoaderHook;
+    }
+
+    public static synchronized void setHook(BootClassLoaderHook hook) {
+        if (!VM.isBooted()) {
+            throw new InternalError("hook can only be set after VM is booted");
+        }
+        if (bootLoaderHook != null) {
+            throw new InternalError("hook should not be reinitialized");
+        }
+        bootLoaderHook = hook;
+    }
+
+    protected BootClassLoaderHook() {
+    }
+
+    /**
+     * A method to be invoked before a class loader loads
+     * a bootstrap class.
+     *
+     * @param classname the binary name of the class
+     */
+    public static void preLoadClass(String classname) {
+        BootClassLoaderHook hook = getHook();
+        if (hook != null) {
+            hook.loadBootstrapClass(classname);
+        }
+    }
+
+    /**
+     * A method to be invoked before a class loader loads
+     * a resource.
+     *
+     * @param resourcename the resource name
+     */
+    public static void preLoadResource(String resourcename) {
+        BootClassLoaderHook hook = getHook();
+        if (hook != null) {
+            hook.getBootstrapResource(resourcename);
+        }
+    }
+
+    /**
+     * A method to be invoked before a library is loaded.
+     *
+     * @param libname the name of the library
+     */
+    public static void preLoadLibrary(String libname) {
+        BootClassLoaderHook hook = getHook();
+        if (hook != null) {
+            hook.loadLibrary(libname);
+        }
+    }
+
+    private static final File[] EMPTY_FILE_ARRAY = new File[0];
+
+    /**
+     * Returns bootstrap class paths added by the hook.
+     */
+    public static File[] getBootstrapPaths() {
+        BootClassLoaderHook hook = getHook();
+        if (hook != null) {
+            return hook.getAdditionalBootstrapPaths();
+        } else {
+            return EMPTY_FILE_ARRAY;
+        }
+    }
+
+    /**
+     * Returns a pathname of a JAR or class that the hook loads
+     * per this loadClass request; or null.
+     *
+     * @param classname the binary name of the class
+     */
+    public abstract String loadBootstrapClass(String className);
+
+    /**
+     * Returns a pathname of a resource file that the hook loads
+     * per this getResource request; or null.
+     *
+     * @param resourceName the resource name
+     */
+    public abstract String getBootstrapResource(String resourceName);
+
+    /**
+     * Returns true if the hook successfully performs an operation per
+     * this loadLibrary request; or false if it fails.
+     *
+     * @param libname the name of the library
+     */
+    public abstract boolean loadLibrary(String libname);
+
+    /**
+     * Returns additional boot class paths added by the hook that
+     * should be searched by the boot class loader.
+     */
+    public abstract File[] getAdditionalBootstrapPaths();
+
+    /**
+     * Returns true if the current thread is in the process of doing
+     * a prefetching operation.
+     */
+    public abstract boolean isCurrentThreadPrefetching();
+
+    /**
+     * Returns true if the hook successfully prefetches the specified file.
+     *
+     * @param name a platform independent pathname
+     */
+    public abstract boolean prefetchFile(String name);
+}
--- a/jdk/src/share/classes/sun/misc/Launcher.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/misc/Launcher.java	Fri Oct 16 18:02:31 2009 -0700
@@ -50,8 +50,6 @@
 import sun.security.action.GetPropertyAction;
 import sun.security.util.SecurityConstants;
 import sun.net.www.ParseUtil;
-import sun.jkernel.Bundle;
-import sun.jkernel.DownloadManager;
 
 /**
  * This class is used by the system to launch the main application.
@@ -248,12 +246,7 @@
         }
 
         protected Class findClass(String name) throws ClassNotFoundException {
-            if (VM.isBootedKernelVM()) {
-                // Check for download before we look for it.  If
-                // DownloadManager ends up downloading it, it will add it to
-                // our search path before we proceed to the findClass().
-                DownloadManager.getBootClassPathEntryForClass(name);
-            }
+            BootClassLoaderHook.preLoadClass(name);
             return super.findClass(name);
         }
 
@@ -321,9 +314,7 @@
         public Class loadClass(String name, boolean resolve)
             throws ClassNotFoundException
         {
-            if (VM.isBootedKernelVM()) {
-                DownloadManager.getBootClassPathEntryForClass(name);
-            }
+            BootClassLoaderHook.preLoadClass(name);
             int i = name.lastIndexOf('.');
             if (i != -1) {
                 SecurityManager sm = System.getSecurityManager();
@@ -421,19 +412,17 @@
             }
 
             bootstrapClassPath = new URLClassPath(urls, factory);
-            if (VM.isBootedKernelVM()) {
-                final File[] additionalBootStrapPaths =
-                    DownloadManager.getAdditionalBootStrapPaths();
-                AccessController.doPrivileged(new PrivilegedAction() {
-                    public Object run() {
-                        for (int i=0; i<additionalBootStrapPaths.length; i++) {
-                            bootstrapClassPath.addURL(
-                                getFileURL(additionalBootStrapPaths[i]));
-                        }
-                        return null;
+            final File[] additionalBootStrapPaths =
+                BootClassLoaderHook.getBootstrapPaths();
+            AccessController.doPrivileged(new PrivilegedAction() {
+                public Object run() {
+                    for (int i=0; i<additionalBootStrapPaths.length; i++) {
+                        bootstrapClassPath.addURL(
+                            getFileURL(additionalBootStrapPaths[i]));
                     }
-                });
-            }
+                    return null;
+                }
+            });
         }
         return bootstrapClassPath;
     }
--- a/jdk/src/share/classes/sun/misc/VM.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/misc/VM.java	Fri Oct 16 18:02:31 2009 -0700
@@ -346,11 +346,6 @@
     private native static void getThreadStateValues(int[][] vmThreadStateValues,
                                                     String[][] vmThreadStateNames);
 
-    private static boolean kernelVM;
-    public static boolean isBootedKernelVM() {
-        return booted && kernelVM;
-    }
-
     static {
         initialize();
     }
--- a/jdk/src/share/classes/sun/net/www/protocol/http/AuthenticationInfo.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/net/www/protocol/http/AuthenticationInfo.java	Fri Oct 16 18:02:31 2009 -0700
@@ -399,13 +399,6 @@
     abstract boolean isAuthorizationStale (String header);
 
     /**
-     * Check for any expected authentication information in the response
-     * from the server
-     */
-    abstract void checkResponse (String header, String method, URL url)
-                                        throws IOException;
-
-    /**
      * Give a key for hash table lookups.
      * @param includeRealm if you want the realm considered.  Preemptively
      *          setting an authorization is done before the realm is known.
--- a/jdk/src/share/classes/sun/net/www/protocol/http/BasicAuthentication.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/net/www/protocol/http/BasicAuthentication.java	Fri Oct 16 18:02:31 2009 -0700
@@ -179,13 +179,6 @@
     }
 
     /**
-     * For Basic Authentication, there is no security information in the
-     * response
-     */
-    void checkResponse (String header, String method, URL url) {
-    }
-
-    /**
      * @return the common root path between npath and path.
      * This is used to detect when we have an authentication for two
      * paths and the root of th authentication space is the common root.
--- a/jdk/src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java	Fri Oct 16 18:02:31 2009 -0700
@@ -291,7 +291,7 @@
             uri = HttpURLConnection.connectRequestURI(conn.getURL());
             method = HTTP_CONNECT;
         } else {
-            uri = conn.getURL().getFile();
+            uri = conn.getRequestURI();
             method = conn.getMethod();
         }
 
@@ -385,7 +385,11 @@
 
     public void checkResponse (String header, String method, URL url)
                                                         throws IOException {
-        String uri = url.getFile();
+        checkResponse (header, method, url.getFile());
+    }
+
+    public void checkResponse (String header, String method, String uri)
+                                                        throws IOException {
         char[] passwd = pw.getPassword();
         String username = pw.getUserName();
         boolean qop = params.authQop();
--- a/jdk/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java	Fri Oct 16 18:02:31 2009 -0700
@@ -390,7 +390,7 @@
              * request.
              */
             if (!failedOnce)
-                requests.prepend(method + " " + http.getURLFile()+" "  +
+                requests.prepend(method + " " + getRequestURI()+" "  +
                                  httpVersion, null);
             if (!getUseCaches()) {
                 requests.setIfNotSet ("Cache-Control", "no-cache");
@@ -1546,10 +1546,14 @@
             if (proxyAuthentication.isAuthorizationStale (raw)) {
                 /* we can retry with the current credentials */
                 String value;
-                if (tunnelState() == TunnelState.SETUP &&
-                      proxyAuthentication instanceof DigestAuthentication) {
-                    value = ((DigestAuthentication)proxyAuthentication)
-                            .getHeaderValue(connectRequestURI(url), HTTP_CONNECT);
+                if (proxyAuthentication instanceof DigestAuthentication) {
+                    DigestAuthentication digestProxy = (DigestAuthentication)
+                        proxyAuthentication;
+                    if (tunnelState() == TunnelState.SETUP) {
+                        value = digestProxy.getHeaderValue(connectRequestURI(url), HTTP_CONNECT);
+                    } else {
+                        value = digestProxy.getHeaderValue(getRequestURI(), method);
+                    }
                 } else {
                     value = proxyAuthentication.getHeaderValue(url, method);
                 }
@@ -1765,10 +1769,14 @@
                                               http.getProxyPortUsed());
         if (pauth != null && pauth.supportsPreemptiveAuthorization()) {
             String value;
-            if (tunnelState() == TunnelState.SETUP &&
-                    pauth instanceof DigestAuthentication) {
-                value = ((DigestAuthentication)pauth)
+            if (pauth instanceof DigestAuthentication) {
+                DigestAuthentication digestProxy = (DigestAuthentication) pauth;
+                if (tunnelState() == TunnelState.SETUP) {
+                    value = digestProxy
                         .getHeaderValue(connectRequestURI(url), HTTP_CONNECT);
+                } else {
+                    value = digestProxy.getHeaderValue(getRequestURI(), method);
+                }
             } else {
                 value = pauth.getHeaderValue(url, method);
             }
@@ -2075,17 +2083,23 @@
         try {
             if (!needToCheck)
                 return;
-            if (validateProxy && currentProxyCredentials != null) {
+            if ((validateProxy && currentProxyCredentials != null) &&
+                (currentProxyCredentials instanceof DigestAuthentication)) {
                 String raw = responses.findValue ("Proxy-Authentication-Info");
                 if (inClose || (raw != null)) {
-                    currentProxyCredentials.checkResponse (raw, method, url);
+                    DigestAuthentication da = (DigestAuthentication)
+                        currentProxyCredentials;
+                    da.checkResponse (raw, method, getRequestURI());
                     currentProxyCredentials = null;
                 }
             }
-            if (validateServer && currentServerCredentials != null) {
+            if ((validateServer && currentServerCredentials != null) &&
+                (currentServerCredentials instanceof DigestAuthentication)) {
                 String raw = responses.findValue ("Authentication-Info");
                 if (inClose || (raw != null)) {
-                    currentServerCredentials.checkResponse (raw, method, url);
+                    DigestAuthentication da = (DigestAuthentication)
+                        currentServerCredentials;
+                    da.checkResponse (raw, method, url);
                     currentServerCredentials = null;
                 }
             }
@@ -2099,6 +2113,23 @@
         }
     }
 
+   /* The request URI used in the request line for this request.
+    * Also, needed for digest authentication
+    */
+
+    String requestURI = null;
+
+    String getRequestURI() {
+        if (requestURI == null) {
+            try {
+                requestURI = http.getURLFile();
+            } catch (IOException e) {
+                requestURI = "";
+            }
+        }
+        return requestURI;
+    }
+
     /* Tells us whether to follow a redirect.  If so, it
      * closes the connection (break any keep-alive) and
      * resets the url, re-connects, and resets the request
@@ -2160,13 +2191,14 @@
             }
 
             setProxiedClient (url, proxyHost, proxyPort);
-            requests.set(0, method + " " + http.getURLFile()+" "  +
+            requests.set(0, method + " " + getRequestURI()+" "  +
                              httpVersion, null);
             connected = true;
         } else {
             // maintain previous headers, just change the name
             // of the file we're getting
             url = locUrl;
+            requestURI = null; // force it to be recalculated
             if (method.equals("POST") && !Boolean.getBoolean("http.strictPostRedirect") && (stat!=307)) {
                 /* The HTTP/1.1 spec says that a redirect from a POST
                  * *should not* be immediately turned into a GET, and
@@ -2204,7 +2236,7 @@
                  * CacheResponse.
                  */
                 if (http != null) {
-                    requests.set(0, method + " " + http.getURLFile()+" "  +
+                    requests.set(0, method + " " + getRequestURI()+" "  +
                                  httpVersion, null);
                     int port = url.getPort();
                     String host = url.getHost();
--- a/jdk/src/share/classes/sun/net/www/protocol/http/NegotiateAuthentication.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/net/www/protocol/http/NegotiateAuthentication.java	Fri Oct 16 18:02:31 2009 -0700
@@ -214,12 +214,6 @@
         return negotiator.nextToken(token);
     }
 
-    /**
-     * no-use for Negotiate
-     */
-    public void checkResponse (String header, String method, URL url) throws IOException {
-    }
-
     class B64Encoder extends BASE64Encoder {
         protected int bytesPerLine () {
             return 100000;  // as big as it can be, maybe INT_MAX
--- a/jdk/src/share/classes/sun/net/www/protocol/https/HttpsClient.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/net/www/protocol/https/HttpsClient.java	Fri Oct 16 18:02:31 2009 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001-2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2001-2009 Sun Microsystems, Inc.  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
@@ -461,12 +461,16 @@
         }
 
         Certificate[] peerCerts = null;
+        String cipher = session.getCipherSuite();
         try {
             HostnameChecker checker = HostnameChecker.getInstance(
                                                 HostnameChecker.TYPE_TLS);
 
             Principal principal = getPeerPrincipal();
-            if (principal instanceof KerberosPrincipal) {
+            // X.500 principal or Kerberos principal.
+            // (Use ciphersuite check to determine whether Kerberos is present.)
+            if (cipher.startsWith("TLS_KRB5") &&
+                    principal instanceof KerberosPrincipal) {
                 if (!checker.match(host, (KerberosPrincipal)principal)) {
                     throw new SSLPeerUnverifiedException("Hostname checker" +
                                 " failed for Kerberos");
@@ -499,7 +503,6 @@
             // ignore
         }
 
-        String cipher = session.getCipherSuite();
         if ((cipher != null) && (cipher.indexOf("_anon_") != -1)) {
             return;
         } else if ((hostnameVerifier != null) &&
--- a/jdk/src/share/classes/sun/nio/ch/ChannelInputStream.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/nio/ch/ChannelInputStream.java	Fri Oct 16 18:02:31 2009 -0700
@@ -109,6 +109,16 @@
         return ChannelInputStream.read(ch, bb, true);
     }
 
+    public int available() throws IOException {
+        // special case where the channel is to a file
+        if (ch instanceof SeekableByteChannel) {
+            SeekableByteChannel sbc = (SeekableByteChannel)ch;
+            long rem = Math.max(0, sbc.size() - sbc.position());
+            return (rem > Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int)rem;
+        }
+        return 0;
+    }
+
     public void close() throws IOException {
         ch.close();
     }
--- a/jdk/src/share/classes/sun/reflect/LangReflectAccess.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/reflect/LangReflectAccess.java	Fri Oct 16 18:02:31 2009 -0700
@@ -33,9 +33,9 @@
 public interface LangReflectAccess {
     /** Creates a new java.lang.reflect.Field. Access checks as per
         java.lang.reflect.AccessibleObject are not overridden. */
-    public Field newField(Class declaringClass,
+    public Field newField(Class<?> declaringClass,
                           String name,
-                          Class type,
+                          Class<?> type,
                           int modifiers,
                           int slot,
                           String signature,
@@ -43,11 +43,11 @@
 
     /** Creates a new java.lang.reflect.Method. Access checks as per
       java.lang.reflect.AccessibleObject are not overridden. */
-    public Method newMethod(Class declaringClass,
+    public Method newMethod(Class<?> declaringClass,
                             String name,
-                            Class[] parameterTypes,
-                            Class returnType,
-                            Class[] checkedExceptions,
+                            Class<?>[] parameterTypes,
+                            Class<?> returnType,
+                            Class<?>[] checkedExceptions,
                             int modifiers,
                             int slot,
                             String signature,
@@ -58,8 +58,8 @@
     /** Creates a new java.lang.reflect.Constructor. Access checks as
       per java.lang.reflect.AccessibleObject are not overridden. */
     public <T> Constructor<T> newConstructor(Class<T> declaringClass,
-                                             Class[] parameterTypes,
-                                             Class[] checkedExceptions,
+                                             Class<?>[] parameterTypes,
+                                             Class<?>[] checkedExceptions,
                                              int modifiers,
                                              int slot,
                                              String signature,
@@ -74,24 +74,24 @@
 
     /** Gets the ConstructorAccessor object for a
         java.lang.reflect.Constructor */
-    public ConstructorAccessor getConstructorAccessor(Constructor c);
+    public ConstructorAccessor getConstructorAccessor(Constructor<?> c);
 
     /** Sets the ConstructorAccessor object for a
         java.lang.reflect.Constructor */
-    public void setConstructorAccessor(Constructor c,
+    public void setConstructorAccessor(Constructor<?> c,
                                        ConstructorAccessor accessor);
 
     /** Gets the "slot" field from a Constructor (used for serialization) */
-    public int getConstructorSlot(Constructor c);
+    public int getConstructorSlot(Constructor<?> c);
 
     /** Gets the "signature" field from a Constructor (used for serialization) */
-    public String getConstructorSignature(Constructor c);
+    public String getConstructorSignature(Constructor<?> c);
 
     /** Gets the "annotations" field from a Constructor (used for serialization) */
-    public byte[] getConstructorAnnotations(Constructor c);
+    public byte[] getConstructorAnnotations(Constructor<?> c);
 
     /** Gets the "parameterAnnotations" field from a Constructor (used for serialization) */
-    public byte[] getConstructorParameterAnnotations(Constructor c);
+    public byte[] getConstructorParameterAnnotations(Constructor<?> c);
 
     //
     // Copying routines, needed to quickly fabricate new Field,
--- a/jdk/src/share/classes/sun/reflect/annotation/AnnotationInvocationHandler.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/reflect/annotation/AnnotationInvocationHandler.java	Fri Oct 16 18:02:31 2009 -0700
@@ -40,17 +40,17 @@
  * @since   1.5
  */
 class AnnotationInvocationHandler implements InvocationHandler, Serializable {
-    private final Class type;
+    private final Class<? extends Annotation> type;
     private final Map<String, Object> memberValues;
 
-    AnnotationInvocationHandler(Class type, Map<String, Object> memberValues) {
+    AnnotationInvocationHandler(Class<? extends Annotation> type, Map<String, Object> memberValues) {
         this.type = type;
         this.memberValues = memberValues;
     }
 
     public Object invoke(Object proxy, Method method, Object[] args) {
         String member = method.getName();
-        Class[] paramTypes = method.getParameterTypes();
+        Class<?>[] paramTypes = method.getParameterTypes();
 
         // Handle Object and Annotation methods
         if (member.equals("equals") && paramTypes.length == 1 &&
@@ -84,7 +84,7 @@
      * if Cloneable had a public clone method.
      */
     private Object cloneArray(Object array) {
-        Class type = array.getClass();
+        Class<?> type = array.getClass();
 
         if (type == byte[].class) {
             byte[] byteArray = (byte[])array;
@@ -151,7 +151,7 @@
      * Translates a member value (in "dynamic proxy return form") into a string
      */
     private static String memberValueToString(Object value) {
-        Class type = value.getClass();
+        Class<?> type = value.getClass();
         if (!type.isArray())    // primitive, string, class, enum const,
                                 // or annotation
             return value.toString();
@@ -229,7 +229,7 @@
      * two members are identical object references.
      */
     private static boolean memberValueEquals(Object v1, Object v2) {
-        Class type = v1.getClass();
+        Class<?> type = v1.getClass();
 
         // Check for primitive, string, class, enum const, annotation,
         // or ExceptionProxy
@@ -301,7 +301,7 @@
      * Computes hashCode of a member value (in "dynamic proxy return form")
      */
     private static int memberValueHashCode(Object value) {
-        Class type = value.getClass();
+        Class<?> type = value.getClass();
         if (!type.isArray())    // primitive, string, class, enum const,
                                 // or annotation
             return value.hashCode();
@@ -340,11 +340,11 @@
             return;
         }
 
-        Map<String, Class> memberTypes = annotationType.memberTypes();
+        Map<String, Class<?>> memberTypes = annotationType.memberTypes();
 
         for (Map.Entry<String, Object> memberValue : memberValues.entrySet()) {
             String name = memberValue.getKey();
-            Class memberType = memberTypes.get(name);
+            Class<?> memberType = memberTypes.get(name);
             if (memberType != null) {  // i.e. member still exists
                 Object value = memberValue.getValue();
                 if (!(memberType.isInstance(value) ||
--- a/jdk/src/share/classes/sun/reflect/annotation/AnnotationParser.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/reflect/annotation/AnnotationParser.java	Fri Oct 16 18:02:31 2009 -0700
@@ -59,10 +59,10 @@
      * @throws AnnotationFormatError if an annotation is found to be
      *         malformed.
      */
-    public static Map<Class, Annotation> parseAnnotations(
+    public static Map<Class<? extends Annotation>, Annotation> parseAnnotations(
                 byte[] rawAnnotations,
                 ConstantPool constPool,
-                Class container) {
+                Class<?> container) {
         if (rawAnnotations == null)
             return Collections.emptyMap();
 
@@ -76,17 +76,18 @@
         }
     }
 
-    private static Map<Class, Annotation> parseAnnotations2(
+    private static Map<Class<? extends Annotation>, Annotation> parseAnnotations2(
                 byte[] rawAnnotations,
                 ConstantPool constPool,
-                Class container) {
-        Map<Class, Annotation> result = new LinkedHashMap<Class, Annotation>();
+                Class<?> container) {
+        Map<Class<? extends Annotation>, Annotation> result =
+            new LinkedHashMap<Class<? extends Annotation>, Annotation>();
         ByteBuffer buf = ByteBuffer.wrap(rawAnnotations);
         int numAnnotations = buf.getShort() & 0xFFFF;
         for (int i = 0; i < numAnnotations; i++) {
             Annotation a = parseAnnotation(buf, constPool, container, false);
             if (a != null) {
-                Class klass = a.annotationType();
+                Class<? extends Annotation> klass = a.annotationType();
                 AnnotationType type = AnnotationType.getInstance(klass);
                 if (type.retention() == RetentionPolicy.RUNTIME)
                     if (result.put(klass, a) != null)
@@ -123,7 +124,7 @@
     public static Annotation[][] parseParameterAnnotations(
                     byte[] rawAnnotations,
                     ConstantPool constPool,
-                    Class container) {
+                    Class<?> container) {
         try {
             return parseParameterAnnotations2(rawAnnotations, constPool, container);
         } catch(BufferUnderflowException e) {
@@ -138,7 +139,7 @@
     private static Annotation[][] parseParameterAnnotations2(
                     byte[] rawAnnotations,
                     ConstantPool constPool,
-                    Class container) {
+                    Class<?> container) {
         ByteBuffer buf = ByteBuffer.wrap(rawAnnotations);
         int numParameters = buf.get() & 0xFF;
         Annotation[][] result = new Annotation[numParameters][];
@@ -188,15 +189,15 @@
      */
     private static Annotation parseAnnotation(ByteBuffer buf,
                                               ConstantPool constPool,
-                                              Class container,
+                                              Class<?> container,
                                               boolean exceptionOnMissingAnnotationClass) {
         int typeIndex = buf.getShort() & 0xFFFF;
-        Class annotationClass = null;
+        Class<? extends Annotation> annotationClass = null;
         String sig = "[unknown]";
         try {
             try {
                 sig = constPool.getUTF8At(typeIndex);
-                annotationClass = parseSig(sig, container);
+                annotationClass = (Class<? extends Annotation>)parseSig(sig, container);
             } catch (IllegalArgumentException ex) {
                 // support obsolete early jsr175 format class files
                 annotationClass = constPool.getClassAt(typeIndex);
@@ -223,7 +224,7 @@
             return null;
         }
 
-        Map<String, Class> memberTypes = type.memberTypes();
+        Map<String, Class<?>> memberTypes = type.memberTypes();
         Map<String, Object> memberValues =
             new LinkedHashMap<String, Object>(type.memberDefaults());
 
@@ -231,7 +232,7 @@
         for (int i = 0; i < numMembers; i++) {
             int memberNameIndex = buf.getShort() & 0xFFFF;
             String memberName = constPool.getUTF8At(memberNameIndex);
-            Class memberType = memberTypes.get(memberName);
+            Class<?> memberType = memberTypes.get(memberName);
 
             if (memberType == null) {
                 // Member is no longer present in annotation type; ignore it
@@ -252,7 +253,7 @@
      * member -> value map.
      */
     public static Annotation annotationForMap(
-        Class type, Map<String, Object> memberValues)
+        Class<? extends Annotation> type, Map<String, Object> memberValues)
     {
         return (Annotation) Proxy.newProxyInstance(
             type.getClassLoader(), new Class[] { type },
@@ -286,14 +287,15 @@
      * The member must be of the indicated type. If it is not, this
      * method returns an AnnotationTypeMismatchExceptionProxy.
      */
-    public static Object parseMemberValue(Class memberType, ByteBuffer buf,
+    public static Object parseMemberValue(Class<?> memberType,
+                                          ByteBuffer buf,
                                           ConstantPool constPool,
-                                          Class container) {
+                                          Class<?> container) {
         Object result = null;
         int tag = buf.get();
         switch(tag) {
           case 'e':
-              return parseEnumValue(memberType, buf, constPool, container);
+              return parseEnumValue((Class<? extends Enum<?>>)memberType, buf, constPool, container);
           case 'c':
               result = parseClassValue(buf, constPool, container);
               break;
@@ -361,7 +363,7 @@
      */
     private static Object parseClassValue(ByteBuffer buf,
                                           ConstantPool constPool,
-                                          Class container) {
+                                          Class<?> container) {
         int classIndex = buf.getShort() & 0xFFFF;
         try {
             try {
@@ -379,7 +381,7 @@
         }
     }
 
-    private static Class<?> parseSig(String sig, Class container) {
+    private static Class<?> parseSig(String sig, Class<?> container) {
         if (sig.equals("V")) return void.class;
         SignatureParser parser = SignatureParser.make();
         TypeSignature typeSig = parser.parseTypeSig(sig);
@@ -389,7 +391,7 @@
         Type result = reify.getResult();
         return toClass(result);
     }
-    static Class toClass(Type o) {
+    static Class<?> toClass(Type o) {
         if (o instanceof GenericArrayType)
             return Array.newInstance(toClass(((GenericArrayType)o).getGenericComponentType()),
                                      0)
@@ -409,9 +411,9 @@
      *           u2   const_name_index;
      *       } enum_const_value;
      */
-    private static Object parseEnumValue(Class enumType, ByteBuffer buf,
+    private static Object parseEnumValue(Class<? extends Enum> enumType, ByteBuffer buf,
                                          ConstantPool constPool,
-                                         Class container) {
+                                         Class<?> container) {
         int typeNameIndex = buf.getShort() & 0xFFFF;
         String typeName  = constPool.getUTF8At(typeNameIndex);
         int constNameIndex = buf.getShort() & 0xFFFF;
@@ -449,12 +451,12 @@
      * If the array values do not match arrayType, an
      * AnnotationTypeMismatchExceptionProxy will be returned.
      */
-    private static Object parseArray(Class arrayType,
+    private static Object parseArray(Class<?> arrayType,
                                      ByteBuffer buf,
                                      ConstantPool constPool,
-                                     Class container) {
+                                     Class<?> container) {
         int length = buf.getShort() & 0xFFFF;  // Number of array components
-        Class componentType = arrayType.getComponentType();
+        Class<?> componentType = arrayType.getComponentType();
 
         if (componentType == byte.class) {
             return parseByteArray(length, buf, constPool);
@@ -477,11 +479,11 @@
         } else if (componentType == Class.class) {
             return parseClassArray(length, buf, constPool, container);
         } else if (componentType.isEnum()) {
-            return parseEnumArray(length, componentType, buf,
+            return parseEnumArray(length, (Class<? extends Enum>)componentType, buf,
                                   constPool, container);
         } else {
             assert componentType.isAnnotation();
-            return parseAnnotationArray(length, componentType, buf,
+            return parseAnnotationArray(length, (Class <? extends Annotation>)componentType, buf,
                                         constPool, container);
         }
     }
@@ -660,8 +662,8 @@
     private static Object parseClassArray(int length,
                                           ByteBuffer buf,
                                           ConstantPool constPool,
-                                          Class container) {
-        Object[] result = new Class[length];
+                                          Class<?> container) {
+        Object[] result = new Class<?>[length];
         boolean typeMismatch = false;
         int tag = 0;
 
@@ -677,10 +679,10 @@
         return typeMismatch ? exceptionProxy(tag) : result;
     }
 
-    private static Object parseEnumArray(int length, Class enumType,
+    private static Object parseEnumArray(int length, Class<? extends Enum> enumType,
                                          ByteBuffer buf,
                                          ConstantPool constPool,
-                                         Class container) {
+                                         Class<?> container) {
         Object[] result = (Object[]) Array.newInstance(enumType, length);
         boolean typeMismatch = false;
         int tag = 0;
@@ -698,10 +700,10 @@
     }
 
     private static Object parseAnnotationArray(int length,
-                                               Class annotationType,
+                                               Class<? extends Annotation> annotationType,
                                                ByteBuffer buf,
                                                ConstantPool constPool,
-                                               Class container) {
+                                               Class<?> container) {
         Object[] result = (Object[]) Array.newInstance(annotationType, length);
         boolean typeMismatch = false;
         int tag = 0;
@@ -797,7 +799,7 @@
      * it is needed.
      */
     private static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0];
-    public static Annotation[] toArray(Map<Class, Annotation> annotations) {
+    public static Annotation[] toArray(Map<Class<? extends Annotation>, Annotation> annotations) {
         return annotations.values().toArray(EMPTY_ANNOTATION_ARRAY);
     }
 }
--- a/jdk/src/share/classes/sun/reflect/annotation/AnnotationType.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/reflect/annotation/AnnotationType.java	Fri Oct 16 18:02:31 2009 -0700
@@ -45,7 +45,7 @@
      * types.  This matches the return value that must be used for a
      * dynamic proxy, allowing for a simple isInstance test.
      */
-    private final Map<String, Class> memberTypes = new HashMap<String,Class>();
+    private final Map<String, Class<?>> memberTypes = new HashMap<String,Class<?>>();
 
     /**
      * Member name -> default value mapping.
@@ -76,12 +76,12 @@
      *     does not represent a valid annotation type
      */
     public static synchronized AnnotationType getInstance(
-        Class annotationClass)
+        Class<? extends Annotation> annotationClass)
     {
         AnnotationType result = sun.misc.SharedSecrets.getJavaLangAccess().
             getAnnotationType(annotationClass);
         if (result == null)
-            result = new AnnotationType((Class<?>) annotationClass);
+            result = new AnnotationType((Class<? extends Annotation>) annotationClass);
 
         return result;
     }
@@ -93,7 +93,7 @@
      * @throw IllegalArgumentException if the specified class object for
      *     does not represent a valid annotation type
      */
-    private AnnotationType(final Class<?> annotationClass) {
+    private AnnotationType(final Class<? extends Annotation> annotationClass) {
         if (!annotationClass.isAnnotation())
             throw new IllegalArgumentException("Not an annotation type");
 
@@ -110,7 +110,7 @@
             if (method.getParameterTypes().length != 0)
                 throw new IllegalArgumentException(method + " has params");
             String name = method.getName();
-            Class type = method.getReturnType();
+            Class<?> type = method.getReturnType();
             memberTypes.put(name, invocationHandlerReturnType(type));
             members.put(name, method);
 
@@ -140,7 +140,7 @@
      * the specified type (which is assumed to be a legal member type
      * for an annotation).
      */
-    public static Class invocationHandlerReturnType(Class type) {
+    public static Class<?> invocationHandlerReturnType(Class<?> type) {
         // Translate primitives to wrappers
         if (type == byte.class)
             return Byte.class;
@@ -167,7 +167,7 @@
      * Returns member types for this annotation type
      * (member name -> type mapping).
      */
-    public Map<String, Class> memberTypes() {
+    public Map<String, Class<?>> memberTypes() {
         return memberTypes;
     }
 
--- a/jdk/src/share/classes/sun/security/krb5/Credentials.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/security/krb5/Credentials.java	Fri Oct 16 18:02:31 2009 -0700
@@ -33,16 +33,11 @@
 
 import sun.security.krb5.internal.*;
 import sun.security.krb5.internal.ccache.CredentialsCache;
-import java.util.StringTokenizer;
 import sun.security.krb5.internal.ktab.*;
 import sun.security.krb5.internal.crypto.EType;
 import java.io.File;
 import java.io.IOException;
 import java.util.Date;
-import java.util.Vector;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
 import java.net.InetAddress;
 
 /**
@@ -378,9 +373,9 @@
 
                 KRBError error = ke.getError();
                 // update salt in PrincipalName
-                byte[] newSalt = error.getSalt();
-                if (newSalt != null && newSalt.length > 0) {
-                    princ.setSalt(new String(newSalt));
+                String newSalt = error.getSalt();
+                if (newSalt != null && newSalt.length() > 0) {
+                    princ.setSalt(newSalt);
                 }
 
                 // refresh keys
--- a/jdk/src/share/classes/sun/security/krb5/KrbAsReq.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/security/krb5/KrbAsReq.java	Fri Oct 16 18:02:31 2009 -0700
@@ -1,5 +1,5 @@
 /*
- * Portions Copyright 2000-2007 Sun Microsystems, Inc.  All Rights Reserved.
+ * Portions Copyright 2000-2009 Sun Microsystems, Inc.  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
@@ -56,7 +56,7 @@
     private boolean PA_ENC_TIMESTAMP_REQUIRED = false;
     private boolean pa_exists = false;
     private int pa_etype = 0;
-    private byte[] pa_salt = null;
+    private String pa_salt = null;
     private byte[] pa_s2kparams = null;
 
     // default is address-less tickets
@@ -88,7 +88,7 @@
      * with pre-authentication values
      */
     KrbAsReq(PrincipalName principal, EncryptionKey[] keys,
-        boolean pa_exists, int etype, byte[] salt, byte[] s2kparams)
+        boolean pa_exists, int etype, String salt, byte[] s2kparams)
         throws KrbException, IOException {
         this(keys, // for pre-authentication
              pa_exists, etype, salt, s2kparams, // pre-auth values
@@ -112,7 +112,7 @@
      }
 
     // update with pre-auth info
-    public void updatePA(int etype, byte[] salt, byte[] params, PrincipalName name) {
+    public void updatePA(int etype, String salt, byte[] params, PrincipalName name) {
         // set the pre-auth values
         pa_exists = true;
         pa_etype = etype;
@@ -120,9 +120,8 @@
         pa_s2kparams = params;
 
         // update salt in PrincipalName
-        if (salt != null && salt.length > 0) {
-            String newSalt = new String(salt);
-            name.setSalt(newSalt);
+        if (salt != null && salt.length() > 0) {
+            name.setSalt(salt);
             if (DEBUG) {
                 System.out.println("Updated salt from pre-auth = " + name.getSalt());
             }
@@ -161,7 +160,7 @@
                     char[] password,
                     boolean pa_exists,
                     int etype,
-                    byte[] salt,
+                    String salt,
                     byte[] s2kparams,
                     KDCOptions options,
                     PrincipalName cname,
@@ -246,7 +245,7 @@
                     EncryptionKey[] keys,
                     boolean pa_exists,
                     int etype,
-                    byte[] salt,
+                    String salt,
                     byte[] s2kparams,
                     KDCOptions options,
                     PrincipalName cname,
--- a/jdk/src/share/classes/sun/security/krb5/PrincipalName.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/security/krb5/PrincipalName.java	Fri Oct 16 18:02:31 2009 -0700
@@ -38,6 +38,7 @@
 import java.io.IOException;
 import java.math.BigInteger;
 import sun.security.krb5.internal.ccache.CCacheOutputStream;
+import sun.security.krb5.internal.util.KerberosString;
 
 
 /**
@@ -246,7 +247,7 @@
             DerValue subSubDer;
             while(subDer.getData().available() > 0) {
                 subSubDer = subDer.getData().getDerValue();
-                v.addElement(subSubDer.getGeneralString());
+                v.addElement(new KerberosString(subSubDer).toString());
             }
             if (v.size() > 0) {
                 nameStrings = new String[v.size()];
@@ -554,7 +555,7 @@
         temp = new DerOutputStream();
         DerValue der[] = new DerValue[nameStrings.length];
         for (int i = 0; i < nameStrings.length; i++) {
-            der[i] = new DerValue(DerValue.tag_GeneralString, nameStrings[i]);
+            der[i] = new KerberosString(nameStrings[i]).toDerValue();
         }
         temp.putSequence(der);
         bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp);
--- a/jdk/src/share/classes/sun/security/krb5/Realm.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/security/krb5/Realm.java	Fri Oct 16 18:02:31 2009 -0700
@@ -31,11 +31,6 @@
 
 package sun.security.krb5;
 
-import sun.security.krb5.Config;
-import sun.security.krb5.PrincipalName;
-import sun.security.krb5.KrbException;
-import sun.security.krb5.Asn1Exception;
-import sun.security.krb5.RealmException;
 import sun.security.krb5.internal.Krb5;
 import sun.security.util.*;
 import java.io.IOException;
@@ -43,6 +38,7 @@
 import java.util.Vector;
 import java.util.Stack;
 import java.util.EmptyStackException;
+import sun.security.krb5.internal.util.KerberosString;
 
 /**
  * Implements the ASN.1 Realm type.
@@ -109,7 +105,7 @@
         if (encoding == null) {
             throw new IllegalArgumentException("encoding can not be null");
         }
-        realm = encoding.getGeneralString();
+        realm = new KerberosString(encoding).toString();
         if (realm == null || realm.length() == 0)
             throw new RealmException(Krb5.REALM_NULL);
         if (!isValidRealmString(realm))
@@ -206,7 +202,7 @@
      */
     public byte[] asn1Encode() throws Asn1Exception, IOException {
         DerOutputStream out = new DerOutputStream();
-        out.putGeneralString(this.realm);
+        out.putDerValue(new KerberosString(this.realm).toDerValue());
         return out.toByteArray();
     }
 
--- a/jdk/src/share/classes/sun/security/krb5/internal/ETypeInfo.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/security/krb5/internal/ETypeInfo.java	Fri Oct 16 18:02:31 2009 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2005-2009 Sun Microsystems, Inc.  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
@@ -28,6 +28,7 @@
 import sun.security.util.*;
 import sun.security.krb5.Asn1Exception;
 import java.io.IOException;
+import sun.security.krb5.internal.util.KerberosString;
 
 /**
  * Implements the ASN.1 ETYPE-INFO-ENTRY type.
@@ -43,7 +44,7 @@
 public class ETypeInfo {
 
     private int etype;
-    private byte[] salt = null;
+    private String salt = null;
 
     private static final byte TAG_TYPE = 0;
     private static final byte TAG_VALUE = 1;
@@ -51,21 +52,13 @@
     private ETypeInfo() {
     }
 
-    public ETypeInfo(int etype, byte[] salt) {
+    public ETypeInfo(int etype, String salt) {
         this.etype = etype;
-        if (salt != null) {
-            this.salt = salt.clone();
-        }
+        this.salt = salt;
     }
 
     public Object clone() {
-        ETypeInfo etypeInfo = new ETypeInfo();
-        etypeInfo.etype = etype;
-        if (salt != null) {
-            etypeInfo.salt = new byte[salt.length];
-            System.arraycopy(salt, 0, etypeInfo.salt, 0, salt.length);
-        }
-        return etypeInfo;
+        return new ETypeInfo(etype, salt);
     }
 
     /**
@@ -94,7 +87,22 @@
         if (encoding.getData().available() > 0) {
             der = encoding.getData().getDerValue();
             if ((der.getTag() & 0x1F) == 0x01) {
-                this.salt = der.getData().getOctetString();
+                byte[] saltBytes = der.getData().getOctetString();
+
+                // Although salt is defined as an OCTET STRING, it's the
+                // encoding from of a string. As RFC 4120 says:
+                //
+                // "The salt, ..., is also completely unspecified with respect
+                // to character set and is probably locale-specific".
+                //
+                // It's known that this field is using the same encoding as
+                // KerberosString in most implementations.
+
+                if (KerberosString.MSNAME) {
+                    this.salt = new String(saltBytes, "UTF8");
+                } else {
+                    this.salt = new String(saltBytes);
+                }
             }
         }
 
@@ -120,7 +128,11 @@
 
         if (salt != null) {
             temp = new DerOutputStream();
-            temp.putOctetString(salt);
+            if (KerberosString.MSNAME) {
+                temp.putOctetString(salt.getBytes("UTF8"));
+            } else {
+                temp.putOctetString(salt.getBytes());
+            }
             bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                         TAG_VALUE), temp);
         }
@@ -135,8 +147,8 @@
         return etype;
     }
 
-    public byte[] getSalt() {
-        return ((salt == null) ? null : salt.clone());
+    public String getSalt() {
+        return salt;
     }
 
 }
--- a/jdk/src/share/classes/sun/security/krb5/internal/ETypeInfo2.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/security/krb5/internal/ETypeInfo2.java	Fri Oct 16 18:02:31 2009 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2005-2009 Sun Microsystems, Inc.  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
@@ -28,6 +28,7 @@
 import sun.security.util.*;
 import sun.security.krb5.Asn1Exception;
 import java.io.IOException;
+import sun.security.krb5.internal.util.KerberosString;
 
 /**
  * Implements the ASN.1 ETYPE-INFO-ENTRY type.
@@ -54,11 +55,9 @@
     private ETypeInfo2() {
     }
 
-    public ETypeInfo2(int etype, byte[] salt, byte[] s2kparams) {
+    public ETypeInfo2(int etype, String salt, byte[] s2kparams) {
         this.etype = etype;
-        if (salt != null) {
-            this.saltStr = new String(salt);
-        }
+        this.saltStr = salt;
         if (s2kparams != null) {
             this.s2kparams = s2kparams.clone();
         }
@@ -102,7 +101,8 @@
         if (encoding.getData().available() > 0) {
             if ((encoding.getData().peekByte() & 0x1F) == 0x01) {
                 der = encoding.getData().getDerValue();
-                this.saltStr = der.getData().getGeneralString();
+                this.saltStr = new KerberosString(
+                        der.getData().getDerValue()).toString();
             }
         }
 
@@ -136,7 +136,7 @@
 
         if (saltStr != null) {
             temp = new DerOutputStream();
-            temp.putGeneralString(saltStr);
+            temp.putDerValue(new KerberosString(saltStr).toDerValue());
             bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                         TAG_VALUE1), temp);
         }
@@ -157,8 +157,8 @@
         return etype;
     }
 
-    public byte[] getSalt() {
-        return ((saltStr == null) ? null : saltStr.getBytes());
+    public String getSalt() {
+        return saltStr;
     }
 
     public byte[] getParams() {
--- a/jdk/src/share/classes/sun/security/krb5/internal/KRBError.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/security/krb5/internal/KRBError.java	Fri Oct 16 18:02:31 2009 -0700
@@ -1,5 +1,5 @@
 /*
- * Portions Copyright 2000-2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * Portions Copyright 2000-2009 Sun Microsystems, Inc.  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
@@ -42,6 +42,7 @@
 import java.io.ObjectInputStream;
 import java.math.BigInteger;
 import java.util.Arrays;
+import sun.security.krb5.internal.util.KerberosString;
 /**
  * Implements the ASN.1 KRBError type.
  *
@@ -97,7 +98,7 @@
 
     // pre-auth info
     private int etype = 0;
-    private byte[] salt = null;
+    private String salt = null;
     private byte[] s2kparams = null;
 
     private static boolean DEBUG = Krb5.DEBUG;
@@ -334,8 +335,8 @@
     }
 
     // access pre-auth info
-    public final byte[] getSalt() {
-        return ((salt == null) ? null : salt.clone());
+    public final String getSalt() {
+        return salt;
     }
 
     // access pre-auth info
@@ -415,7 +416,8 @@
         if (der.getData().available() >0) {
             if ((der.getData().peekByte() & 0x1F) == 0x0B) {
                 subDer = der.getData().getDerValue();
-                eText = subDer.getData().getGeneralString();
+                eText = new KerberosString(subDer.getData().getDerValue())
+                        .toString();
             }
         }
         if (der.getData().available() >0) {
@@ -515,7 +517,7 @@
 
         if (eText != null) {
             temp = new DerOutputStream();
-            temp.putGeneralString(eText);
+            temp.putDerValue(new KerberosString(eText).toDerValue());
             bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0B), temp);
         }
         if (eData != null) {
--- a/jdk/src/share/classes/sun/security/krb5/internal/crypto/Des.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/security/krb5/internal/crypto/Des.java	Fri Oct 16 18:02:31 2009 -0700
@@ -34,17 +34,29 @@
 import javax.crypto.spec.SecretKeySpec;
 import javax.crypto.SecretKeyFactory;
 import javax.crypto.SecretKey;
-import java.security.Security;
-import java.security.Provider;
 import java.security.GeneralSecurityException;
 import javax.crypto.spec.IvParameterSpec;
 import sun.security.krb5.KrbCryptoException;
-import sun.security.krb5.internal.Krb5;
-import java.io.UnsupportedEncodingException;
 import java.util.Arrays;
+import sun.security.action.GetPropertyAction;
 
 public final class Des {
 
+    // RFC 3961 demands that UTF-8 encoding be used in DES's
+    // string-to-key function. For historical reasons, some
+    // implementations use a locale-specific encoding. Even
+    // so, when the client and server use different locales,
+    // they must agree on a common value, normally the one
+    // used when the password is set/reset.
+    //
+    // The following system property is provided to perform the
+    // string-to-key encoding. When set, the specified charset
+    // name is used. Otherwise, the system default charset.
+
+    private final static String CHARSET =
+            java.security.AccessController.doPrivileged(
+            new GetPropertyAction("sun.security.krb5.msinterop.des.s2kcharset"));
+
     private static final long[] bad_keys = {
         0x0101010101010101L, 0xfefefefefefefefeL,
         0x1f1f1f1f1f1f1f1fL, 0xe0e0e0e0e0e0e0e0L,
@@ -226,7 +238,11 @@
 
         // Convert password to byte array
         try {
-            cbytes = (new String(passwdChars)).getBytes();
+            if (CHARSET == null) {
+                cbytes = (new String(passwdChars)).getBytes();
+            } else {
+                cbytes = (new String(passwdChars)).getBytes(CHARSET);
+            }
         } catch (Exception e) {
             // clear-up sensitive information
             if (cbytes != null) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/sun/security/krb5/internal/util/KerberosString.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package sun.security.krb5.internal.util;
+
+import java.io.IOException;
+import java.security.AccessController;
+import sun.security.action.GetBooleanAction;
+import sun.security.util.DerValue;
+
+/**
+ * Implements the ASN.1 KerberosString type.
+ *
+ * <pre>
+ * KerberosString  ::= GeneralString (IA5String)
+ * </pre>
+ *
+ * This definition reflects the Network Working Group RFC 4120
+ * specification available at
+ * <a href="http://www.ietf.org/rfc/rfc4120.txt">
+ * http://www.ietf.org/rfc/rfc4120.txt</a>.
+ */
+public final class KerberosString {
+    /**
+     * RFC 4120 defines KerberosString as GeneralString (IA5String), which
+     * only includes ASCII characters. However, other implementations have been
+     * known to use GeneralString to contain UTF-8 encoding. To interop
+     * with these implementations, the following system property is defined.
+     * When set as true, KerberosString is encoded as UTF-8. Note that this
+     * only affects the byte encoding, the tag of the ASN.1 type is still
+     * GeneralString.
+     */
+    public static final boolean MSNAME = AccessController.doPrivileged(
+            new GetBooleanAction("sun.security.krb5.msinterop.kstring"));
+
+    private final String s;
+
+    public KerberosString(String s) {
+        this.s = s;
+    }
+
+    public KerberosString(DerValue der) throws IOException {
+        if (der.tag != DerValue.tag_GeneralString) {
+            throw new IOException(
+                "KerberosString's tag is incorrect: " + der.tag);
+        }
+        s = new String(der.getDataBytes(), MSNAME?"UTF8":"ASCII");
+    }
+
+    public String toString() {
+        return s;
+    }
+
+    public DerValue toDerValue() throws IOException {
+        // No need to cache the result since this method is
+        // only called once.
+        return new DerValue(DerValue.tag_GeneralString,
+                s.getBytes(MSNAME?"UTF8":"ASCII"));
+    }
+}
--- a/jdk/src/share/classes/sun/security/provider/PolicyFile.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/security/provider/PolicyFile.java	Fri Oct 16 18:02:31 2009 -0700
@@ -54,7 +54,6 @@
 import java.net.NetPermission;
 import java.util.PropertyPermission;
 import java.util.concurrent.atomic.AtomicReference;
-import java.awt.AWTPermission;
 /*
 import javax.security.auth.AuthPermission;
 import javax.security.auth.kerberos.ServicePermission;
@@ -1023,8 +1022,6 @@
             return new NetPermission(name, actions);
         } else if (claz.equals(AllPermission.class)) {
             return SecurityConstants.ALL_PERMISSION;
-        } else if (claz.equals(AWTPermission.class)) {
-            return new AWTPermission(name, actions);
 /*
         } else if (claz.equals(ReflectPermission.class)) {
             return new ReflectPermission(name, actions);
--- a/jdk/src/share/classes/sun/security/ssl/CipherSuite.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/security/ssl/CipherSuite.java	Fri Oct 16 18:02:31 2009 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2002-2009 Sun Microsystems, Inc.  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
@@ -74,7 +74,7 @@
     // Flag indicating if CipherSuite availability can change dynamically.
     // This is the case when we rely on a JCE cipher implementation that
     // may not be available in the installed JCE providers.
-    // It is true because we do not have a Java ECC implementation.
+    // It is true because we might not have an ECC or Kerberos implementation.
     final static boolean DYNAMIC_AVAILABILITY = true;
 
     private final static boolean ALLOW_ECC = Debug.getBooleanProperty
@@ -278,14 +278,22 @@
         KeyExchange(String name, boolean allowed) {
             this.name = name;
             this.allowed = allowed;
-            this.alwaysAvailable = allowed && (name.startsWith("EC") == false);
+            this.alwaysAvailable = allowed &&
+                (!name.startsWith("EC")) && (!name.startsWith("KRB"));
         }
 
         boolean isAvailable() {
             if (alwaysAvailable) {
                 return true;
             }
-            return allowed && JsseJce.isEcAvailable();
+
+            if (name.startsWith("EC")) {
+                return (allowed && JsseJce.isEcAvailable());
+            } else if (name.startsWith("KRB")) {
+                return (allowed && JsseJce.isKerberosAvailable());
+            } else {
+                return allowed;
+            }
         }
 
         public String toString() {
--- a/jdk/src/share/classes/sun/security/ssl/JsseJce.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/security/ssl/JsseJce.java	Fri Oct 16 18:02:31 2009 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001-2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2001-2009 Sun Microsystems, Inc.  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
@@ -64,6 +64,29 @@
     // If yes, then all the EC based crypto we need is available.
     private static volatile Boolean ecAvailable;
 
+    // Flag indicating whether Kerberos crypto is available.
+    // If true, then all the Kerberos-based crypto we need is available.
+    private final static boolean kerberosAvailable;
+    static {
+        boolean temp;
+        try {
+            AccessController.doPrivileged(
+                new PrivilegedExceptionAction<Void>() {
+                    public Void run() throws Exception {
+                        // Test for Kerberos using the bootstrap class loader
+                        Class.forName("sun.security.krb5.PrincipalName", true,
+                                null);
+                        return null;
+                    }
+                });
+            temp = true;
+
+        } catch (Exception e) {
+            temp = false;
+        }
+        kerberosAvailable = temp;
+    }
+
     static {
         // force FIPS flag initialization
         // Because isFIPS() is synchronized and cryptoProvider is not modified
@@ -187,6 +210,10 @@
         ecAvailable = null;
     }
 
+    static boolean isKerberosAvailable() {
+        return kerberosAvailable;
+    }
+
     /**
      * Return an JCE cipher implementation for the specified algorithm.
      */
--- a/jdk/src/share/classes/sun/security/tools/JarSigner.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/security/tools/JarSigner.java	Fri Oct 16 18:02:31 2009 -0700
@@ -291,13 +291,21 @@
         for (n=0; n < args.length; n++) {
 
             String flags = args[n];
+            String modifier = null;
+            if (flags.charAt(0) == '-') {
+                int pos = flags.indexOf(':');
+                if (pos > 0) {
+                    modifier = flags.substring(pos+1);
+                    flags = flags.substring(0, pos);
+                }
+            }
 
             if (collator.compare(flags, "-keystore") == 0) {
                 if (++n == args.length) usageNoArg();
                 keystore = args[n];
             } else if (collator.compare(flags, "-storepass") ==0) {
                 if (++n == args.length) usageNoArg();
-                storepass = args[n].toCharArray();
+                storepass = getPass(modifier, args[n]);
             } else if (collator.compare(flags, "-storetype") ==0) {
                 if (++n == args.length) usageNoArg();
                 storetype = args[n];
@@ -329,7 +337,7 @@
                 debug = true;
             } else if (collator.compare(flags, "-keypass") ==0) {
                 if (++n == args.length) usageNoArg();
-                keypass = args[n].toCharArray();
+                keypass = getPass(modifier, args[n]);
             } else if (collator.compare(flags, "-sigfile") ==0) {
                 if (++n == args.length) usageNoArg();
                 sigfile = args[n];
@@ -355,13 +363,7 @@
             } else if (collator.compare(flags, "-verify") ==0) {
                 verify = true;
             } else if (collator.compare(flags, "-verbose") ==0) {
-                verbose = "all";
-            } else if (collator.compare(flags, "-verbose:all") ==0) {
-                verbose = "all";
-            } else if (collator.compare(flags, "-verbose:summary") ==0) {
-                verbose = "summary";
-            } else if (collator.compare(flags, "-verbose:grouped") ==0) {
-                verbose = "grouped";
+                verbose = (modifier != null) ? modifier : "all";
             } else if (collator.compare(flags, "-sigalg") ==0) {
                 if (++n == args.length) usageNoArg();
                 sigalg = args[n];
@@ -465,18 +467,25 @@
         }
     }
 
-    void usageNoArg() {
+    static char[] getPass(String modifier, String arg) {
+        char[] output = KeyTool.getPassWithModifier(modifier, arg);
+        if (output != null) return output;
+        usage();
+        return null;    // Useless, usage() already exit
+    }
+
+    static void usageNoArg() {
         System.out.println(rb.getString("Option lacks argument"));
         usage();
     }
 
-    void usage() {
+    static void usage() {
         System.out.println();
         System.out.println(rb.getString("Please type jarsigner -help for usage"));
         System.exit(1);
     }
 
-    void fullusage() {
+    static void fullusage() {
         System.out.println(rb.getString
                 ("Usage: jarsigner [options] jar-file alias"));
         System.out.println(rb.getString
--- a/jdk/src/share/classes/sun/security/tools/KeyTool.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/security/tools/KeyTool.java	Fri Oct 16 18:02:31 2009 -0700
@@ -76,6 +76,7 @@
 import sun.security.x509.*;
 
 import static java.security.KeyStore.*;
+import static sun.security.tools.KeyTool.Command.*;
 
 /**
  * This tool manages keystores.
@@ -92,7 +93,7 @@
 public final class KeyTool {
 
     private boolean debug = false;
-    private int command = -1;
+    private Command command = null;
     private String sigAlgName = null;
     private String keyAlgName = null;
     private boolean verbose = false;
@@ -146,24 +147,132 @@
 
     private List <String> v3ext = new ArrayList <String> ();
 
-    private static final int CERTREQ = 1;
-    private static final int CHANGEALIAS = 2;
-    private static final int DELETE = 3;
-    private static final int EXPORTCERT = 4;
-    private static final int GENKEYPAIR = 5;
-    private static final int GENSECKEY = 6;
-    // there is no HELP
-    private static final int IDENTITYDB = 7;
-    private static final int IMPORTCERT = 8;
-    private static final int IMPORTKEYSTORE = 9;
-    private static final int KEYCLONE = 10;
-    private static final int KEYPASSWD = 11;
-    private static final int LIST = 12;
-    private static final int PRINTCERT = 13;
-    private static final int SELFCERT = 14;
-    private static final int STOREPASSWD = 15;
-    private static final int GENCERT = 16;
-    private static final int PRINTCERTREQ = 17;
+    enum Command {
+        CERTREQ("Generates a certificate request",
+            "-alias", "-sigalg", "-file", "-keypass", "-keystore",
+            "-storepass", "-storetype", "-providername", "-providerclass",
+            "-providerarg", "-providerpath", "-v", "-protected"),
+        CHANGEALIAS("Changes an entry's alias",
+            "-alias", "-destalias", "-keypass", "-keystore", "-storepass",
+            "-storetype", "-providername", "-providerclass", "-providerarg",
+            "-providerpath", "-v", "-protected"),
+        DELETE("Deletes an entry",
+            "-alias", "-keystore", "-storepass", "-storetype",
+            "-providername", "-providerclass", "-providerarg",
+            "-providerpath", "-v", "-protected"),
+        EXPORTCERT("Exports certificate",
+            "-rfc", "-alias", "-file", "-keystore", "-storepass",
+            "-storetype", "-providername", "-providerclass", "-providerarg",
+            "-providerpath", "-v", "-protected"),
+        GENKEYPAIR("Generates a key pair",
+            "-alias", "-keyalg", "-keysize", "-sigalg", "-destalias",
+            "-startdate", "-ext", "-validity", "-keypass", "-keystore",
+            "-storepass", "-storetype", "-providername", "-providerclass",
+            "-providerarg", "-providerpath", "-v", "-protected"),
+        GENSECKEY("Generates a secret key",
+            "-alias", "-keypass", "-keyalg", "-keysize", "-keystore",
+            "-storepass", "-storetype", "-providername", "-providerclass",
+            "-providerarg", "-providerpath", "-v", "-protected"),
+        GENCERT("Generates certificate from a certificate request",
+            "-rfc", "-infile", "-outfile", "-alias", "-sigalg",
+            "-startdate", "-ext", "-validity", "-keypass", "-keystore",
+            "-storepass", "-storetype", "-providername", "-providerclass",
+            "-providerarg", "-providerpath", "-v", "-protected"),
+        IDENTITYDB("Imports entries from a JDK 1.1.x-style identity database",
+            "-file", "-storetype", "-keystore", "-storepass", "-providername",
+            "-providerclass", "-providerarg", "-providerpath", "-v"),
+        IMPORTCERT("Imports a certificate or a certificate chain",
+            "-noprompt", "-trustcacerts", "-protected", "-alias", "-file",
+            "-keypass", "-keystore", "-storepass", "-storetype",
+            "-providername", "-providerclass", "-providerarg",
+            "-providerpath", "-v"),
+        IMPORTKEYSTORE("Imports one or all entries from another keystore",
+            "-srckeystore", "-destkeystore", "-srcstoretype",
+            "-deststoretype", "-srcstorepass", "-deststorepass",
+            "-srcprotected", "-srcprovidername", "-destprovidername",
+            "-srcalias", "-destalias", "-srckeypass", "-destkeypass",
+            "-noprompt", "-providerclass", "-providerarg", "-providerpath",
+            "-v"),
+        KEYCLONE("Clones a key entry",
+            "-alias", "-destalias", "-keypass", "-new", "-storetype",
+            "-keystore", "-storepass", "-providername", "-providerclass",
+            "-providerarg", "-providerpath", "-v"),
+        KEYPASSWD("Changes the key password of an entry",
+            "-alias", "-keypass", "-new", "-keystore", "-storepass",
+            "-storetype", "-providername", "-providerclass", "-providerarg",
+            "-providerpath", "-v"),
+        LIST("Lists entries in a keystore",
+            "-rfc", "-alias", "-keystore", "-storepass", "-storetype",
+            "-providername", "-providerclass", "-providerarg",
+            "-providerpath", "-v", "-protected"),
+        PRINTCERT("Prints the content of a certificate",
+            "-rfc", "-file", "-sslserver", "-v"),
+        PRINTCERTREQ("Prints the content of a certificate request",
+            "-file", "-v"),
+        SELFCERT("Generates a self-signed certificate",
+            "-alias", "-sigalg", "-dname", "-startdate", "-validity", "-keypass",
+            "-storetype", "-keystore", "-storepass", "-providername",
+            "-providerclass", "-providerarg", "-providerpath", "-v"),
+        STOREPASSWD("Changes the store password of a keystore",
+            "-new", "-keystore", "-storepass", "-storetype", "-providername",
+            "-providerclass", "-providerarg", "-providerpath", "-v");
+
+        final String description;
+        final String[] options;
+        Command(String d, String... o) {
+            description = d;
+            options = o;
+        }
+        @Override
+        public String toString() {
+            return "-" + name().toLowerCase(Locale.ENGLISH);
+        }
+    };
+
+    private static String[][] options = {
+        // name, arg, description
+        {"-alias", "<alias>", "alias name of the entry to process"},
+        {"-destalias", "<destalias>", "destination alias"},
+        {"-destkeypass", "<arg>", "destination key password"},
+        {"-destkeystore", "<destkeystore>", "destination keystore name"},
+        {"-destprotected", null, "destination keystore password protected"},
+        {"-destprovidername", "<destprovidername>", "destination keystore provider name"},
+        {"-deststorepass", "<arg>", "destination keystore password"},
+        {"-deststoretype", "<deststoretype>", "destination keystore type"},
+        {"-dname", "<dname>", "distinguished name"},
+        {"-ext", "<value>", "X.509 extension"},
+        {"-file", "<filename>", "output file name"},
+        {"-file", "<filename>", "input file name"},
+        {"-infile", "<filename>", "input file name"},
+        {"-keyalg", "<keyalg>", "key algorithm name"},
+        {"-keypass", "<arg>", "key password"},
+        {"-keysize", "<keysize>", "key bit size"},
+        {"-keystore", "<keystore>", "keystore name"},
+        {"-new", "<arg>", "new password"},
+        {"-noprompt", null, "do not prompt"},
+        {"-outfile", "<filename>", "output file name"},
+        {"-protected", null, "password through protected mechanism"},
+        {"-providerarg", "<arg>", "provider argument"},
+        {"-providerclass", "<providerclass>", "provider class name"},
+        {"-providername", "<providername>", "provider name"},
+        {"-providerpath", "<pathlist>", "provider classpath"},
+        {"-rfc", null, "output in RFC style"},
+        {"-sigalg", "<sigalg>", "signature algorithm name"},
+        {"-srcalias", "<srcalias>", "source alias"},
+        {"-srckeypass", "<arg>", "source keystore password"},
+        {"-srckeystore", "<srckeystore>", "source keystore name"},
+        {"-srcprotected", null, "source keystore password protected"},
+        {"-srcprovidername", "<srcprovidername>", "source keystore provider name"},
+        {"-srcstorepass", "<arg>", "source keystore password"},
+        {"-srcstoretype", "<srcstoretype>", "source keystore type"},
+        {"-sslserver", "<server[:port]>", "SSL server host and port"},
+        {"-startdate", "<startdate>", "certificate validity start date/time"},
+        {"-storepass", "<arg>", "keystore password"},
+        {"-storetype", "<storetype>", "keystore type"},
+        {"-trustcacerts", null, "trust certificates from cacerts"},
+        {"-v", null, "verbose output"},
+        {"-validity", "<valDays>", "validity number of days"},
+    };
 
     private static final Class[] PARAM_STRING = { String.class };
 
@@ -192,7 +301,7 @@
     private void run(String[] args, PrintStream out) throws Exception {
         try {
             parseArgs(args);
-            if (command != -1) {
+            if (command != null) {
                 doCommands(out);
             }
         } catch (Exception e) {
@@ -224,59 +333,59 @@
      */
     void parseArgs(String[] args) {
 
-        if (args.length == 0) {
-            usage();
-            return;
-        }
-
         int i=0;
+        boolean help = args.length == 0;
 
         for (i=0; (i < args.length) && args[i].startsWith("-"); i++) {
 
             String flags = args[i];
+
+            // Check if the last option needs an arg
+            if (i == args.length - 1) {
+                for (String[] option: options) {
+                    // Only options with an arg need to be checked
+                    if (collator.compare(flags, option[0]) == 0) {
+                        if (option[1] != null) errorNeedArgument(flags);
+                        break;
+                    }
+                }
+            }
+
+            /*
+             * Check modifiers
+             */
+            String modifier = null;
+            int pos = flags.indexOf(':');
+            if (pos > 0) {
+                modifier = flags.substring(pos+1);
+                flags = flags.substring(0, pos);
+            }
             /*
              * command modes
              */
-            if (collator.compare(flags, "-certreq") == 0) {
-                command = CERTREQ;
-            } else if (collator.compare(flags, "-delete") == 0) {
-                command = DELETE;
-            } else if (collator.compare(flags, "-export") == 0 ||
-                    collator.compare(flags, "-exportcert") == 0) {
+            boolean isCommand = false;
+            for (Command c: Command.values()) {
+                if (collator.compare(flags, c.toString()) == 0) {
+                    command = c;
+                    isCommand = true;
+                    break;
+                }
+            }
+
+            if (isCommand) {
+                // already recognized as a command
+            } else if (collator.compare(flags, "-export") == 0) {
                 command = EXPORTCERT;
-            } else if (collator.compare(flags, "-genkey") == 0 ||
-                    collator.compare(flags, "-genkeypair") == 0) {
+            } else if (collator.compare(flags, "-genkey") == 0) {
                 command = GENKEYPAIR;
-            } else if (collator.compare(flags, "-help") == 0) {
-                usage();
-                return;
-            } else if (collator.compare(flags, "-identitydb") == 0) { // obsolete
-                command = IDENTITYDB;
-            } else if (collator.compare(flags, "-import") == 0 ||
-                    collator.compare(flags, "-importcert") == 0) {
+            } else if (collator.compare(flags, "-import") == 0) {
                 command = IMPORTCERT;
-            } else if (collator.compare(flags, "-keyclone") == 0) { // obsolete
-                command = KEYCLONE;
-            } else if (collator.compare(flags, "-changealias") == 0) {
-                command = CHANGEALIAS;
-            } else if (collator.compare(flags, "-keypasswd") == 0) {
-                command = KEYPASSWD;
-            } else if (collator.compare(flags, "-list") == 0) {
-                command = LIST;
-            } else if (collator.compare(flags, "-printcert") == 0) {
-                command = PRINTCERT;
-            } else if (collator.compare(flags, "-selfcert") == 0) {     // obsolete
-                command = SELFCERT;
-            } else if (collator.compare(flags, "-storepasswd") == 0) {
-                command = STOREPASSWD;
-            } else if (collator.compare(flags, "-importkeystore") == 0) {
-                command = IMPORTKEYSTORE;
-            } else if (collator.compare(flags, "-genseckey") == 0) {
-                command = GENSECKEY;
-            } else if (collator.compare(flags, "-gencert") == 0) {
-                command = GENCERT;
-            } else if (collator.compare(flags, "-printcertreq") == 0) {
-                command = PRINTCERTREQ;
+            }
+            /*
+             * Help
+             */
+            else if (collator.compare(flags, "-help") == 0) {
+                help = true;
             }
 
             /*
@@ -284,101 +393,74 @@
              */
             else if (collator.compare(flags, "-keystore") == 0 ||
                     collator.compare(flags, "-destkeystore") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                ksfname = args[i];
+                ksfname = args[++i];
             } else if (collator.compare(flags, "-storepass") == 0 ||
                     collator.compare(flags, "-deststorepass") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                storePass = args[i].toCharArray();
+                storePass = getPass(modifier, args[++i]);
                 passwords.add(storePass);
             } else if (collator.compare(flags, "-storetype") == 0 ||
                     collator.compare(flags, "-deststoretype") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                storetype = args[i];
+                storetype = args[++i];
             } else if (collator.compare(flags, "-srcstorepass") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                srcstorePass = args[i].toCharArray();
+                srcstorePass = getPass(modifier, args[++i]);
                 passwords.add(srcstorePass);
             } else if (collator.compare(flags, "-srcstoretype") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                srcstoretype = args[i];
+                srcstoretype = args[++i];
             } else if (collator.compare(flags, "-srckeypass") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                srckeyPass = args[i].toCharArray();
+                srckeyPass = getPass(modifier, args[++i]);
                 passwords.add(srckeyPass);
             } else if (collator.compare(flags, "-srcprovidername") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                srcProviderName = args[i];
+                srcProviderName = args[++i];
             } else if (collator.compare(flags, "-providername") == 0 ||
                     collator.compare(flags, "-destprovidername") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                providerName = args[i];
+                providerName = args[++i];
             } else if (collator.compare(flags, "-providerpath") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                pathlist = args[i];
+                pathlist = args[++i];
             } else if (collator.compare(flags, "-keypass") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                keyPass = args[i].toCharArray();
+                keyPass = getPass(modifier, args[++i]);
                 passwords.add(keyPass);
             } else if (collator.compare(flags, "-new") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                newPass = args[i].toCharArray();
+                newPass = getPass(modifier, args[++i]);
                 passwords.add(newPass);
             } else if (collator.compare(flags, "-destkeypass") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                destKeyPass = args[i].toCharArray();
+                destKeyPass = getPass(modifier, args[++i]);
                 passwords.add(destKeyPass);
             } else if (collator.compare(flags, "-alias") == 0 ||
                     collator.compare(flags, "-srcalias") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                alias = args[i];
+                alias = args[++i];
             } else if (collator.compare(flags, "-dest") == 0 ||
                     collator.compare(flags, "-destalias") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                dest = args[i];
+                dest = args[++i];
             } else if (collator.compare(flags, "-dname") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                dname = args[i];
+                dname = args[++i];
             } else if (collator.compare(flags, "-keysize") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                keysize = Integer.parseInt(args[i]);
+                keysize = Integer.parseInt(args[++i]);
             } else if (collator.compare(flags, "-keyalg") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                keyAlgName = args[i];
+                keyAlgName = args[++i];
             } else if (collator.compare(flags, "-sigalg") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                sigAlgName = args[i];
+                sigAlgName = args[++i];
             } else if (collator.compare(flags, "-startdate") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                startDate = args[i];
+                startDate = args[++i];
             } else if (collator.compare(flags, "-validity") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                validity = Long.parseLong(args[i]);
+                validity = Long.parseLong(args[++i]);
             } else if (collator.compare(flags, "-ext") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                v3ext.add(args[i]);
+                v3ext.add(args[++i]);
             } else if (collator.compare(flags, "-file") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                filename = args[i];
+                filename = args[++i];
             } else if (collator.compare(flags, "-infile") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                infilename = args[i];
+                infilename = args[++i];
             } else if (collator.compare(flags, "-outfile") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                outfilename = args[i];
+                outfilename = args[++i];
             } else if (collator.compare(flags, "-sslserver") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                sslserver = args[i];
+                sslserver = args[++i];
             } else if (collator.compare(flags, "-srckeystore") == 0) {
-                if (++i == args.length) errorNeedArgument(flags);
-                srcksfname = args[i];
+                srcksfname = args[++i];
             } else if ((collator.compare(flags, "-provider") == 0) ||
                         (collator.compare(flags, "-providerclass") == 0)) {
-                if (++i == args.length) errorNeedArgument(flags);
                 if (providers == null) {
                     providers = new HashSet<Pair <String, String>> (3);
                 }
-                String providerClass = args[i];
+                String providerClass = args[++i];
                 String providerArg = null;
 
                 if (args.length > (i+1)) {
@@ -418,19 +500,24 @@
         }
 
         if (i<args.length) {
-            MessageFormat form = new MessageFormat
-                (rb.getString("Usage error, <arg> is not a legal command"));
-            Object[] source = {args[i]};
-            throw new RuntimeException(form.format(source));
-        }
-
-        if (command == -1) {
-            System.err.println(rb.getString("Usage error: no command provided"));
+            System.err.println(rb.getString("Illegal option:  ") + args[i]);
             tinyHelp();
         }
+
+        if (command == null) {
+            if (help) {
+                usage();
+            } else {
+                System.err.println(rb.getString("Usage error: no command provided"));
+                tinyHelp();
+            }
+        } else if (help) {
+            usage();
+            command = null;
+        }
     }
 
-    boolean isKeyStoreRelated(int cmd) {
+    boolean isKeyStoreRelated(Command cmd) {
         return cmd != PRINTCERT && cmd != PRINTCERTREQ;
     }
 
@@ -2600,7 +2687,7 @@
         do {
             if (maxRetry-- < 0) {
                 throw new RuntimeException(rb.getString(
-                        "Too may retries, program terminated"));
+                        "Too many retries, program terminated"));
             }
             commonName = inputString(in,
                     rb.getString("What is your first and last name?"),
@@ -3086,7 +3173,7 @@
         do {
             if (maxRetry-- < 0) {
                 throw new RuntimeException(rb.getString(
-                        "Too may retries, program terminated"));
+                        "Too many retries, program terminated"));
             }
             System.err.print(prompt);
             System.err.flush();
@@ -3258,7 +3345,8 @@
         int nmatch = 0;
         for (int i = 0; i<list.length; i++) {
             String one = list[i];
-            if (one.toLowerCase().startsWith(s.toLowerCase())) {
+            if (one.toLowerCase(Locale.ENGLISH)
+                    .startsWith(s.toLowerCase(Locale.ENGLISH))) {
                 match[nmatch++] = i;
             } else {
                 StringBuffer sb = new StringBuffer();
@@ -3368,9 +3456,9 @@
             // Honoring requested extensions
             if (reqex != null) {
                 for(String extstr: extstrs) {
-                    if (extstr.toLowerCase().startsWith("honored=")) {
+                    if (extstr.toLowerCase(Locale.ENGLISH).startsWith("honored=")) {
                         List<String> list = Arrays.asList(
-                                extstr.toLowerCase().substring(8).split(","));
+                                extstr.toLowerCase(Locale.ENGLISH).substring(8).split(","));
                         // First check existence of "all"
                         if (list.contains("all")) {
                             ext = reqex;    // we know ext was null
@@ -3687,227 +3775,69 @@
      * Prints the usage of this tool.
      */
     private void usage() {
-        System.err.println(rb.getString("keytool usage:\n"));
-
-        System.err.println(rb.getString
-                ("-certreq     [-v] [-protected]"));
-        System.err.println(rb.getString
-                ("\t     [-alias <alias>] [-sigalg <sigalg>]"));
-        System.err.println(rb.getString
-                ("\t     [-dname <dname>]"));
-        System.err.println(rb.getString
-                ("\t     [-file <csr_file>] [-keypass <keypass>]"));
-        System.err.println(rb.getString
-                ("\t     [-keystore <keystore>] [-storepass <storepass>]"));
-        System.err.println(rb.getString
-                ("\t     [-storetype <storetype>] [-providername <name>]"));
-        System.err.println(rb.getString
-                ("\t     [-providerclass <provider_class_name> [-providerarg <arg>]] ..."));
-        System.err.println(rb.getString
-                ("\t     [-providerpath <pathlist>]"));
-        System.err.println();
-
-        System.err.println(rb.getString
-                ("-changealias [-v] [-protected] -alias <alias> -destalias <destalias>"));
-        System.err.println(rb.getString
-                ("\t     [-keypass <keypass>]"));
-        System.err.println(rb.getString
-                ("\t     [-keystore <keystore>] [-storepass <storepass>]"));
-        System.err.println(rb.getString
-                ("\t     [-storetype <storetype>] [-providername <name>]"));
-        System.err.println(rb.getString
-                ("\t     [-providerclass <provider_class_name> [-providerarg <arg>]] ..."));
-        System.err.println(rb.getString
-                ("\t     [-providerpath <pathlist>]"));
-        System.err.println();
-
-        System.err.println(rb.getString
-                ("-delete      [-v] [-protected] -alias <alias>"));
-        System.err.println(rb.getString
-                ("\t     [-keystore <keystore>] [-storepass <storepass>]"));
-        System.err.println(rb.getString
-                ("\t     [-storetype <storetype>] [-providername <name>]"));
-        System.err.println(rb.getString
-                ("\t     [-providerclass <provider_class_name> [-providerarg <arg>]] ..."));
-        System.err.println(rb.getString
-                ("\t     [-providerpath <pathlist>]"));
-        System.err.println();
-
-        System.err.println(rb.getString
-                ("-exportcert  [-v] [-rfc] [-protected]"));
-        System.err.println(rb.getString
-                ("\t     [-alias <alias>] [-file <cert_file>]"));
-        System.err.println(rb.getString
-                ("\t     [-keystore <keystore>] [-storepass <storepass>]"));
-        System.err.println(rb.getString
-                ("\t     [-storetype <storetype>] [-providername <name>]"));
-        System.err.println(rb.getString
-                ("\t     [-providerclass <provider_class_name> [-providerarg <arg>]] ..."));
-        System.err.println(rb.getString
-                ("\t     [-providerpath <pathlist>]"));
-        System.err.println();
-
-        System.err.println(rb.getString
-                ("-genkeypair  [-v] [-protected]"));
-        System.err.println(rb.getString
-                ("\t     [-alias <alias>]"));
-        System.err.println(rb.getString
-                ("\t     [-keyalg <keyalg>] [-keysize <keysize>]"));
-        System.err.println(rb.getString
-                ("\t     [-sigalg <sigalg>] [-dname <dname>]"));
-        System.err.println(rb.getString
-                ("\t     [-startdate <startdate>]"));
-        System.err.println(rb.getString
-                ("\t     [-ext <key>[:critical][=<value>]]..."));
-        System.err.println(rb.getString
-                ("\t     [-validity <valDays>] [-keypass <keypass>]"));
-        System.err.println(rb.getString
-                ("\t     [-keystore <keystore>] [-storepass <storepass>]"));
-        System.err.println(rb.getString
-                ("\t     [-storetype <storetype>] [-providername <name>]"));
-        System.err.println(rb.getString
-                ("\t     [-providerclass <provider_class_name> [-providerarg <arg>]] ..."));
-        System.err.println(rb.getString
-                ("\t     [-providerpath <pathlist>]"));
-        System.err.println();
-
-        System.err.println(rb.getString
-                ("-gencert     [-v] [-rfc] [-protected]"));
-        System.err.println(rb.getString
-                ("\t     [-infile <infile>] [-outfile <outfile>]"));
-        System.err.println(rb.getString
-                ("\t     [-alias <alias>]"));
-        System.err.println(rb.getString
-                ("\t     [-dname <dname>]"));
-        System.err.println(rb.getString
-                ("\t     [-sigalg <sigalg>]"));
-        System.err.println(rb.getString
-                ("\t     [-startdate <startdate>]"));
-        System.err.println(rb.getString
-                ("\t     [-ext <key>[:critical][=<value>]]..."));
-        System.err.println(rb.getString
-                ("\t     [-validity <valDays>] [-keypass <keypass>]"));
-        System.err.println(rb.getString
-                ("\t     [-keystore <keystore>] [-storepass <storepass>]"));
-        System.err.println(rb.getString
-                ("\t     [-storetype <storetype>] [-providername <name>]"));
-        System.err.println(rb.getString
-                ("\t     [-providerclass <provider_class_name> [-providerarg <arg>]] ..."));
-        System.err.println(rb.getString
-                ("\t     [-providerpath <pathlist>]"));
-        System.err.println();
-
-        System.err.println(rb.getString
-                ("-genseckey   [-v] [-protected]"));
-        System.err.println(rb.getString
-                ("\t     [-alias <alias>] [-keypass <keypass>]"));
-        System.err.println(rb.getString
-                ("\t     [-keyalg <keyalg>] [-keysize <keysize>]"));
-        System.err.println(rb.getString
-                ("\t     [-keystore <keystore>] [-storepass <storepass>]"));
-        System.err.println(rb.getString
-                ("\t     [-storetype <storetype>] [-providername <name>]"));
-        System.err.println(rb.getString
-                ("\t     [-providerclass <provider_class_name> [-providerarg <arg>]] ..."));
-        System.err.println(rb.getString
-                ("\t     [-providerpath <pathlist>]"));
-        System.err.println();
-
-        System.err.println(rb.getString("-help"));
-        System.err.println();
-
-        System.err.println(rb.getString
-                ("-importcert  [-v] [-noprompt] [-trustcacerts] [-protected]"));
-        System.err.println(rb.getString
-                ("\t     [-alias <alias>]"));
-        System.err.println(rb.getString
-                ("\t     [-file <cert_file>] [-keypass <keypass>]"));
-        System.err.println(rb.getString
-                ("\t     [-keystore <keystore>] [-storepass <storepass>]"));
-        System.err.println(rb.getString
-                ("\t     [-storetype <storetype>] [-providername <name>]"));
-        System.err.println(rb.getString
-                ("\t     [-providerclass <provider_class_name> [-providerarg <arg>]] ..."));
-        System.err.println(rb.getString
-                ("\t     [-providerpath <pathlist>]"));
-        System.err.println();
-
-        System.err.println(rb.getString
-                ("-importkeystore [-v] "));
-        System.err.println(rb.getString
-                ("\t     [-srckeystore <srckeystore>] [-destkeystore <destkeystore>]"));
-        System.err.println(rb.getString
-                ("\t     [-srcstoretype <srcstoretype>] [-deststoretype <deststoretype>]"));
-        System.err.println(rb.getString
-                ("\t     [-srcstorepass <srcstorepass>] [-deststorepass <deststorepass>]"));
-        System.err.println(rb.getString
-                ("\t     [-srcprotected] [-destprotected]"));
-        System.err.println(rb.getString
-                ("\t     [-srcprovidername <srcprovidername>]\n\t     [-destprovidername <destprovidername>]"));
-        System.err.println(rb.getString
-                ("\t     [-srcalias <srcalias> [-destalias <destalias>]"));
-        System.err.println(rb.getString
-                ("\t       [-srckeypass <srckeypass>] [-destkeypass <destkeypass>]]"));
-        System.err.println(rb.getString
-                ("\t     [-noprompt]"));
-        System.err.println(rb.getString
-                ("\t     [-providerclass <provider_class_name> [-providerarg <arg>]] ..."));
-        System.err.println(rb.getString
-                ("\t     [-providerpath <pathlist>]"));
-        System.err.println();
-
-        System.err.println(rb.getString
-                ("-keypasswd   [-v] [-alias <alias>]"));
-        System.err.println(rb.getString
-                ("\t     [-keypass <old_keypass>] [-new <new_keypass>]"));
-        System.err.println(rb.getString
-                ("\t     [-keystore <keystore>] [-storepass <storepass>]"));
-        System.err.println(rb.getString
-                ("\t     [-storetype <storetype>] [-providername <name>]"));
-        System.err.println(rb.getString
-                ("\t     [-providerclass <provider_class_name> [-providerarg <arg>]] ..."));
-        System.err.println(rb.getString
-                ("\t     [-providerpath <pathlist>]"));
-        System.err.println();
-
-        System.err.println(rb.getString
-                ("-list        [-v | -rfc] [-protected]"));
-        System.err.println(rb.getString
-                ("\t     [-alias <alias>]"));
-        System.err.println(rb.getString
-                ("\t     [-keystore <keystore>] [-storepass <storepass>]"));
-        System.err.println(rb.getString
-                ("\t     [-storetype <storetype>] [-providername <name>]"));
-        System.err.println(rb.getString
-                ("\t     [-providerclass <provider_class_name> [-providerarg <arg>]] ..."));
-        System.err.println(rb.getString
-                ("\t     [-providerpath <pathlist>]"));
-        System.err.println();
-
-        System.err.println(rb.getString
-                ("-printcert   [-v] [-rfc] [-file <cert_file> | -sslserver <host[:port]>]"));
-        System.err.println();
-
-        System.err.println(rb.getString
-                ("-printcertreq   [-v] [-file <cert_file>]"));
-        System.err.println();
-
-        System.err.println(rb.getString
-                ("-storepasswd [-v] [-new <new_storepass>]"));
-        System.err.println(rb.getString
-                ("\t     [-keystore <keystore>] [-storepass <storepass>]"));
-        System.err.println(rb.getString
-                ("\t     [-storetype <storetype>] [-providername <name>]"));
-        System.err.println(rb.getString
-                ("\t     [-providerclass <provider_class_name> [-providerarg <arg>]] ..."));
-        System.err.println(rb.getString
-                ("\t     [-providerpath <pathlist>]"));
+        if (command != null) {
+            System.err.println("keytool " + command +
+                    rb.getString(" [OPTION]..."));
+            System.err.println();
+            System.err.println(rb.getString(command.description));
+            System.err.println();
+            System.err.println(rb.getString("Options:"));
+            System.err.println();
+
+            // Left and right sides of the options list
+            String[] left = new String[command.options.length];
+            String[] right = new String[command.options.length];
+
+            // Check if there's an unknown option
+            boolean found = false;
+
+            // Length of left side of options list
+            int lenLeft = 0;
+            for (int j=0; j<left.length; j++) {
+                for (String[] opt: options) {
+                    if (collator.compare(opt[0], command.options[j]) == 0) {
+                        left[j] = opt[0];
+                        if (opt[1] != null) left[j] += " " + opt[1];
+                        if (left[j].length() > lenLeft) {
+                            lenLeft = left[j].length();
+                        }
+                        right[j] = rb.getString(opt[2]);
+                        found = true;
+                        break;
+                    }
+                }
+                if (!found) {
+                    throw new RuntimeException("ERROR: CANNOT FIND " + command.options[j]);
+                }
+            }
+            for (int j=0; j<left.length; j++) {
+                System.err.printf(" %-" + lenLeft + "s  %s\n",
+                        left[j], right[j]);
+            }
+            System.err.println();
+            System.err.println(rb.getString(
+                    "Use \"keytool -help\" for all available commands"));
+        } else {
+            System.err.println(rb.getString(
+                    "Key and Certificate Management Tool"));
+            System.err.println();
+            System.err.println(rb.getString("Commands:"));
+            System.err.println();
+            for (Command c: Command.values()) {
+                if (c != IDENTITYDB
+                        && c != KEYCLONE
+                        && c != SELFCERT) {     // Deprecated commands
+                    System.err.printf(" %-20s%s\n", c, rb.getString(c.description));
+                }
+            }
+            System.err.println();
+            System.err.println(rb.getString(
+                    "Use \"keytool -command_name -help\" for usage of command_name"));
+        }
     }
 
     private void tinyHelp() {
-        System.err.println(rb.getString("Try keytool -help"));
-
-        // do not drown user with the help lines.
+        usage();
         if (debug) {
             throw new RuntimeException("NO BIG ERROR, SORRY");
         } else {
@@ -3921,6 +3851,61 @@
                 rb.getString("Command option <flag> needs an argument.")).format(source));
         tinyHelp();
     }
+
+    private char[] getPass(String modifier, String arg) {
+        char[] output = getPassWithModifier(modifier, arg);
+        if (output != null) return output;
+        tinyHelp();
+        return null;    // Useless, tinyHelp() already exits.
+    }
+
+    // This method also used by JarSigner
+    public static char[] getPassWithModifier(String modifier, String arg) {
+        if (modifier == null) {
+            return arg.toCharArray();
+        } else if (collator.compare(modifier, "env") == 0) {
+            String value = System.getenv(arg);
+            if (value == null) {
+                System.err.println(rb.getString(
+                        "Cannot find environment variable: ") + arg);
+                return null;
+            } else {
+                return value.toCharArray();
+            }
+        } else if (collator.compare(modifier, "file") == 0) {
+            try {
+                URL url = null;
+                try {
+                    url = new URL(arg);
+                } catch (java.net.MalformedURLException mue) {
+                    File f = new File(arg);
+                    if (f.exists()) {
+                        url = f.toURI().toURL();
+                    } else {
+                        System.err.println(rb.getString(
+                                "Cannot find file: ") + arg);
+                        return null;
+                    }
+                }
+                BufferedReader br = new BufferedReader(new InputStreamReader(
+                            url.openStream()));
+                String value = br.readLine();
+                br.close();
+                if (value == null) {
+                    return new char[0];
+                } else {
+                    return value.toCharArray();
+                }
+            } catch (IOException ioe) {
+                System.err.println(ioe);
+                return null;
+            }
+        } else {
+            System.err.println(rb.getString("Unknown password type: ") +
+                    modifier);
+            return null;
+        }
+    }
 }
 
 // This class is exactly the same as com.sun.tools.javac.util.Pair,
@@ -3960,3 +3945,4 @@
         return new Pair<A,B>(a,b);
     }
 }
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/sun/security/util/PermissionFactory.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package sun.security.util;
+
+import java.security.Permission;
+
+/**
+ * A factory object that creates Permission objects.
+ */
+
+public interface PermissionFactory<T extends Permission> {
+    T newPermission(String name);
+}
--- a/jdk/src/share/classes/sun/security/util/Resources.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/security/util/Resources.java	Fri Oct 16 18:02:31 2009 -0700
@@ -46,18 +46,149 @@
         {"*******************************************\n\n",
                 "*******************************************\n\n"},
 
-        // keytool
+        // keytool: Help part
+        {" [OPTION]...", " [OPTION]..."},
+        {"Options:", "Options:"},
+        {"Use \"keytool -help\" for all available commands",
+                 "Use \"keytool -help\" for all available commands"},
+        {"Key and Certificate Management Tool",
+                 "Key and Certificate Management Tool"},
+        {"Commands:", "Commands:"},
+        {"Use \"keytool -command_name -help\" for usage of command_name",
+                "Use \"keytool -command_name -help\" for usage of command_name"},
+        // keytool: help: commands
+        {"Generates a certificate request",
+                "Generates a certificate request"}, //-certreq
+        {"Changes an entry's alias",
+                "Changes an entry's alias"}, //-changealias
+        {"Deletes an entry",
+                "Deletes an entry"}, //-delete
+        {"Exports certificate",
+                "Exports certificate"}, //-exportcert
+        {"Generates a key pair",
+                "Generates a key pair"}, //-genkeypair
+        {"Generates a secret key",
+                "Generates a secret key"}, //-genseckey
+        {"Generates certificate from a certificate request",
+                "Generates certificate from a certificate request"}, //-gencert
+        {"Imports entries from a JDK 1.1.x-style identity database",
+                "Imports entries from a JDK 1.1.x-style identity database"}, //-identitydb
+        {"Imports a certificate or a certificate chain",
+                "Imports a certificate or a certificate chain"}, //-importcert
+        {"Imports one or all entries from another keystore",
+                "Imports one or all entries from another keystore"}, //-importkeystore
+        {"Clones a key entry",
+                "Clones a key entry"}, //-keyclone
+        {"Changes the key password of an entry",
+                "Changes the key password of an entry"}, //-keypasswd
+        {"Lists entries in a keystore",
+                "Lists entries in a keystore"}, //-list
+        {"Prints the content of a certificate",
+                "Prints the content of a certificate"}, //-printcert
+        {"Prints the content of a certificate request",
+                "Prints the content of a certificate request"}, //-printcertreq
+        {"Generates a self-signed certificate",
+                "Generates a self-signed certificate"}, //-selfcert
+        {"Changes the store password of a keystore",
+                "Changes the store password of a keystore"}, //-storepasswd
+        // keytool: help: options
+        {"alias name of the entry to process",
+                "alias name of the entry to process"}, //-alias
+        {"destination alias",
+                "destination alias"}, //-destalias
+        {"destination key password",
+                "destination key password"}, //-destkeypass
+        {"destination keystore name",
+                "destination keystore name"}, //-destkeystore
+        {"destination keystore password protected",
+                "destination keystore password protected"}, //-destprotected
+        {"destination keystore provider name",
+                "destination keystore provider name"}, //-destprovidername
+        {"destination keystore password",
+                "destination keystore password"}, //-deststorepass
+        {"destination keystore type",
+                "destination keystore type"}, //-deststoretype
+        {"distinguished name",
+                "distinguished name"}, //-dname
+        {"X.509 extension",
+                "X.509 extension"}, //-ext
+        {"output file name",
+                "output file name"}, //-file
+        {"input file name",
+                "input file name"}, //-file
+        {"input file name",
+                "input file name"}, //-infile
+        {"key algorithm name",
+                "key algorithm name"}, //-keyalg
+        {"key password",
+                "key password"}, //-keypass
+        {"key bit size",
+                "key bit size"}, //-keysize
+        {"keystore name",
+                "keystore name"}, //-keystore
+        {"new password",
+                "new password"}, //-new
+        {"do not prompt",
+                "do not prompt"}, //-noprompt
+        {"output file name",
+                "output file name"}, //-outfile
+        {"password through protected mechanism",
+                "password through protected mechanism"}, //-protected
+        {"provider argument",
+                "provider argument"}, //-providerarg
+        {"provider class name",
+                "provider class name"}, //-providerclass
+        {"provider name",
+                "provider name"}, //-providername
+        {"provider classpath",
+                "provider classpath"}, //-providerpath
+        {"output in RFC style",
+                "output in RFC style"}, //-rfc
+        {"signature algorithm name",
+                "signature algorithm name"}, //-sigalg
+        {"source alias",
+                "source alias"}, //-srcalias
+        {"source keystore password",
+                "source keystore password"}, //-srckeypass
+        {"source keystore name",
+                "source keystore name"}, //-srckeystore
+        {"source keystore password protected",
+                "source keystore password protected"}, //-srcprotected
+        {"source keystore provider name",
+                "source keystore provider name"}, //-srcprovidername
+        {"source keystore password",
+                "source keystore password"}, //-srcstorepass
+        {"source keystore type",
+                "source keystore type"}, //-srcstoretype
+        {"SSL server host and port",
+                "SSL server host and port"}, //-sslserver
+        {"certificate validity start date/time",
+                "certificate validity start date/time"}, //-startdate
+        {"keystore password",
+                "keystore password"}, //-storepass
+        {"keystore type",
+                "keystore type"}, //-storetype
+        {"trust certificates from cacerts",
+                "trust certificates from cacerts"}, //-trustcacerts
+        {"verbose output",
+                "verbose output"}, //-v
+        {"validity number of days",
+                "validity number of days"}, //-validity
+        // keytool: Running part
         {"keytool error: ", "keytool error: "},
         {"Illegal option:  ", "Illegal option:  "},
         {"Illegal value: ", "Illegal value: "},
-        {"Try keytool -help","Try keytool -help"},
+        {"Unknown password type: ", "Unknown password type: "},
+        {"Cannot find environment variable: ",
+                "Cannot find environment variable: "},
+        {"Cannot find file: ", "Cannot find file: "},
         {"Command option <flag> needs an argument.", "Command option {0} needs an argument."},
         {"Warning:  Different store and key passwords not supported for PKCS12 KeyStores. Ignoring user-specified <command> value.",
                 "Warning:  Different store and key passwords not supported for PKCS12 KeyStores. Ignoring user-specified {0} value."},
         {"-keystore must be NONE if -storetype is {0}",
                 "-keystore must be NONE if -storetype is {0}"},
-        {"Too may retries, program terminated",
-                 "Too may retries, program terminated"},
+        {"Too many retries, program terminated",
+                 "Too many retries, program terminated"},
         {"-storepasswd and -keypasswd commands not supported if -storetype is {0}",
                 "-storepasswd and -keypasswd commands not supported if -storetype is {0}"},
         {"-keypasswd commands not supported if -storetype is PKCS12",
@@ -77,7 +208,6 @@
                 "Validity must be greater than zero"},
         {"provName not a provider", "{0} not a provider"},
         {"Usage error: no command provided", "Usage error: no command provided"},
-        {"Usage error, <arg> is not a legal command", "Usage error, {0} is not a legal command"},
         {"Source keystore file exists, but is empty: ", "Source keystore file exists, but is empty: "},
         {"Please specify -srckeystore", "Please specify -srckeystore"},
         {"Must not specify both -v and -rfc with 'list' command",
@@ -279,7 +409,6 @@
                 "Secret Key not generated, alias <{0}> already exists"},
         {"Please provide -keysize for secret key generation",
                 "Please provide -keysize for secret key generation"},
-        {"keytool usage:\n", "keytool usage:\n"},
 
         {"Extensions: ", "Extensions: "},
         {"(Empty value)", "(Empty value)"},
@@ -297,139 +426,6 @@
         {"Odd number of hex digits found: ", "Odd number of hex digits found: "},
         {"command {0} is ambiguous:", "command {0} is ambiguous:"},
 
-        {"-certreq     [-v] [-protected]",
-                "-certreq     [-v] [-protected]"},
-        {"\t     [-alias <alias>] [-sigalg <sigalg>]",
-                "\t     [-alias <alias>] [-sigalg <sigalg>]"},
-        {"\t     [-dname <dname>]", "\t     [-dname <dname>]"},
-        {"\t     [-file <csr_file>] [-keypass <keypass>]",
-                "\t     [-file <csr_file>] [-keypass <keypass>]"},
-        {"\t     [-keystore <keystore>] [-storepass <storepass>]",
-                "\t     [-keystore <keystore>] [-storepass <storepass>]"},
-        {"\t     [-storetype <storetype>] [-providername <name>]",
-                "\t     [-storetype <storetype>] [-providername <name>]"},
-        {"\t     [-providerclass <provider_class_name> [-providerarg <arg>]] ...",
-                "\t     [-providerclass <provider_class_name> [-providerarg <arg>]] ..."},
-        {"\t     [-providerpath <pathlist>]",
-                "\t     [-providerpath <pathlist>]"},
-        {"-delete      [-v] [-protected] -alias <alias>",
-                "-delete      [-v] [-protected] -alias <alias>"},
-        /** rest is same as -certreq starting from -keystore **/
-
-        //{"-export      [-v] [-rfc] [-protected]",
-        //       "-export      [-v] [-rfc] [-protected]"},
-        {"-exportcert  [-v] [-rfc] [-protected]",
-                "-exportcert  [-v] [-rfc] [-protected]"},
-        {"\t     [-alias <alias>] [-file <cert_file>]",
-                "\t     [-alias <alias>] [-file <cert_file>]"},
-        /** rest is same as -certreq starting from -keystore **/
-
-        //{"-genkey      [-v] [-protected]",
-        //        "-genkey      [-v] [-protected]"},
-        {"-genkeypair  [-v] [-protected]",
-                "-genkeypair  [-v] [-protected]"},
-        {"\t     [-alias <alias>]", "\t     [-alias <alias>]"},
-        {"\t     [-keyalg <keyalg>] [-keysize <keysize>]",
-                "\t     [-keyalg <keyalg>] [-keysize <keysize>]"},
-        {"\t     [-sigalg <sigalg>] [-dname <dname>]",
-                "\t     [-sigalg <sigalg>] [-dname <dname>]"},
-        {"\t     [-startdate <startdate>]",
-                "\t     [-startdate <startdate>]"},
-        {"\t     [-validity <valDays>] [-keypass <keypass>]",
-                "\t     [-validity <valDays>] [-keypass <keypass>]"},
-        /** rest is same as -certreq starting from -keystore **/
-        {"-gencert     [-v] [-rfc] [-protected]",
-                "-gencert     [-v] [-rfc] [-protected]"},
-        {"\t     [-infile <infile>] [-outfile <outfile>]",
-                 "\t     [-infile <infile>] [-outfile <outfile>]"},
-        {"\t     [-sigalg <sigalg>]",
-                "\t     [-sigalg <sigalg>]"},
-        {"\t     [-ext <key>[:critical][=<value>]]...",
-                "\t     [-ext <key>[:critical][=<value>]]..."},
-
-        {"-genseckey   [-v] [-protected]",
-                "-genseckey   [-v] [-protected]"},
-        /** rest is same as -certreq starting from -keystore **/
-
-        {"-help", "-help"},
-        //{"-identitydb  [-v] [-protected]",
-        //      "-identitydb  [-v] [-protected]"},
-        //{"\t     [-file <idb_file>]", "\t     [-file <idb_file>]"},
-        /** rest is same as -certreq starting from -keystore **/
-
-        //{"-import      [-v] [-noprompt] [-trustcacerts] [-protected]",
-        //       "-import      [-v] [-noprompt] [-trustcacerts] [-protected]"},
-        {"-importcert  [-v] [-noprompt] [-trustcacerts] [-protected]",
-                "-importcert  [-v] [-noprompt] [-trustcacerts] [-protected]"},
-        {"\t     [-alias <alias>]", "\t     [-alias <alias>]"},
-        {"\t     [-alias <alias>] [-keypass <keypass>]",
-            "\t     [-alias <alias>] [-keypass <keypass>]"},
-        {"\t     [-file <cert_file>] [-keypass <keypass>]",
-                "\t     [-file <cert_file>] [-keypass <keypass>]"},
-        /** rest is same as -certreq starting from -keystore **/
-
-        {"-importkeystore [-v] ",
-                "-importkeystore [-v] "},
-        {"\t     [-srckeystore <srckeystore>] [-destkeystore <destkeystore>]",
-                "\t     [-srckeystore <srckeystore>] [-destkeystore <destkeystore>]"},
-        {"\t     [-srcstoretype <srcstoretype>] [-deststoretype <deststoretype>]",
-                "\t     [-srcstoretype <srcstoretype>] [-deststoretype <deststoretype>]"},
-        {"\t     [-srcprotected] [-destprotected]",
-                "\t     [-srcprotected] [-destprotected]"},
-        {"\t     [-srcstorepass <srcstorepass>] [-deststorepass <deststorepass>]",
-                "\t     [-srcstorepass <srcstorepass>] [-deststorepass <deststorepass>]"},
-        {"\t     [-srcprovidername <srcprovidername>]\n\t     [-destprovidername <destprovidername>]",  // line too long, split to 2
-                 "\t     [-srcprovidername <srcprovidername>]\n\t     [-destprovidername <destprovidername>]"},
-        {"\t     [-srcalias <srcalias> [-destalias <destalias>]",
-                "\t     [-srcalias <srcalias> [-destalias <destalias>]"},
-        {"\t       [-srckeypass <srckeypass>] [-destkeypass <destkeypass>]]",
-                "\t       [-srckeypass <srckeypass>] [-destkeypass <destkeypass>]]"},
-        {"\t     [-noprompt]", "\t     [-noprompt]"},
-        /** rest is same as -certreq starting from -keystore **/
-
-        {"-changealias [-v] [-protected] -alias <alias> -destalias <destalias>",
-                "-changealias [-v] [-protected] -alias <alias> -destalias <destalias>"},
-        {"\t     [-keypass <keypass>]", "\t     [-keypass <keypass>]"},
-
-        //{"-keyclone    [-v] [-protected]",
-        //      "-keyclone    [-v] [-protected]"},
-        //{"\t     [-alias <alias>] -dest <dest_alias>",
-        //      "\t     [-alias <alias>] -dest <dest_alias>"},
-        //{"\t     [-keypass <keypass>] [-new <new_keypass>]",
-        //      "\t     [-keypass <keypass>] [-new <new_keypass>]"},
-        /** rest is same as -certreq starting from -keystore **/
-
-        {"-keypasswd   [-v] [-alias <alias>]",
-                "-keypasswd   [-v] [-alias <alias>]"},
-        {"\t     [-keypass <old_keypass>] [-new <new_keypass>]",
-                "\t     [-keypass <old_keypass>] [-new <new_keypass>]"},
-        /** rest is same as -certreq starting from -keystore **/
-
-        {"-list        [-v | -rfc] [-protected]",
-                "-list        [-v | -rfc] [-protected]"},
-        {"\t     [-alias <alias>]", "\t     [-alias <alias>]"},
-        /** rest is same as -certreq starting from -keystore **/
-
-        {"-printcert   [-v] [-rfc] [-file <cert_file> | -sslserver <host[:port]>]",
-                "-printcert   [-v] [-rfc] [-file <cert_file> | -sslserver <host[:port]>]"},
-        {"-printcertreq   [-v] [-file <cert_file>]",
-                 "-printcertreq   [-v] [-file <cert_file>]"},
-        {"No certificate from the SSL server",
-                "No certificate from the SSL server"},
-
-        //{"-selfcert    [-v] [-protected]",
-        //      "-selfcert    [-v] [-protected]"},
-        {"\t     [-alias <alias>]", "\t     [-alias <alias>]"},
-        //{"\t     [-dname <dname>] [-validity <valDays>]",
-        //      "\t     [-dname <dname>] [-validity <valDays>]"},
-        //{"\t     [-keypass <keypass>] [-sigalg <sigalg>]",
-        //      "\t     [-keypass <keypass>] [-sigalg <sigalg>]"},
-        /** rest is same as -certreq starting from -keystore **/
-
-        {"-storepasswd [-v] [-new <new_storepass>]",
-                "-storepasswd [-v] [-new <new_storepass>]"},
-        /** rest is same as -certreq starting from -keystore **/
-
         // policytool
         {"Warning: A public key for alias 'signers[i]' does not exist.  Make sure a KeyStore is properly configured.",
                 "Warning: A public key for alias {0} does not exist.  Make sure a KeyStore is properly configured."},
@@ -679,3 +675,4 @@
         return contents;
     }
 }
+
--- a/jdk/src/share/classes/sun/security/util/SecurityConstants.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/security/util/SecurityConstants.java	Fri Oct 16 18:02:31 2009 -0700
@@ -25,12 +25,12 @@
 
 package sun.security.util;
 
-import java.io.FilePermission;
-import java.awt.AWTPermission;
-import java.util.PropertyPermission;
-import java.lang.RuntimePermission;
 import java.net.SocketPermission;
 import java.net.NetPermission;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.Permission;
+import java.security.BasicPermission;
 import java.security.SecurityPermission;
 import java.security.AllPermission;
 import javax.security.auth.AuthPermission;
@@ -71,45 +71,118 @@
     // sun.security.provider.PolicyFile
     public static final AllPermission ALL_PERMISSION = new AllPermission();
 
-    // java.lang.SecurityManager
-    public static final AWTPermission TOPLEVEL_WINDOW_PERMISSION =
-        new AWTPermission("showWindowWithoutWarningBanner");
-
-    // java.lang.SecurityManager
-    public static final AWTPermission ACCESS_CLIPBOARD_PERMISSION =
-        new AWTPermission("accessClipboard");
+    /**
+     * Permission type used when AWT is not present.
+     */
+    private static class FakeAWTPermission extends BasicPermission {
+        private static final long serialVersionUID = -1L;
+        public FakeAWTPermission(String name) {
+            super(name);
+        }
+        public String toString() {
+            return "(\"java.awt.AWTPermission\" \"" + getName() + "\")";
+        }
+    }
 
-    // java.lang.SecurityManager
-    public static final AWTPermission CHECK_AWT_EVENTQUEUE_PERMISSION =
-        new AWTPermission("accessEventQueue");
+    /**
+     * Permission factory used when AWT is not present.
+     */
+    private static class FakeAWTPermissionFactory
+        implements PermissionFactory<FakeAWTPermission>
+    {
+        @Override
+        public FakeAWTPermission newPermission(String name) {
+            return new FakeAWTPermission(name);
+        }
+    }
 
-    // java.awt.Dialog
-    public static final AWTPermission TOOLKIT_MODALITY_PERMISSION =
-        new AWTPermission("toolkitModality");
+    /**
+     * AWT Permissions used in the JDK.
+     */
+    public static class AWT {
+        private AWT() { }
 
-    // java.awt.Robot
-    public static final AWTPermission READ_DISPLAY_PIXELS_PERMISSION =
-        new AWTPermission("readDisplayPixels");
+        /**
+         * The class name of the factory to create java.awt.AWTPermission objects.
+         */
+        private static final String AWTFactory = "sun.awt.AWTPermissionFactory";
+
+        /**
+         * The PermissionFactory to create AWT permissions (or fake permissions
+         * if AWT is not present).
+         */
+        private static final PermissionFactory<?> factory = permissionFactory();
 
-    // java.awt.Robot
-    public static final AWTPermission CREATE_ROBOT_PERMISSION =
-        new AWTPermission("createRobot");
+        private static PermissionFactory<?> permissionFactory() {
+            Class<?> c = AccessController
+                .doPrivileged(new PrivilegedAction<Class<?>>() {
+                    public Class<?> run() {
+                        try {
+                           return Class.forName(AWTFactory, true, null);
+                        } catch (ClassNotFoundException e) {
+                            // not available
+                            return null;
+                        }
+                    }});
+            if (c != null) {
+                // AWT present
+                try {
+                    return (PermissionFactory<?>)c.newInstance();
+                } catch (InstantiationException x) {
+                    throw new InternalError(x.getMessage());
+                } catch (IllegalAccessException x) {
+                    throw new InternalError(x.getMessage());
+                }
+            } else {
+                // AWT not present
+                return new FakeAWTPermissionFactory();
+            }
+        }
 
-    // java.awt.MouseInfo
-    public static final AWTPermission WATCH_MOUSE_PERMISSION =
-        new AWTPermission("watchMousePointer");
+        private static Permission newAWTPermission(String name) {
+            return factory.newPermission(name);
+        }
+
+        // java.lang.SecurityManager
+        public static final Permission TOPLEVEL_WINDOW_PERMISSION =
+            newAWTPermission("showWindowWithoutWarningBanner");
 
-    // java.awt.Window
-    public static final AWTPermission SET_WINDOW_ALWAYS_ON_TOP_PERMISSION =
-        new AWTPermission("setWindowAlwaysOnTop");
+        // java.lang.SecurityManager
+        public static final Permission ACCESS_CLIPBOARD_PERMISSION =
+            newAWTPermission("accessClipboard");
+
+        // java.lang.SecurityManager
+        public static final Permission CHECK_AWT_EVENTQUEUE_PERMISSION =
+            newAWTPermission("accessEventQueue");
+
+        // java.awt.Dialog
+        public static final Permission TOOLKIT_MODALITY_PERMISSION =
+            newAWTPermission("toolkitModality");
+
+        // java.awt.Robot
+        public static final Permission READ_DISPLAY_PIXELS_PERMISSION =
+            newAWTPermission("readDisplayPixels");
 
-    // java.awt.Toolkit
-    public static final AWTPermission ALL_AWT_EVENTS_PERMISSION =
-        new AWTPermission("listenToAllAWTEvents");
+        // java.awt.Robot
+        public static final Permission CREATE_ROBOT_PERMISSION =
+            newAWTPermission("createRobot");
+
+        // java.awt.MouseInfo
+        public static final Permission WATCH_MOUSE_PERMISSION =
+            newAWTPermission("watchMousePointer");
 
-    // java.awt.SystemTray
-    public static final AWTPermission ACCESS_SYSTEM_TRAY_PERMISSION =
-        new AWTPermission("accessSystemTray");
+        // java.awt.Window
+        public static final Permission SET_WINDOW_ALWAYS_ON_TOP_PERMISSION =
+            newAWTPermission("setWindowAlwaysOnTop");
+
+        // java.awt.Toolkit
+        public static final Permission ALL_AWT_EVENTS_PERMISSION =
+            newAWTPermission("listenToAllAWTEvents");
+
+        // java.awt.SystemTray
+        public static final Permission ACCESS_SYSTEM_TRAY_PERMISSION =
+            newAWTPermission("accessSystemTray");
+    }
 
     // java.net.URL
     public static final NetPermission SPECIFY_HANDLER_PERMISSION =
--- a/jdk/src/share/classes/sun/swing/SwingUtilities2.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/classes/sun/swing/SwingUtilities2.java	Fri Oct 16 18:02:31 2009 -0700
@@ -193,6 +193,19 @@
     }
 
     /**
+     * Fill the character buffer cache.  Return the buffer length.
+     */
+    private static int syncCharsBuffer(String s) {
+        int length = s.length();
+        if ((charsBuffer == null) || (charsBuffer.length < length)) {
+            charsBuffer = s.toCharArray();
+        } else {
+            s.getChars(0, length, charsBuffer, 0);
+        }
+        return length;
+    }
+
+    /**
      * checks whether TextLayout is required to handle characters.
      *
      * @param text characters to be tested
@@ -237,15 +250,23 @@
      * Returns the left side bearing of the first character of string. The
      * left side bearing is calculated from the passed in
      * FontMetrics.  If the passed in String is less than one
-     * character, this will throw a StringIndexOutOfBoundsException exception.
+     * character {@code 0} is returned.
      *
      * @param c JComponent that will display the string
      * @param fm FontMetrics used to measure the String width
      * @param string String to get the left side bearing for.
+     * @throws NullPointerException if {@code string} is {@code null}
+     *
+     * @return the left side bearing of the first character of string
+     * or {@code 0} if the string is empty
      */
     public static int getLeftSideBearing(JComponent c, FontMetrics fm,
                                          String string) {
-        return getLeftSideBearing(c, fm, string.charAt(0));
+        int res = 0;
+        if (!string.isEmpty()) {
+            res = getLeftSideBearing(c, fm, string.charAt(0));
+        }
+        return res;
     }
 
     /**
@@ -353,7 +374,21 @@
         if (string == null || string.equals("")) {
             return 0;
         }
-        return fm.stringWidth(string);
+        boolean needsTextLayout = ((c != null) &&
+                (c.getClientProperty(TextAttribute.NUMERIC_SHAPING) != null));
+        if (needsTextLayout) {
+            synchronized(charsBufferLock) {
+                int length = syncCharsBuffer(string);
+                needsTextLayout = isComplexLayout(charsBuffer, 0, length);
+            }
+        }
+        if (needsTextLayout) {
+            TextLayout layout = createTextLayout(c, string,
+                                    fm.getFont(), fm.getFontRenderContext());
+            return (int) layout.getAdvance();
+        } else {
+            return fm.stringWidth(string);
+        }
     }
 
 
@@ -394,21 +429,11 @@
                                     String string, int availTextWidth) {
         // c may be null here.
         String clipString = "...";
-        int stringLength = string.length();
         availTextWidth -= SwingUtilities2.stringWidth(c, fm, clipString);
-        if (availTextWidth <= 0) {
-            //can not fit any characters
-            return clipString;
-        }
-
         boolean needsTextLayout;
 
         synchronized (charsBufferLock) {
-            if (charsBuffer == null || charsBuffer.length < stringLength) {
-                charsBuffer  = string.toCharArray();
-            } else {
-                string.getChars(0, stringLength, charsBuffer, 0);
-            }
+            int stringLength = syncCharsBuffer(string);
             needsTextLayout =
                 isComplexLayout(charsBuffer, 0, stringLength);
             if (!needsTextLayout) {
@@ -425,6 +450,10 @@
         if (needsTextLayout) {
             FontRenderContext frc = getFontRenderContext(c, fm);
             AttributedString aString = new AttributedString(string);
+            if (c != null) {
+                aString.addAttribute(TextAttribute.NUMERIC_SHAPING,
+                        c.getClientProperty(TextAttribute.NUMERIC_SHAPING));
+            }
             LineBreakMeasurer measurer =
                 new LineBreakMeasurer(aString.getIterator(), frc);
             int nChars = measurer.nextOffset(availTextWidth);
@@ -465,7 +494,7 @@
                  */
                 float screenWidth = (float)
                    g2d.getFont().getStringBounds(text, DEFAULT_FRC).getWidth();
-                TextLayout layout = new TextLayout(text, g2d.getFont(),
+                TextLayout layout = createTextLayout(c, text, g2d.getFont(),
                                                    g2d.getFontRenderContext());
 
                 layout = layout.getJustifiedLayout(screenWidth);
@@ -505,7 +534,21 @@
                 }
             }
 
-            g.drawString(text, x, y);
+            boolean needsTextLayout = ((c != null) &&
+                (c.getClientProperty(TextAttribute.NUMERIC_SHAPING) != null));
+            if (needsTextLayout) {
+                synchronized(charsBufferLock) {
+                    int length = syncCharsBuffer(text);
+                    needsTextLayout = isComplexLayout(charsBuffer, 0, length);
+                }
+            }
+            if (needsTextLayout) {
+                TextLayout layout = createTextLayout(c, text, g2.getFont(),
+                                                    g2.getFontRenderContext());
+                layout.draw(g2, x, y);
+            } else {
+                g.drawString(text, x, y);
+            }
 
             if (oldAAValue != null) {
                 g2.setRenderingHint(KEY_TEXT_ANTIALIASING, oldAAValue);
@@ -547,11 +590,7 @@
             boolean needsTextLayout = isPrinting;
             if (!needsTextLayout) {
                 synchronized (charsBufferLock) {
-                    if (charsBuffer == null || charsBuffer.length < textLength) {
-                        charsBuffer = text.toCharArray();
-                    } else {
-                        text.getChars(0, textLength, charsBuffer, 0);
-                    }
+                    syncCharsBuffer(text);
                     needsTextLayout =
                         isComplexLayout(charsBuffer, 0, textLength);
                 }
@@ -567,7 +606,7 @@
                 Graphics2D g2d = getGraphics2D(g);
                 if (g2d != null) {
                     TextLayout layout =
-                        new TextLayout(text, g2d.getFont(),
+                        createTextLayout(c, text, g2d.getFont(),
                                        g2d.getFontRenderContext());
                     if (isPrinting) {
                         float screenWidth = (float)g2d.getFont().
@@ -728,7 +767,7 @@
                     !isFontRenderContextPrintCompatible
                     (deviceFontRenderContext, frc)) {
                     TextLayout layout =
-                        new TextLayout(new String(data,offset,length),
+                        createTextLayout(c, new String(data, offset, length),
                                        g2d.getFont(),
                                        deviceFontRenderContext);
                     float screenWidth = (float)g2d.getFont().
@@ -846,6 +885,20 @@
         return retVal;
     }
 
+    private static TextLayout createTextLayout(JComponent c, String s,
+                                            Font f, FontRenderContext frc) {
+        Object shaper = (c == null ?
+                    null : c.getClientProperty(TextAttribute.NUMERIC_SHAPING));
+        if (shaper == null) {
+            return new TextLayout(s, f, frc);
+        } else {
+            Map<TextAttribute, Object> a = new HashMap<TextAttribute, Object>();
+            a.put(TextAttribute.FONT, f);
+            a.put(TextAttribute.NUMERIC_SHAPING, shaper);
+            return new TextLayout(s, a, frc);
+        }
+    }
+
     /*
      * Checks if two given FontRenderContexts are compatible for printing.
      * We can't just use equals as we want to exclude from the comparison :
--- a/jdk/src/share/native/common/check_code.c	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/native/common/check_code.c	Fri Oct 16 18:02:31 2009 -0700
@@ -338,7 +338,8 @@
                           int** code_lengths, unsigned char*** code);
 static void verify_method(context_type *context, jclass cb, int index,
                           int code_length, unsigned char* code);
-static void free_all_code(int num_methods, int* lengths, unsigned char** code);
+static void free_all_code(context_type* context, int num_methods,
+                          unsigned char** code);
 static void verify_field(context_type *context, jclass cb, int index);
 
 static void verify_opcode_operands (context_type *, unsigned int inumber, int offset);
@@ -813,11 +814,11 @@
         /* Look at each method */
         for (i = JVM_GetClassFieldsCount(env, cb); --i >= 0;)
             verify_field(context, cb, i);
-  num_methods = JVM_GetClassMethodsCount(env, cb);
-  read_all_code(context, cb, num_methods, &code_lengths, &code);
-  for (i = num_methods - 1; i >= 0; --i)
+        num_methods = JVM_GetClassMethodsCount(env, cb);
+        read_all_code(context, cb, num_methods, &code_lengths, &code);
+        for (i = num_methods - 1; i >= 0; --i)
             verify_method(context, cb, i, code_lengths[i], code[i]);
-  free_all_code(num_methods, code_lengths, code);
+        free_all_code(context, num_methods, code);
         result = CC_OK;
     } else {
         result = context->err_code;
@@ -836,9 +837,6 @@
     if (context->exceptions)
         free(context->exceptions);
 
-    if (context->code)
-        free(context->code);
-
     if (context->constant_types)
         free(context->constant_types);
 
@@ -895,41 +893,42 @@
 read_all_code(context_type* context, jclass cb, int num_methods,
               int** lengths_addr, unsigned char*** code_addr)
 {
-  int* lengths = malloc(sizeof(int) * num_methods);
-  unsigned char** code = malloc(sizeof(unsigned char*) * num_methods);
-
-  *(lengths_addr) = lengths;
-  *(code_addr) = code;
-
-  if (lengths == 0 || code == 0) {
-    CCout_of_memory(context);
-  } else {
+    int* lengths;
+    unsigned char** code;
     int i;
+
+    lengths = malloc(sizeof(int) * num_methods);
+    check_and_push(context, lengths, VM_MALLOC_BLK);
+
+    code = malloc(sizeof(unsigned char*) * num_methods);
+    check_and_push(context, code, VM_MALLOC_BLK);
+
+    *(lengths_addr) = lengths;
+    *(code_addr) = code;
+
     for (i = 0; i < num_methods; ++i) {
-      lengths[i] = JVM_GetMethodIxByteCodeLength(context->env, cb, i);
-      if (lengths[i] != 0) {
-        code[i] = malloc(sizeof(unsigned char) * (lengths[i] + 1));
-        if (code[i] == NULL) {
-          CCout_of_memory(context);
+        lengths[i] = JVM_GetMethodIxByteCodeLength(context->env, cb, i);
+        if (lengths[i] > 0) {
+            code[i] = malloc(sizeof(unsigned char) * (lengths[i] + 1));
+            check_and_push(context, code[i], VM_MALLOC_BLK);
+            JVM_GetMethodIxByteCode(context->env, cb, i, code[i]);
         } else {
-          JVM_GetMethodIxByteCode(context->env, cb, i, code[i]);
+            code[i] = NULL;
         }
-      } else {
-        code[i] = NULL;
-      }
     }
-  }
 }
 
 static void
-free_all_code(int num_methods, int* lengths, unsigned char** code)
+free_all_code(context_type* context, int num_methods, unsigned char** code)
 {
   int i;
   for (i = 0; i < num_methods; ++i) {
-    free(code[i]);
+      if (code[i] != NULL) {
+          pop_and_free(context);
+      }
   }
-  free(lengths);
-  free(code);
+  pop_and_free(context); /* code */
+  pop_and_free(context); /* lengths */
 }
 
 /* Verify the code of one method */
--- a/jdk/src/share/native/sun/awt/giflib/gifalloc.c	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/native/sun/awt/giflib/gifalloc.c	Fri Oct 16 18:02:31 2009 -0700
@@ -88,6 +88,7 @@
 
     Object->Colors = (GifColorType *)calloc(ColorCount, sizeof(GifColorType));
     if (Object->Colors == (GifColorType *) NULL) {
+        free(Object);
         return ((ColorMapObject *) NULL);
     }
 
--- a/jdk/src/share/native/sun/misc/VM.c	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/share/native/sun/misc/VM.c	Fri Oct 16 18:02:31 2009 -0700
@@ -131,17 +131,6 @@
 
         /* obtain the JVM version info */
         (*func_p)(env, &info, sizeof(info));
-
-        if (info.is_kernel_jvm == 1) {
-            /* set the static field VM.kernelVM to true for kernel VM */
-            fid = (*env)->GetStaticFieldID(env, cls, "kernelVM", "Z");
-            if (fid != 0) {
-                (*env)->SetStaticBooleanField(env, cls, fid, info.is_kernel_jvm);
-            } else {
-                sprintf(errmsg, "Static kernelVM boolean field not found");
-                JNU_ThrowInternalError(env, errmsg);
-            }
-        }
     }
 }
 
--- a/jdk/src/share/native/sun/security/ec/ec.h	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,72 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Elliptic Curve Cryptography library.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef __ec_h_
-#define __ec_h_
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#define EC_DEBUG                          0
-#define EC_POINT_FORM_COMPRESSED_Y0    0x02
-#define EC_POINT_FORM_COMPRESSED_Y1    0x03
-#define EC_POINT_FORM_UNCOMPRESSED     0x04
-#define EC_POINT_FORM_HYBRID_Y0        0x06
-#define EC_POINT_FORM_HYBRID_Y1        0x07
-
-#define ANSI_X962_CURVE_OID_TOTAL_LEN    10
-#define SECG_CURVE_OID_TOTAL_LEN          7
-
-#endif /* __ec_h_ */
--- a/jdk/src/share/native/sun/security/ec/ec2.h	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,146 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library for binary polynomial field curves.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _EC2_H
-#define _EC2_H
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "ecl-priv.h"
-
-/* Checks if point P(px, py) is at infinity.  Uses affine coordinates. */
-mp_err ec_GF2m_pt_is_inf_aff(const mp_int *px, const mp_int *py);
-
-/* Sets P(px, py) to be the point at infinity.  Uses affine coordinates. */
-mp_err ec_GF2m_pt_set_inf_aff(mp_int *px, mp_int *py);
-
-/* Computes R = P + Q where R is (rx, ry), P is (px, py) and Q is (qx,
- * qy). Uses affine coordinates. */
-mp_err ec_GF2m_pt_add_aff(const mp_int *px, const mp_int *py,
-                                                  const mp_int *qx, const mp_int *qy, mp_int *rx,
-                                                  mp_int *ry, const ECGroup *group);
-
-/* Computes R = P - Q.  Uses affine coordinates. */
-mp_err ec_GF2m_pt_sub_aff(const mp_int *px, const mp_int *py,
-                                                  const mp_int *qx, const mp_int *qy, mp_int *rx,
-                                                  mp_int *ry, const ECGroup *group);
-
-/* Computes R = 2P.  Uses affine coordinates. */
-mp_err ec_GF2m_pt_dbl_aff(const mp_int *px, const mp_int *py, mp_int *rx,
-                                                  mp_int *ry, const ECGroup *group);
-
-/* Validates a point on a GF2m curve. */
-mp_err ec_GF2m_validate_point(const mp_int *px, const mp_int *py, const ECGroup *group);
-
-/* by default, this routine is unused and thus doesn't need to be compiled */
-#ifdef ECL_ENABLE_GF2M_PT_MUL_AFF
-/* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters
- * a, b and p are the elliptic curve coefficients and the irreducible that
- * determines the field GF2m.  Uses affine coordinates. */
-mp_err ec_GF2m_pt_mul_aff(const mp_int *n, const mp_int *px,
-                                                  const mp_int *py, mp_int *rx, mp_int *ry,
-                                                  const ECGroup *group);
-#endif
-
-/* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters
- * a, b and p are the elliptic curve coefficients and the irreducible that
- * determines the field GF2m.  Uses Montgomery projective coordinates. */
-mp_err ec_GF2m_pt_mul_mont(const mp_int *n, const mp_int *px,
-                                                   const mp_int *py, mp_int *rx, mp_int *ry,
-                                                   const ECGroup *group);
-
-#ifdef ECL_ENABLE_GF2M_PROJ
-/* Converts a point P(px, py) from affine coordinates to projective
- * coordinates R(rx, ry, rz). */
-mp_err ec_GF2m_pt_aff2proj(const mp_int *px, const mp_int *py, mp_int *rx,
-                                                   mp_int *ry, mp_int *rz, const ECGroup *group);
-
-/* Converts a point P(px, py, pz) from projective coordinates to affine
- * coordinates R(rx, ry). */
-mp_err ec_GF2m_pt_proj2aff(const mp_int *px, const mp_int *py,
-                                                   const mp_int *pz, mp_int *rx, mp_int *ry,
-                                                   const ECGroup *group);
-
-/* Checks if point P(px, py, pz) is at infinity.  Uses projective
- * coordinates. */
-mp_err ec_GF2m_pt_is_inf_proj(const mp_int *px, const mp_int *py,
-                                                          const mp_int *pz);
-
-/* Sets P(px, py, pz) to be the point at infinity.  Uses projective
- * coordinates. */
-mp_err ec_GF2m_pt_set_inf_proj(mp_int *px, mp_int *py, mp_int *pz);
-
-/* Computes R = P + Q where R is (rx, ry, rz), P is (px, py, pz) and Q is
- * (qx, qy, qz).  Uses projective coordinates. */
-mp_err ec_GF2m_pt_add_proj(const mp_int *px, const mp_int *py,
-                                                   const mp_int *pz, const mp_int *qx,
-                                                   const mp_int *qy, mp_int *rx, mp_int *ry,
-                                                   mp_int *rz, const ECGroup *group);
-
-/* Computes R = 2P.  Uses projective coordinates. */
-mp_err ec_GF2m_pt_dbl_proj(const mp_int *px, const mp_int *py,
-                                                   const mp_int *pz, mp_int *rx, mp_int *ry,
-                                                   mp_int *rz, const ECGroup *group);
-
-/* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters
- * a, b and p are the elliptic curve coefficients and the prime that
- * determines the field GF2m.  Uses projective coordinates. */
-mp_err ec_GF2m_pt_mul_proj(const mp_int *n, const mp_int *px,
-                                                   const mp_int *py, mp_int *rx, mp_int *ry,
-                                                   const ECGroup *group);
-#endif
-
-#endif /* _EC2_H */
--- a/jdk/src/share/native/sun/security/ec/ec2_163.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,281 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library for binary polynomial field curves.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Sheueling Chang-Shantz <sheueling.chang@sun.com>,
- *   Stephen Fung <fungstep@hotmail.com>, and
- *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories.
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "ec2.h"
-#include "mp_gf2m.h"
-#include "mp_gf2m-priv.h"
-#include "mpi.h"
-#include "mpi-priv.h"
-#ifndef _KERNEL
-#include <stdlib.h>
-#endif
-
-/* Fast reduction for polynomials over a 163-bit curve. Assumes reduction
- * polynomial with terms {163, 7, 6, 3, 0}. */
-mp_err
-ec_GF2m_163_mod(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_digit *u, z;
-
-        if (a != r) {
-                MP_CHECKOK(mp_copy(a, r));
-        }
-#ifdef ECL_SIXTY_FOUR_BIT
-        if (MP_USED(r) < 6) {
-                MP_CHECKOK(s_mp_pad(r, 6));
-        }
-        u = MP_DIGITS(r);
-        MP_USED(r) = 6;
-
-        /* u[5] only has 6 significant bits */
-        z = u[5];
-        u[2] ^= (z << 36) ^ (z << 35) ^ (z << 32) ^ (z << 29);
-        z = u[4];
-        u[2] ^= (z >> 28) ^ (z >> 29) ^ (z >> 32) ^ (z >> 35);
-        u[1] ^= (z << 36) ^ (z << 35) ^ (z << 32) ^ (z << 29);
-        z = u[3];
-        u[1] ^= (z >> 28) ^ (z >> 29) ^ (z >> 32) ^ (z >> 35);
-        u[0] ^= (z << 36) ^ (z << 35) ^ (z << 32) ^ (z << 29);
-        z = u[2] >> 35;                         /* z only has 29 significant bits */
-        u[0] ^= (z << 7) ^ (z << 6) ^ (z << 3) ^ z;
-        /* clear bits above 163 */
-        u[5] = u[4] = u[3] = 0;
-        u[2] ^= z << 35;
-#else
-        if (MP_USED(r) < 11) {
-                MP_CHECKOK(s_mp_pad(r, 11));
-        }
-        u = MP_DIGITS(r);
-        MP_USED(r) = 11;
-
-        /* u[11] only has 6 significant bits */
-        z = u[10];
-        u[5] ^= (z << 4) ^ (z << 3) ^ z ^ (z >> 3);
-        u[4] ^= (z << 29);
-        z = u[9];
-        u[5] ^= (z >> 28) ^ (z >> 29);
-        u[4] ^= (z << 4) ^ (z << 3) ^ z ^ (z >> 3);
-        u[3] ^= (z << 29);
-        z = u[8];
-        u[4] ^= (z >> 28) ^ (z >> 29);
-        u[3] ^= (z << 4) ^ (z << 3) ^ z ^ (z >> 3);
-        u[2] ^= (z << 29);
-        z = u[7];
-        u[3] ^= (z >> 28) ^ (z >> 29);
-        u[2] ^= (z << 4) ^ (z << 3) ^ z ^ (z >> 3);
-        u[1] ^= (z << 29);
-        z = u[6];
-        u[2] ^= (z >> 28) ^ (z >> 29);
-        u[1] ^= (z << 4) ^ (z << 3) ^ z ^ (z >> 3);
-        u[0] ^= (z << 29);
-        z = u[5] >> 3;                          /* z only has 29 significant bits */
-        u[1] ^= (z >> 25) ^ (z >> 26);
-        u[0] ^= (z << 7) ^ (z << 6) ^ (z << 3) ^ z;
-        /* clear bits above 163 */
-        u[11] = u[10] = u[9] = u[8] = u[7] = u[6] = 0;
-        u[5] ^= z << 3;
-#endif
-        s_mp_clamp(r);
-
-  CLEANUP:
-        return res;
-}
-
-/* Fast squaring for polynomials over a 163-bit curve. Assumes reduction
- * polynomial with terms {163, 7, 6, 3, 0}. */
-mp_err
-ec_GF2m_163_sqr(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_digit *u, *v;
-
-        v = MP_DIGITS(a);
-
-#ifdef ECL_SIXTY_FOUR_BIT
-        if (MP_USED(a) < 3) {
-                return mp_bsqrmod(a, meth->irr_arr, r);
-        }
-        if (MP_USED(r) < 6) {
-                MP_CHECKOK(s_mp_pad(r, 6));
-        }
-        MP_USED(r) = 6;
-#else
-        if (MP_USED(a) < 6) {
-                return mp_bsqrmod(a, meth->irr_arr, r);
-        }
-        if (MP_USED(r) < 12) {
-                MP_CHECKOK(s_mp_pad(r, 12));
-        }
-        MP_USED(r) = 12;
-#endif
-        u = MP_DIGITS(r);
-
-#ifdef ECL_THIRTY_TWO_BIT
-        u[11] = gf2m_SQR1(v[5]);
-        u[10] = gf2m_SQR0(v[5]);
-        u[9] = gf2m_SQR1(v[4]);
-        u[8] = gf2m_SQR0(v[4]);
-        u[7] = gf2m_SQR1(v[3]);
-        u[6] = gf2m_SQR0(v[3]);
-#endif
-        u[5] = gf2m_SQR1(v[2]);
-        u[4] = gf2m_SQR0(v[2]);
-        u[3] = gf2m_SQR1(v[1]);
-        u[2] = gf2m_SQR0(v[1]);
-        u[1] = gf2m_SQR1(v[0]);
-        u[0] = gf2m_SQR0(v[0]);
-        return ec_GF2m_163_mod(r, r, meth);
-
-  CLEANUP:
-        return res;
-}
-
-/* Fast multiplication for polynomials over a 163-bit curve. Assumes
- * reduction polynomial with terms {163, 7, 6, 3, 0}. */
-mp_err
-ec_GF2m_163_mul(const mp_int *a, const mp_int *b, mp_int *r,
-                                const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_digit a2 = 0, a1 = 0, a0, b2 = 0, b1 = 0, b0;
-
-#ifdef ECL_THIRTY_TWO_BIT
-        mp_digit a5 = 0, a4 = 0, a3 = 0, b5 = 0, b4 = 0, b3 = 0;
-        mp_digit rm[6];
-#endif
-
-        if (a == b) {
-                return ec_GF2m_163_sqr(a, r, meth);
-        } else {
-                switch (MP_USED(a)) {
-#ifdef ECL_THIRTY_TWO_BIT
-                case 6:
-                        a5 = MP_DIGIT(a, 5);
-                case 5:
-                        a4 = MP_DIGIT(a, 4);
-                case 4:
-                        a3 = MP_DIGIT(a, 3);
-#endif
-                case 3:
-                        a2 = MP_DIGIT(a, 2);
-                case 2:
-                        a1 = MP_DIGIT(a, 1);
-                default:
-                        a0 = MP_DIGIT(a, 0);
-                }
-                switch (MP_USED(b)) {
-#ifdef ECL_THIRTY_TWO_BIT
-                case 6:
-                        b5 = MP_DIGIT(b, 5);
-                case 5:
-                        b4 = MP_DIGIT(b, 4);
-                case 4:
-                        b3 = MP_DIGIT(b, 3);
-#endif
-                case 3:
-                        b2 = MP_DIGIT(b, 2);
-                case 2:
-                        b1 = MP_DIGIT(b, 1);
-                default:
-                        b0 = MP_DIGIT(b, 0);
-                }
-#ifdef ECL_SIXTY_FOUR_BIT
-                MP_CHECKOK(s_mp_pad(r, 6));
-                s_bmul_3x3(MP_DIGITS(r), a2, a1, a0, b2, b1, b0);
-                MP_USED(r) = 6;
-                s_mp_clamp(r);
-#else
-                MP_CHECKOK(s_mp_pad(r, 12));
-                s_bmul_3x3(MP_DIGITS(r) + 6, a5, a4, a3, b5, b4, b3);
-                s_bmul_3x3(MP_DIGITS(r), a2, a1, a0, b2, b1, b0);
-                s_bmul_3x3(rm, a5 ^ a2, a4 ^ a1, a3 ^ a0, b5 ^ b2, b4 ^ b1,
-                                   b3 ^ b0);
-                rm[5] ^= MP_DIGIT(r, 5) ^ MP_DIGIT(r, 11);
-                rm[4] ^= MP_DIGIT(r, 4) ^ MP_DIGIT(r, 10);
-                rm[3] ^= MP_DIGIT(r, 3) ^ MP_DIGIT(r, 9);
-                rm[2] ^= MP_DIGIT(r, 2) ^ MP_DIGIT(r, 8);
-                rm[1] ^= MP_DIGIT(r, 1) ^ MP_DIGIT(r, 7);
-                rm[0] ^= MP_DIGIT(r, 0) ^ MP_DIGIT(r, 6);
-                MP_DIGIT(r, 8) ^= rm[5];
-                MP_DIGIT(r, 7) ^= rm[4];
-                MP_DIGIT(r, 6) ^= rm[3];
-                MP_DIGIT(r, 5) ^= rm[2];
-                MP_DIGIT(r, 4) ^= rm[1];
-                MP_DIGIT(r, 3) ^= rm[0];
-                MP_USED(r) = 12;
-                s_mp_clamp(r);
-#endif
-                return ec_GF2m_163_mod(r, r, meth);
-        }
-
-  CLEANUP:
-        return res;
-}
-
-/* Wire in fast field arithmetic for 163-bit curves. */
-mp_err
-ec_group_set_gf2m163(ECGroup *group, ECCurveName name)
-{
-        group->meth->field_mod = &ec_GF2m_163_mod;
-        group->meth->field_mul = &ec_GF2m_163_mul;
-        group->meth->field_sqr = &ec_GF2m_163_sqr;
-        return MP_OKAY;
-}
--- a/jdk/src/share/native/sun/security/ec/ec2_193.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,298 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library for binary polynomial field curves.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Sheueling Chang-Shantz <sheueling.chang@sun.com>,
- *   Stephen Fung <fungstep@hotmail.com>, and
- *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories.
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "ec2.h"
-#include "mp_gf2m.h"
-#include "mp_gf2m-priv.h"
-#include "mpi.h"
-#include "mpi-priv.h"
-#ifndef _KERNEL
-#include <stdlib.h>
-#endif
-
-/* Fast reduction for polynomials over a 193-bit curve. Assumes reduction
- * polynomial with terms {193, 15, 0}. */
-mp_err
-ec_GF2m_193_mod(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_digit *u, z;
-
-        if (a != r) {
-                MP_CHECKOK(mp_copy(a, r));
-        }
-#ifdef ECL_SIXTY_FOUR_BIT
-        if (MP_USED(r) < 7) {
-                MP_CHECKOK(s_mp_pad(r, 7));
-        }
-        u = MP_DIGITS(r);
-        MP_USED(r) = 7;
-
-        /* u[6] only has 2 significant bits */
-        z = u[6];
-        u[3] ^= (z << 14) ^ (z >> 1);
-        u[2] ^= (z << 63);
-        z = u[5];
-        u[3] ^= (z >> 50);
-        u[2] ^= (z << 14) ^ (z >> 1);
-        u[1] ^= (z << 63);
-        z = u[4];
-        u[2] ^= (z >> 50);
-        u[1] ^= (z << 14) ^ (z >> 1);
-        u[0] ^= (z << 63);
-        z = u[3] >> 1;                          /* z only has 63 significant bits */
-        u[1] ^= (z >> 49);
-        u[0] ^= (z << 15) ^ z;
-        /* clear bits above 193 */
-        u[6] = u[5] = u[4] = 0;
-        u[3] ^= z << 1;
-#else
-        if (MP_USED(r) < 13) {
-                MP_CHECKOK(s_mp_pad(r, 13));
-        }
-        u = MP_DIGITS(r);
-        MP_USED(r) = 13;
-
-        /* u[12] only has 2 significant bits */
-        z = u[12];
-        u[6] ^= (z << 14) ^ (z >> 1);
-        u[5] ^= (z << 31);
-        z = u[11];
-        u[6] ^= (z >> 18);
-        u[5] ^= (z << 14) ^ (z >> 1);
-        u[4] ^= (z << 31);
-        z = u[10];
-        u[5] ^= (z >> 18);
-        u[4] ^= (z << 14) ^ (z >> 1);
-        u[3] ^= (z << 31);
-        z = u[9];
-        u[4] ^= (z >> 18);
-        u[3] ^= (z << 14) ^ (z >> 1);
-        u[2] ^= (z << 31);
-        z = u[8];
-        u[3] ^= (z >> 18);
-        u[2] ^= (z << 14) ^ (z >> 1);
-        u[1] ^= (z << 31);
-        z = u[7];
-        u[2] ^= (z >> 18);
-        u[1] ^= (z << 14) ^ (z >> 1);
-        u[0] ^= (z << 31);
-        z = u[6] >> 1;                          /* z only has 31 significant bits */
-        u[1] ^= (z >> 17);
-        u[0] ^= (z << 15) ^ z;
-        /* clear bits above 193 */
-        u[12] = u[11] = u[10] = u[9] = u[8] = u[7] = 0;
-        u[6] ^= z << 1;
-#endif
-        s_mp_clamp(r);
-
-  CLEANUP:
-        return res;
-}
-
-/* Fast squaring for polynomials over a 193-bit curve. Assumes reduction
- * polynomial with terms {193, 15, 0}. */
-mp_err
-ec_GF2m_193_sqr(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_digit *u, *v;
-
-        v = MP_DIGITS(a);
-
-#ifdef ECL_SIXTY_FOUR_BIT
-        if (MP_USED(a) < 4) {
-                return mp_bsqrmod(a, meth->irr_arr, r);
-        }
-        if (MP_USED(r) < 7) {
-                MP_CHECKOK(s_mp_pad(r, 7));
-        }
-        MP_USED(r) = 7;
-#else
-        if (MP_USED(a) < 7) {
-                return mp_bsqrmod(a, meth->irr_arr, r);
-        }
-        if (MP_USED(r) < 13) {
-                MP_CHECKOK(s_mp_pad(r, 13));
-        }
-        MP_USED(r) = 13;
-#endif
-        u = MP_DIGITS(r);
-
-#ifdef ECL_THIRTY_TWO_BIT
-        u[12] = gf2m_SQR0(v[6]);
-        u[11] = gf2m_SQR1(v[5]);
-        u[10] = gf2m_SQR0(v[5]);
-        u[9] = gf2m_SQR1(v[4]);
-        u[8] = gf2m_SQR0(v[4]);
-        u[7] = gf2m_SQR1(v[3]);
-#endif
-        u[6] = gf2m_SQR0(v[3]);
-        u[5] = gf2m_SQR1(v[2]);
-        u[4] = gf2m_SQR0(v[2]);
-        u[3] = gf2m_SQR1(v[1]);
-        u[2] = gf2m_SQR0(v[1]);
-        u[1] = gf2m_SQR1(v[0]);
-        u[0] = gf2m_SQR0(v[0]);
-        return ec_GF2m_193_mod(r, r, meth);
-
-  CLEANUP:
-        return res;
-}
-
-/* Fast multiplication for polynomials over a 193-bit curve. Assumes
- * reduction polynomial with terms {193, 15, 0}. */
-mp_err
-ec_GF2m_193_mul(const mp_int *a, const mp_int *b, mp_int *r,
-                                const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_digit a3 = 0, a2 = 0, a1 = 0, a0, b3 = 0, b2 = 0, b1 = 0, b0;
-
-#ifdef ECL_THIRTY_TWO_BIT
-        mp_digit a6 = 0, a5 = 0, a4 = 0, b6 = 0, b5 = 0, b4 = 0;
-        mp_digit rm[8];
-#endif
-
-        if (a == b) {
-                return ec_GF2m_193_sqr(a, r, meth);
-        } else {
-                switch (MP_USED(a)) {
-#ifdef ECL_THIRTY_TWO_BIT
-                case 7:
-                        a6 = MP_DIGIT(a, 6);
-                case 6:
-                        a5 = MP_DIGIT(a, 5);
-                case 5:
-                        a4 = MP_DIGIT(a, 4);
-#endif
-                case 4:
-                        a3 = MP_DIGIT(a, 3);
-                case 3:
-                        a2 = MP_DIGIT(a, 2);
-                case 2:
-                        a1 = MP_DIGIT(a, 1);
-                default:
-                        a0 = MP_DIGIT(a, 0);
-                }
-                switch (MP_USED(b)) {
-#ifdef ECL_THIRTY_TWO_BIT
-                case 7:
-                        b6 = MP_DIGIT(b, 6);
-                case 6:
-                        b5 = MP_DIGIT(b, 5);
-                case 5:
-                        b4 = MP_DIGIT(b, 4);
-#endif
-                case 4:
-                        b3 = MP_DIGIT(b, 3);
-                case 3:
-                        b2 = MP_DIGIT(b, 2);
-                case 2:
-                        b1 = MP_DIGIT(b, 1);
-                default:
-                        b0 = MP_DIGIT(b, 0);
-                }
-#ifdef ECL_SIXTY_FOUR_BIT
-                MP_CHECKOK(s_mp_pad(r, 8));
-                s_bmul_4x4(MP_DIGITS(r), a3, a2, a1, a0, b3, b2, b1, b0);
-                MP_USED(r) = 8;
-                s_mp_clamp(r);
-#else
-                MP_CHECKOK(s_mp_pad(r, 14));
-                s_bmul_3x3(MP_DIGITS(r) + 8, a6, a5, a4, b6, b5, b4);
-                s_bmul_4x4(MP_DIGITS(r), a3, a2, a1, a0, b3, b2, b1, b0);
-                s_bmul_4x4(rm, a3, a6 ^ a2, a5 ^ a1, a4 ^ a0, b3, b6 ^ b2, b5 ^ b1,
-                                   b4 ^ b0);
-                rm[7] ^= MP_DIGIT(r, 7);
-                rm[6] ^= MP_DIGIT(r, 6);
-                rm[5] ^= MP_DIGIT(r, 5) ^ MP_DIGIT(r, 13);
-                rm[4] ^= MP_DIGIT(r, 4) ^ MP_DIGIT(r, 12);
-                rm[3] ^= MP_DIGIT(r, 3) ^ MP_DIGIT(r, 11);
-                rm[2] ^= MP_DIGIT(r, 2) ^ MP_DIGIT(r, 10);
-                rm[1] ^= MP_DIGIT(r, 1) ^ MP_DIGIT(r, 9);
-                rm[0] ^= MP_DIGIT(r, 0) ^ MP_DIGIT(r, 8);
-                MP_DIGIT(r, 11) ^= rm[7];
-                MP_DIGIT(r, 10) ^= rm[6];
-                MP_DIGIT(r, 9) ^= rm[5];
-                MP_DIGIT(r, 8) ^= rm[4];
-                MP_DIGIT(r, 7) ^= rm[3];
-                MP_DIGIT(r, 6) ^= rm[2];
-                MP_DIGIT(r, 5) ^= rm[1];
-                MP_DIGIT(r, 4) ^= rm[0];
-                MP_USED(r) = 14;
-                s_mp_clamp(r);
-#endif
-                return ec_GF2m_193_mod(r, r, meth);
-        }
-
-  CLEANUP:
-        return res;
-}
-
-/* Wire in fast field arithmetic for 193-bit curves. */
-mp_err
-ec_group_set_gf2m193(ECGroup *group, ECCurveName name)
-{
-        group->meth->field_mod = &ec_GF2m_193_mod;
-        group->meth->field_mul = &ec_GF2m_193_mul;
-        group->meth->field_sqr = &ec_GF2m_193_sqr;
-        return MP_OKAY;
-}
--- a/jdk/src/share/native/sun/security/ec/ec2_233.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,321 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library for binary polynomial field curves.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Sheueling Chang-Shantz <sheueling.chang@sun.com>,
- *   Stephen Fung <fungstep@hotmail.com>, and
- *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories.
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "ec2.h"
-#include "mp_gf2m.h"
-#include "mp_gf2m-priv.h"
-#include "mpi.h"
-#include "mpi-priv.h"
-#ifndef _KERNEL
-#include <stdlib.h>
-#endif
-
-/* Fast reduction for polynomials over a 233-bit curve. Assumes reduction
- * polynomial with terms {233, 74, 0}. */
-mp_err
-ec_GF2m_233_mod(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_digit *u, z;
-
-        if (a != r) {
-                MP_CHECKOK(mp_copy(a, r));
-        }
-#ifdef ECL_SIXTY_FOUR_BIT
-        if (MP_USED(r) < 8) {
-                MP_CHECKOK(s_mp_pad(r, 8));
-        }
-        u = MP_DIGITS(r);
-        MP_USED(r) = 8;
-
-        /* u[7] only has 18 significant bits */
-        z = u[7];
-        u[4] ^= (z << 33) ^ (z >> 41);
-        u[3] ^= (z << 23);
-        z = u[6];
-        u[4] ^= (z >> 31);
-        u[3] ^= (z << 33) ^ (z >> 41);
-        u[2] ^= (z << 23);
-        z = u[5];
-        u[3] ^= (z >> 31);
-        u[2] ^= (z << 33) ^ (z >> 41);
-        u[1] ^= (z << 23);
-        z = u[4];
-        u[2] ^= (z >> 31);
-        u[1] ^= (z << 33) ^ (z >> 41);
-        u[0] ^= (z << 23);
-        z = u[3] >> 41;                         /* z only has 23 significant bits */
-        u[1] ^= (z << 10);
-        u[0] ^= z;
-        /* clear bits above 233 */
-        u[7] = u[6] = u[5] = u[4] = 0;
-        u[3] ^= z << 41;
-#else
-        if (MP_USED(r) < 15) {
-                MP_CHECKOK(s_mp_pad(r, 15));
-        }
-        u = MP_DIGITS(r);
-        MP_USED(r) = 15;
-
-        /* u[14] only has 18 significant bits */
-        z = u[14];
-        u[9] ^= (z << 1);
-        u[7] ^= (z >> 9);
-        u[6] ^= (z << 23);
-        z = u[13];
-        u[9] ^= (z >> 31);
-        u[8] ^= (z << 1);
-        u[6] ^= (z >> 9);
-        u[5] ^= (z << 23);
-        z = u[12];
-        u[8] ^= (z >> 31);
-        u[7] ^= (z << 1);
-        u[5] ^= (z >> 9);
-        u[4] ^= (z << 23);
-        z = u[11];
-        u[7] ^= (z >> 31);
-        u[6] ^= (z << 1);
-        u[4] ^= (z >> 9);
-        u[3] ^= (z << 23);
-        z = u[10];
-        u[6] ^= (z >> 31);
-        u[5] ^= (z << 1);
-        u[3] ^= (z >> 9);
-        u[2] ^= (z << 23);
-        z = u[9];
-        u[5] ^= (z >> 31);
-        u[4] ^= (z << 1);
-        u[2] ^= (z >> 9);
-        u[1] ^= (z << 23);
-        z = u[8];
-        u[4] ^= (z >> 31);
-        u[3] ^= (z << 1);
-        u[1] ^= (z >> 9);
-        u[0] ^= (z << 23);
-        z = u[7] >> 9;                          /* z only has 23 significant bits */
-        u[3] ^= (z >> 22);
-        u[2] ^= (z << 10);
-        u[0] ^= z;
-        /* clear bits above 233 */
-        u[14] = u[13] = u[12] = u[11] = u[10] = u[9] = u[8] = 0;
-        u[7] ^= z << 9;
-#endif
-        s_mp_clamp(r);
-
-  CLEANUP:
-        return res;
-}
-
-/* Fast squaring for polynomials over a 233-bit curve. Assumes reduction
- * polynomial with terms {233, 74, 0}. */
-mp_err
-ec_GF2m_233_sqr(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_digit *u, *v;
-
-        v = MP_DIGITS(a);
-
-#ifdef ECL_SIXTY_FOUR_BIT
-        if (MP_USED(a) < 4) {
-                return mp_bsqrmod(a, meth->irr_arr, r);
-        }
-        if (MP_USED(r) < 8) {
-                MP_CHECKOK(s_mp_pad(r, 8));
-        }
-        MP_USED(r) = 8;
-#else
-        if (MP_USED(a) < 8) {
-                return mp_bsqrmod(a, meth->irr_arr, r);
-        }
-        if (MP_USED(r) < 15) {
-                MP_CHECKOK(s_mp_pad(r, 15));
-        }
-        MP_USED(r) = 15;
-#endif
-        u = MP_DIGITS(r);
-
-#ifdef ECL_THIRTY_TWO_BIT
-        u[14] = gf2m_SQR0(v[7]);
-        u[13] = gf2m_SQR1(v[6]);
-        u[12] = gf2m_SQR0(v[6]);
-        u[11] = gf2m_SQR1(v[5]);
-        u[10] = gf2m_SQR0(v[5]);
-        u[9] = gf2m_SQR1(v[4]);
-        u[8] = gf2m_SQR0(v[4]);
-#endif
-        u[7] = gf2m_SQR1(v[3]);
-        u[6] = gf2m_SQR0(v[3]);
-        u[5] = gf2m_SQR1(v[2]);
-        u[4] = gf2m_SQR0(v[2]);
-        u[3] = gf2m_SQR1(v[1]);
-        u[2] = gf2m_SQR0(v[1]);
-        u[1] = gf2m_SQR1(v[0]);
-        u[0] = gf2m_SQR0(v[0]);
-        return ec_GF2m_233_mod(r, r, meth);
-
-  CLEANUP:
-        return res;
-}
-
-/* Fast multiplication for polynomials over a 233-bit curve. Assumes
- * reduction polynomial with terms {233, 74, 0}. */
-mp_err
-ec_GF2m_233_mul(const mp_int *a, const mp_int *b, mp_int *r,
-                                const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_digit a3 = 0, a2 = 0, a1 = 0, a0, b3 = 0, b2 = 0, b1 = 0, b0;
-
-#ifdef ECL_THIRTY_TWO_BIT
-        mp_digit a7 = 0, a6 = 0, a5 = 0, a4 = 0, b7 = 0, b6 = 0, b5 = 0, b4 =
-                0;
-        mp_digit rm[8];
-#endif
-
-        if (a == b) {
-                return ec_GF2m_233_sqr(a, r, meth);
-        } else {
-                switch (MP_USED(a)) {
-#ifdef ECL_THIRTY_TWO_BIT
-                case 8:
-                        a7 = MP_DIGIT(a, 7);
-                case 7:
-                        a6 = MP_DIGIT(a, 6);
-                case 6:
-                        a5 = MP_DIGIT(a, 5);
-                case 5:
-                        a4 = MP_DIGIT(a, 4);
-#endif
-                case 4:
-                        a3 = MP_DIGIT(a, 3);
-                case 3:
-                        a2 = MP_DIGIT(a, 2);
-                case 2:
-                        a1 = MP_DIGIT(a, 1);
-                default:
-                        a0 = MP_DIGIT(a, 0);
-                }
-                switch (MP_USED(b)) {
-#ifdef ECL_THIRTY_TWO_BIT
-                case 8:
-                        b7 = MP_DIGIT(b, 7);
-                case 7:
-                        b6 = MP_DIGIT(b, 6);
-                case 6:
-                        b5 = MP_DIGIT(b, 5);
-                case 5:
-                        b4 = MP_DIGIT(b, 4);
-#endif
-                case 4:
-                        b3 = MP_DIGIT(b, 3);
-                case 3:
-                        b2 = MP_DIGIT(b, 2);
-                case 2:
-                        b1 = MP_DIGIT(b, 1);
-                default:
-                        b0 = MP_DIGIT(b, 0);
-                }
-#ifdef ECL_SIXTY_FOUR_BIT
-                MP_CHECKOK(s_mp_pad(r, 8));
-                s_bmul_4x4(MP_DIGITS(r), a3, a2, a1, a0, b3, b2, b1, b0);
-                MP_USED(r) = 8;
-                s_mp_clamp(r);
-#else
-                MP_CHECKOK(s_mp_pad(r, 16));
-                s_bmul_4x4(MP_DIGITS(r) + 8, a7, a6, a5, a4, b7, b6, b5, b4);
-                s_bmul_4x4(MP_DIGITS(r), a3, a2, a1, a0, b3, b2, b1, b0);
-                s_bmul_4x4(rm, a7 ^ a3, a6 ^ a2, a5 ^ a1, a4 ^ a0, b7 ^ b3,
-                                   b6 ^ b2, b5 ^ b1, b4 ^ b0);
-                rm[7] ^= MP_DIGIT(r, 7) ^ MP_DIGIT(r, 15);
-                rm[6] ^= MP_DIGIT(r, 6) ^ MP_DIGIT(r, 14);
-                rm[5] ^= MP_DIGIT(r, 5) ^ MP_DIGIT(r, 13);
-                rm[4] ^= MP_DIGIT(r, 4) ^ MP_DIGIT(r, 12);
-                rm[3] ^= MP_DIGIT(r, 3) ^ MP_DIGIT(r, 11);
-                rm[2] ^= MP_DIGIT(r, 2) ^ MP_DIGIT(r, 10);
-                rm[1] ^= MP_DIGIT(r, 1) ^ MP_DIGIT(r, 9);
-                rm[0] ^= MP_DIGIT(r, 0) ^ MP_DIGIT(r, 8);
-                MP_DIGIT(r, 11) ^= rm[7];
-                MP_DIGIT(r, 10) ^= rm[6];
-                MP_DIGIT(r, 9) ^= rm[5];
-                MP_DIGIT(r, 8) ^= rm[4];
-                MP_DIGIT(r, 7) ^= rm[3];
-                MP_DIGIT(r, 6) ^= rm[2];
-                MP_DIGIT(r, 5) ^= rm[1];
-                MP_DIGIT(r, 4) ^= rm[0];
-                MP_USED(r) = 16;
-                s_mp_clamp(r);
-#endif
-                return ec_GF2m_233_mod(r, r, meth);
-        }
-
-  CLEANUP:
-        return res;
-}
-
-/* Wire in fast field arithmetic for 233-bit curves. */
-mp_err
-ec_group_set_gf2m233(ECGroup *group, ECCurveName name)
-{
-        group->meth->field_mod = &ec_GF2m_233_mod;
-        group->meth->field_mul = &ec_GF2m_233_mul;
-        group->meth->field_sqr = &ec_GF2m_233_sqr;
-        return MP_OKAY;
-}
--- a/jdk/src/share/native/sun/security/ec/ec2_aff.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,368 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library for binary polynomial field curves.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "ec2.h"
-#include "mplogic.h"
-#include "mp_gf2m.h"
-#ifndef _KERNEL
-#include <stdlib.h>
-#endif
-
-/* Checks if point P(px, py) is at infinity.  Uses affine coordinates. */
-mp_err
-ec_GF2m_pt_is_inf_aff(const mp_int *px, const mp_int *py)
-{
-
-        if ((mp_cmp_z(px) == 0) && (mp_cmp_z(py) == 0)) {
-                return MP_YES;
-        } else {
-                return MP_NO;
-        }
-
-}
-
-/* Sets P(px, py) to be the point at infinity.  Uses affine coordinates. */
-mp_err
-ec_GF2m_pt_set_inf_aff(mp_int *px, mp_int *py)
-{
-        mp_zero(px);
-        mp_zero(py);
-        return MP_OKAY;
-}
-
-/* Computes R = P + Q based on IEEE P1363 A.10.2. Elliptic curve points P,
- * Q, and R can all be identical. Uses affine coordinates. */
-mp_err
-ec_GF2m_pt_add_aff(const mp_int *px, const mp_int *py, const mp_int *qx,
-                                   const mp_int *qy, mp_int *rx, mp_int *ry,
-                                   const ECGroup *group)
-{
-        mp_err res = MP_OKAY;
-        mp_int lambda, tempx, tempy;
-
-        MP_DIGITS(&lambda) = 0;
-        MP_DIGITS(&tempx) = 0;
-        MP_DIGITS(&tempy) = 0;
-        MP_CHECKOK(mp_init(&lambda, FLAG(px)));
-        MP_CHECKOK(mp_init(&tempx, FLAG(px)));
-        MP_CHECKOK(mp_init(&tempy, FLAG(px)));
-        /* if P = inf, then R = Q */
-        if (ec_GF2m_pt_is_inf_aff(px, py) == 0) {
-                MP_CHECKOK(mp_copy(qx, rx));
-                MP_CHECKOK(mp_copy(qy, ry));
-                res = MP_OKAY;
-                goto CLEANUP;
-        }
-        /* if Q = inf, then R = P */
-        if (ec_GF2m_pt_is_inf_aff(qx, qy) == 0) {
-                MP_CHECKOK(mp_copy(px, rx));
-                MP_CHECKOK(mp_copy(py, ry));
-                res = MP_OKAY;
-                goto CLEANUP;
-        }
-        /* if px != qx, then lambda = (py+qy) / (px+qx), tempx = a + lambda^2
-         * + lambda + px + qx */
-        if (mp_cmp(px, qx) != 0) {
-                MP_CHECKOK(group->meth->field_add(py, qy, &tempy, group->meth));
-                MP_CHECKOK(group->meth->field_add(px, qx, &tempx, group->meth));
-                MP_CHECKOK(group->meth->
-                                   field_div(&tempy, &tempx, &lambda, group->meth));
-                MP_CHECKOK(group->meth->field_sqr(&lambda, &tempx, group->meth));
-                MP_CHECKOK(group->meth->
-                                   field_add(&tempx, &lambda, &tempx, group->meth));
-                MP_CHECKOK(group->meth->
-                                   field_add(&tempx, &group->curvea, &tempx, group->meth));
-                MP_CHECKOK(group->meth->
-                                   field_add(&tempx, px, &tempx, group->meth));
-                MP_CHECKOK(group->meth->
-                                   field_add(&tempx, qx, &tempx, group->meth));
-        } else {
-                /* if py != qy or qx = 0, then R = inf */
-                if (((mp_cmp(py, qy) != 0)) || (mp_cmp_z(qx) == 0)) {
-                        mp_zero(rx);
-                        mp_zero(ry);
-                        res = MP_OKAY;
-                        goto CLEANUP;
-                }
-                /* lambda = qx + qy / qx */
-                MP_CHECKOK(group->meth->field_div(qy, qx, &lambda, group->meth));
-                MP_CHECKOK(group->meth->
-                                   field_add(&lambda, qx, &lambda, group->meth));
-                /* tempx = a + lambda^2 + lambda */
-                MP_CHECKOK(group->meth->field_sqr(&lambda, &tempx, group->meth));
-                MP_CHECKOK(group->meth->
-                                   field_add(&tempx, &lambda, &tempx, group->meth));
-                MP_CHECKOK(group->meth->
-                                   field_add(&tempx, &group->curvea, &tempx, group->meth));
-        }
-        /* ry = (qx + tempx) * lambda + tempx + qy */
-        MP_CHECKOK(group->meth->field_add(qx, &tempx, &tempy, group->meth));
-        MP_CHECKOK(group->meth->
-                           field_mul(&tempy, &lambda, &tempy, group->meth));
-        MP_CHECKOK(group->meth->
-                           field_add(&tempy, &tempx, &tempy, group->meth));
-        MP_CHECKOK(group->meth->field_add(&tempy, qy, ry, group->meth));
-        /* rx = tempx */
-        MP_CHECKOK(mp_copy(&tempx, rx));
-
-  CLEANUP:
-        mp_clear(&lambda);
-        mp_clear(&tempx);
-        mp_clear(&tempy);
-        return res;
-}
-
-/* Computes R = P - Q. Elliptic curve points P, Q, and R can all be
- * identical. Uses affine coordinates. */
-mp_err
-ec_GF2m_pt_sub_aff(const mp_int *px, const mp_int *py, const mp_int *qx,
-                                   const mp_int *qy, mp_int *rx, mp_int *ry,
-                                   const ECGroup *group)
-{
-        mp_err res = MP_OKAY;
-        mp_int nqy;
-
-        MP_DIGITS(&nqy) = 0;
-        MP_CHECKOK(mp_init(&nqy, FLAG(px)));
-        /* nqy = qx+qy */
-        MP_CHECKOK(group->meth->field_add(qx, qy, &nqy, group->meth));
-        MP_CHECKOK(group->point_add(px, py, qx, &nqy, rx, ry, group));
-  CLEANUP:
-        mp_clear(&nqy);
-        return res;
-}
-
-/* Computes R = 2P. Elliptic curve points P and R can be identical. Uses
- * affine coordinates. */
-mp_err
-ec_GF2m_pt_dbl_aff(const mp_int *px, const mp_int *py, mp_int *rx,
-                                   mp_int *ry, const ECGroup *group)
-{
-        return group->point_add(px, py, px, py, rx, ry, group);
-}
-
-/* by default, this routine is unused and thus doesn't need to be compiled */
-#ifdef ECL_ENABLE_GF2M_PT_MUL_AFF
-/* Computes R = nP based on IEEE P1363 A.10.3. Elliptic curve points P and
- * R can be identical. Uses affine coordinates. */
-mp_err
-ec_GF2m_pt_mul_aff(const mp_int *n, const mp_int *px, const mp_int *py,
-                                   mp_int *rx, mp_int *ry, const ECGroup *group)
-{
-        mp_err res = MP_OKAY;
-        mp_int k, k3, qx, qy, sx, sy;
-        int b1, b3, i, l;
-
-        MP_DIGITS(&k) = 0;
-        MP_DIGITS(&k3) = 0;
-        MP_DIGITS(&qx) = 0;
-        MP_DIGITS(&qy) = 0;
-        MP_DIGITS(&sx) = 0;
-        MP_DIGITS(&sy) = 0;
-        MP_CHECKOK(mp_init(&k));
-        MP_CHECKOK(mp_init(&k3));
-        MP_CHECKOK(mp_init(&qx));
-        MP_CHECKOK(mp_init(&qy));
-        MP_CHECKOK(mp_init(&sx));
-        MP_CHECKOK(mp_init(&sy));
-
-        /* if n = 0 then r = inf */
-        if (mp_cmp_z(n) == 0) {
-                mp_zero(rx);
-                mp_zero(ry);
-                res = MP_OKAY;
-                goto CLEANUP;
-        }
-        /* Q = P, k = n */
-        MP_CHECKOK(mp_copy(px, &qx));
-        MP_CHECKOK(mp_copy(py, &qy));
-        MP_CHECKOK(mp_copy(n, &k));
-        /* if n < 0 then Q = -Q, k = -k */
-        if (mp_cmp_z(n) < 0) {
-                MP_CHECKOK(group->meth->field_add(&qx, &qy, &qy, group->meth));
-                MP_CHECKOK(mp_neg(&k, &k));
-        }
-#ifdef ECL_DEBUG                                /* basic double and add method */
-        l = mpl_significant_bits(&k) - 1;
-        MP_CHECKOK(mp_copy(&qx, &sx));
-        MP_CHECKOK(mp_copy(&qy, &sy));
-        for (i = l - 1; i >= 0; i--) {
-                /* S = 2S */
-                MP_CHECKOK(group->point_dbl(&sx, &sy, &sx, &sy, group));
-                /* if k_i = 1, then S = S + Q */
-                if (mpl_get_bit(&k, i) != 0) {
-                        MP_CHECKOK(group->
-                                           point_add(&sx, &sy, &qx, &qy, &sx, &sy, group));
-                }
-        }
-#else                                                   /* double and add/subtract method from
-                                                                 * standard */
-        /* k3 = 3 * k */
-        MP_CHECKOK(mp_set_int(&k3, 3));
-        MP_CHECKOK(mp_mul(&k, &k3, &k3));
-        /* S = Q */
-        MP_CHECKOK(mp_copy(&qx, &sx));
-        MP_CHECKOK(mp_copy(&qy, &sy));
-        /* l = index of high order bit in binary representation of 3*k */
-        l = mpl_significant_bits(&k3) - 1;
-        /* for i = l-1 downto 1 */
-        for (i = l - 1; i >= 1; i--) {
-                /* S = 2S */
-                MP_CHECKOK(group->point_dbl(&sx, &sy, &sx, &sy, group));
-                b3 = MP_GET_BIT(&k3, i);
-                b1 = MP_GET_BIT(&k, i);
-                /* if k3_i = 1 and k_i = 0, then S = S + Q */
-                if ((b3 == 1) && (b1 == 0)) {
-                        MP_CHECKOK(group->
-                                           point_add(&sx, &sy, &qx, &qy, &sx, &sy, group));
-                        /* if k3_i = 0 and k_i = 1, then S = S - Q */
-                } else if ((b3 == 0) && (b1 == 1)) {
-                        MP_CHECKOK(group->
-                                           point_sub(&sx, &sy, &qx, &qy, &sx, &sy, group));
-                }
-        }
-#endif
-        /* output S */
-        MP_CHECKOK(mp_copy(&sx, rx));
-        MP_CHECKOK(mp_copy(&sy, ry));
-
-  CLEANUP:
-        mp_clear(&k);
-        mp_clear(&k3);
-        mp_clear(&qx);
-        mp_clear(&qy);
-        mp_clear(&sx);
-        mp_clear(&sy);
-        return res;
-}
-#endif
-
-/* Validates a point on a GF2m curve. */
-mp_err
-ec_GF2m_validate_point(const mp_int *px, const mp_int *py, const ECGroup *group)
-{
-        mp_err res = MP_NO;
-        mp_int accl, accr, tmp, pxt, pyt;
-
-        MP_DIGITS(&accl) = 0;
-        MP_DIGITS(&accr) = 0;
-        MP_DIGITS(&tmp) = 0;
-        MP_DIGITS(&pxt) = 0;
-        MP_DIGITS(&pyt) = 0;
-        MP_CHECKOK(mp_init(&accl, FLAG(px)));
-        MP_CHECKOK(mp_init(&accr, FLAG(px)));
-        MP_CHECKOK(mp_init(&tmp, FLAG(px)));
-        MP_CHECKOK(mp_init(&pxt, FLAG(px)));
-        MP_CHECKOK(mp_init(&pyt, FLAG(px)));
-
-    /* 1: Verify that publicValue is not the point at infinity */
-        if (ec_GF2m_pt_is_inf_aff(px, py) == MP_YES) {
-                res = MP_NO;
-                goto CLEANUP;
-        }
-    /* 2: Verify that the coordinates of publicValue are elements
-     *    of the field.
-     */
-        if ((MP_SIGN(px) == MP_NEG) || (mp_cmp(px, &group->meth->irr) >= 0) ||
-                (MP_SIGN(py) == MP_NEG) || (mp_cmp(py, &group->meth->irr) >= 0)) {
-                res = MP_NO;
-                goto CLEANUP;
-        }
-    /* 3: Verify that publicValue is on the curve. */
-        if (group->meth->field_enc) {
-                group->meth->field_enc(px, &pxt, group->meth);
-                group->meth->field_enc(py, &pyt, group->meth);
-        } else {
-                mp_copy(px, &pxt);
-                mp_copy(py, &pyt);
-        }
-        /* left-hand side: y^2 + x*y  */
-        MP_CHECKOK( group->meth->field_sqr(&pyt, &accl, group->meth) );
-        MP_CHECKOK( group->meth->field_mul(&pxt, &pyt, &tmp, group->meth) );
-        MP_CHECKOK( group->meth->field_add(&accl, &tmp, &accl, group->meth) );
-        /* right-hand side: x^3 + a*x^2 + b */
-        MP_CHECKOK( group->meth->field_sqr(&pxt, &tmp, group->meth) );
-        MP_CHECKOK( group->meth->field_mul(&pxt, &tmp, &accr, group->meth) );
-        MP_CHECKOK( group->meth->field_mul(&group->curvea, &tmp, &tmp, group->meth) );
-        MP_CHECKOK( group->meth->field_add(&tmp, &accr, &accr, group->meth) );
-        MP_CHECKOK( group->meth->field_add(&accr, &group->curveb, &accr, group->meth) );
-        /* check LHS - RHS == 0 */
-        MP_CHECKOK( group->meth->field_add(&accl, &accr, &accr, group->meth) );
-        if (mp_cmp_z(&accr) != 0) {
-                res = MP_NO;
-                goto CLEANUP;
-        }
-    /* 4: Verify that the order of the curve times the publicValue
-     *    is the point at infinity.
-     */
-        MP_CHECKOK( ECPoint_mul(group, &group->order, px, py, &pxt, &pyt) );
-        if (ec_GF2m_pt_is_inf_aff(&pxt, &pyt) != MP_YES) {
-                res = MP_NO;
-                goto CLEANUP;
-        }
-
-        res = MP_YES;
-
-CLEANUP:
-        mp_clear(&accl);
-        mp_clear(&accr);
-        mp_clear(&tmp);
-        mp_clear(&pxt);
-        mp_clear(&pyt);
-        return res;
-}
--- a/jdk/src/share/native/sun/security/ec/ec2_mont.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,296 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library for binary polynomial field curves.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Sheueling Chang-Shantz <sheueling.chang@sun.com>,
- *   Stephen Fung <fungstep@hotmail.com>, and
- *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories.
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "ec2.h"
-#include "mplogic.h"
-#include "mp_gf2m.h"
-#ifndef _KERNEL
-#include <stdlib.h>
-#endif
-
-/* Compute the x-coordinate x/z for the point 2*(x/z) in Montgomery
- * projective coordinates. Uses algorithm Mdouble in appendix of Lopez, J.
- * and Dahab, R.  "Fast multiplication on elliptic curves over GF(2^m)
- * without precomputation". modified to not require precomputation of
- * c=b^{2^{m-1}}. */
-static mp_err
-gf2m_Mdouble(mp_int *x, mp_int *z, const ECGroup *group, int kmflag)
-{
-        mp_err res = MP_OKAY;
-        mp_int t1;
-
-        MP_DIGITS(&t1) = 0;
-        MP_CHECKOK(mp_init(&t1, kmflag));
-
-        MP_CHECKOK(group->meth->field_sqr(x, x, group->meth));
-        MP_CHECKOK(group->meth->field_sqr(z, &t1, group->meth));
-        MP_CHECKOK(group->meth->field_mul(x, &t1, z, group->meth));
-        MP_CHECKOK(group->meth->field_sqr(x, x, group->meth));
-        MP_CHECKOK(group->meth->field_sqr(&t1, &t1, group->meth));
-        MP_CHECKOK(group->meth->
-                           field_mul(&group->curveb, &t1, &t1, group->meth));
-        MP_CHECKOK(group->meth->field_add(x, &t1, x, group->meth));
-
-  CLEANUP:
-        mp_clear(&t1);
-        return res;
-}
-
-/* Compute the x-coordinate x1/z1 for the point (x1/z1)+(x2/x2) in
- * Montgomery projective coordinates. Uses algorithm Madd in appendix of
- * Lopex, J. and Dahab, R.  "Fast multiplication on elliptic curves over
- * GF(2^m) without precomputation". */
-static mp_err
-gf2m_Madd(const mp_int *x, mp_int *x1, mp_int *z1, mp_int *x2, mp_int *z2,
-                  const ECGroup *group, int kmflag)
-{
-        mp_err res = MP_OKAY;
-        mp_int t1, t2;
-
-        MP_DIGITS(&t1) = 0;
-        MP_DIGITS(&t2) = 0;
-        MP_CHECKOK(mp_init(&t1, kmflag));
-        MP_CHECKOK(mp_init(&t2, kmflag));
-
-        MP_CHECKOK(mp_copy(x, &t1));
-        MP_CHECKOK(group->meth->field_mul(x1, z2, x1, group->meth));
-        MP_CHECKOK(group->meth->field_mul(z1, x2, z1, group->meth));
-        MP_CHECKOK(group->meth->field_mul(x1, z1, &t2, group->meth));
-        MP_CHECKOK(group->meth->field_add(z1, x1, z1, group->meth));
-        MP_CHECKOK(group->meth->field_sqr(z1, z1, group->meth));
-        MP_CHECKOK(group->meth->field_mul(z1, &t1, x1, group->meth));
-        MP_CHECKOK(group->meth->field_add(x1, &t2, x1, group->meth));
-
-  CLEANUP:
-        mp_clear(&t1);
-        mp_clear(&t2);
-        return res;
-}
-
-/* Compute the x, y affine coordinates from the point (x1, z1) (x2, z2)
- * using Montgomery point multiplication algorithm Mxy() in appendix of
- * Lopex, J. and Dahab, R.  "Fast multiplication on elliptic curves over
- * GF(2^m) without precomputation". Returns: 0 on error 1 if return value
- * should be the point at infinity 2 otherwise */
-static int
-gf2m_Mxy(const mp_int *x, const mp_int *y, mp_int *x1, mp_int *z1,
-                 mp_int *x2, mp_int *z2, const ECGroup *group)
-{
-        mp_err res = MP_OKAY;
-        int ret = 0;
-        mp_int t3, t4, t5;
-
-        MP_DIGITS(&t3) = 0;
-        MP_DIGITS(&t4) = 0;
-        MP_DIGITS(&t5) = 0;
-        MP_CHECKOK(mp_init(&t3, FLAG(x2)));
-        MP_CHECKOK(mp_init(&t4, FLAG(x2)));
-        MP_CHECKOK(mp_init(&t5, FLAG(x2)));
-
-        if (mp_cmp_z(z1) == 0) {
-                mp_zero(x2);
-                mp_zero(z2);
-                ret = 1;
-                goto CLEANUP;
-        }
-
-        if (mp_cmp_z(z2) == 0) {
-                MP_CHECKOK(mp_copy(x, x2));
-                MP_CHECKOK(group->meth->field_add(x, y, z2, group->meth));
-                ret = 2;
-                goto CLEANUP;
-        }
-
-        MP_CHECKOK(mp_set_int(&t5, 1));
-        if (group->meth->field_enc) {
-                MP_CHECKOK(group->meth->field_enc(&t5, &t5, group->meth));
-        }
-
-        MP_CHECKOK(group->meth->field_mul(z1, z2, &t3, group->meth));
-
-        MP_CHECKOK(group->meth->field_mul(z1, x, z1, group->meth));
-        MP_CHECKOK(group->meth->field_add(z1, x1, z1, group->meth));
-        MP_CHECKOK(group->meth->field_mul(z2, x, z2, group->meth));
-        MP_CHECKOK(group->meth->field_mul(z2, x1, x1, group->meth));
-        MP_CHECKOK(group->meth->field_add(z2, x2, z2, group->meth));
-
-        MP_CHECKOK(group->meth->field_mul(z2, z1, z2, group->meth));
-        MP_CHECKOK(group->meth->field_sqr(x, &t4, group->meth));
-        MP_CHECKOK(group->meth->field_add(&t4, y, &t4, group->meth));
-        MP_CHECKOK(group->meth->field_mul(&t4, &t3, &t4, group->meth));
-        MP_CHECKOK(group->meth->field_add(&t4, z2, &t4, group->meth));
-
-        MP_CHECKOK(group->meth->field_mul(&t3, x, &t3, group->meth));
-        MP_CHECKOK(group->meth->field_div(&t5, &t3, &t3, group->meth));
-        MP_CHECKOK(group->meth->field_mul(&t3, &t4, &t4, group->meth));
-        MP_CHECKOK(group->meth->field_mul(x1, &t3, x2, group->meth));
-        MP_CHECKOK(group->meth->field_add(x2, x, z2, group->meth));
-
-        MP_CHECKOK(group->meth->field_mul(z2, &t4, z2, group->meth));
-        MP_CHECKOK(group->meth->field_add(z2, y, z2, group->meth));
-
-        ret = 2;
-
-  CLEANUP:
-        mp_clear(&t3);
-        mp_clear(&t4);
-        mp_clear(&t5);
-        if (res == MP_OKAY) {
-                return ret;
-        } else {
-                return 0;
-        }
-}
-
-/* Computes R = nP based on algorithm 2P of Lopex, J. and Dahab, R.  "Fast
- * multiplication on elliptic curves over GF(2^m) without
- * precomputation". Elliptic curve points P and R can be identical. Uses
- * Montgomery projective coordinates. */
-mp_err
-ec_GF2m_pt_mul_mont(const mp_int *n, const mp_int *px, const mp_int *py,
-                                        mp_int *rx, mp_int *ry, const ECGroup *group)
-{
-        mp_err res = MP_OKAY;
-        mp_int x1, x2, z1, z2;
-        int i, j;
-        mp_digit top_bit, mask;
-
-        MP_DIGITS(&x1) = 0;
-        MP_DIGITS(&x2) = 0;
-        MP_DIGITS(&z1) = 0;
-        MP_DIGITS(&z2) = 0;
-        MP_CHECKOK(mp_init(&x1, FLAG(n)));
-        MP_CHECKOK(mp_init(&x2, FLAG(n)));
-        MP_CHECKOK(mp_init(&z1, FLAG(n)));
-        MP_CHECKOK(mp_init(&z2, FLAG(n)));
-
-        /* if result should be point at infinity */
-        if ((mp_cmp_z(n) == 0) || (ec_GF2m_pt_is_inf_aff(px, py) == MP_YES)) {
-                MP_CHECKOK(ec_GF2m_pt_set_inf_aff(rx, ry));
-                goto CLEANUP;
-        }
-
-        MP_CHECKOK(mp_copy(px, &x1));   /* x1 = px */
-        MP_CHECKOK(mp_set_int(&z1, 1)); /* z1 = 1 */
-        MP_CHECKOK(group->meth->field_sqr(&x1, &z2, group->meth));      /* z2 =
-                                                                                                                                 * x1^2 =
-                                                                                                                                 * px^2 */
-        MP_CHECKOK(group->meth->field_sqr(&z2, &x2, group->meth));
-        MP_CHECKOK(group->meth->field_add(&x2, &group->curveb, &x2, group->meth));      /* x2
-                                                                                                                                                                 * =
-                                                                                                                                                                 * px^4
-                                                                                                                                                                 * +
-                                                                                                                                                                 * b
-                                                                                                                                                                 */
-
-        /* find top-most bit and go one past it */
-        i = MP_USED(n) - 1;
-        j = MP_DIGIT_BIT - 1;
-        top_bit = 1;
-        top_bit <<= MP_DIGIT_BIT - 1;
-        mask = top_bit;
-        while (!(MP_DIGITS(n)[i] & mask)) {
-                mask >>= 1;
-                j--;
-        }
-        mask >>= 1;
-        j--;
-
-        /* if top most bit was at word break, go to next word */
-        if (!mask) {
-                i--;
-                j = MP_DIGIT_BIT - 1;
-                mask = top_bit;
-        }
-
-        for (; i >= 0; i--) {
-                for (; j >= 0; j--) {
-                        if (MP_DIGITS(n)[i] & mask) {
-                                MP_CHECKOK(gf2m_Madd(px, &x1, &z1, &x2, &z2, group, FLAG(n)));
-                                MP_CHECKOK(gf2m_Mdouble(&x2, &z2, group, FLAG(n)));
-                        } else {
-                                MP_CHECKOK(gf2m_Madd(px, &x2, &z2, &x1, &z1, group, FLAG(n)));
-                                MP_CHECKOK(gf2m_Mdouble(&x1, &z1, group, FLAG(n)));
-                        }
-                        mask >>= 1;
-                }
-                j = MP_DIGIT_BIT - 1;
-                mask = top_bit;
-        }
-
-        /* convert out of "projective" coordinates */
-        i = gf2m_Mxy(px, py, &x1, &z1, &x2, &z2, group);
-        if (i == 0) {
-                res = MP_BADARG;
-                goto CLEANUP;
-        } else if (i == 1) {
-                MP_CHECKOK(ec_GF2m_pt_set_inf_aff(rx, ry));
-        } else {
-                MP_CHECKOK(mp_copy(&x2, rx));
-                MP_CHECKOK(mp_copy(&z2, ry));
-        }
-
-  CLEANUP:
-        mp_clear(&x1);
-        mp_clear(&x2);
-        mp_clear(&z1);
-        mp_clear(&z2);
-        return res;
-}
--- a/jdk/src/share/native/sun/security/ec/ec_naf.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,123 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Stephen Fung <fungstep@hotmail.com>, Sun Microsystems Laboratories
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "ecl-priv.h"
-
-/* Returns 2^e as an integer. This is meant to be used for small powers of
- * two. */
-int
-ec_twoTo(int e)
-{
-        int a = 1;
-        int i;
-
-        for (i = 0; i < e; i++) {
-                a *= 2;
-        }
-        return a;
-}
-
-/* Computes the windowed non-adjacent-form (NAF) of a scalar. Out should
- * be an array of signed char's to output to, bitsize should be the number
- * of bits of out, in is the original scalar, and w is the window size.
- * NAF is discussed in the paper: D. Hankerson, J. Hernandez and A.
- * Menezes, "Software implementation of elliptic curve cryptography over
- * binary fields", Proc. CHES 2000. */
-mp_err
-ec_compute_wNAF(signed char *out, int bitsize, const mp_int *in, int w)
-{
-        mp_int k;
-        mp_err res = MP_OKAY;
-        int i, twowm1, mask;
-
-        twowm1 = ec_twoTo(w - 1);
-        mask = 2 * twowm1 - 1;
-
-        MP_DIGITS(&k) = 0;
-        MP_CHECKOK(mp_init_copy(&k, in));
-
-        i = 0;
-        /* Compute wNAF form */
-        while (mp_cmp_z(&k) > 0) {
-                if (mp_isodd(&k)) {
-                        out[i] = MP_DIGIT(&k, 0) & mask;
-                        if (out[i] >= twowm1)
-                                out[i] -= 2 * twowm1;
-
-                        /* Subtract off out[i].  Note mp_sub_d only works with
-                         * unsigned digits */
-                        if (out[i] >= 0) {
-                                mp_sub_d(&k, out[i], &k);
-                        } else {
-                                mp_add_d(&k, -(out[i]), &k);
-                        }
-                } else {
-                        out[i] = 0;
-                }
-                mp_div_2(&k, &k);
-                i++;
-        }
-        /* Zero out the remaining elements of the out array. */
-        for (; i < bitsize + 1; i++) {
-                out[i] = 0;
-        }
-  CLEANUP:
-        mp_clear(&k);
-        return res;
-
-}
--- a/jdk/src/share/native/sun/security/ec/ecc_impl.h	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,278 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Netscape security libraries.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1994-2000
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Dr Vipul Gupta <vipul.gupta@sun.com> and
- *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _ECC_IMPL_H
-#define _ECC_IMPL_H
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <sys/types.h>
-#include "ecl-exp.h"
-
-/*
- * Multi-platform definitions
- */
-#ifdef __linux__
-#define B_FALSE FALSE
-#define B_TRUE TRUE
-typedef unsigned char uint8_t;
-typedef unsigned long ulong_t;
-typedef enum { B_FALSE, B_TRUE } boolean_t;
-#endif /* __linux__ */
-
-#ifdef _WIN32
-typedef unsigned char uint8_t;
-typedef unsigned long ulong_t;
-typedef enum boolean { B_FALSE, B_TRUE } boolean_t;
-#endif /* _WIN32 */
-
-#ifndef _KERNEL
-#include <stdlib.h>
-#endif  /* _KERNEL */
-
-#define EC_MAX_DIGEST_LEN 1024  /* max digest that can be signed */
-#define EC_MAX_POINT_LEN 145    /* max len of DER encoded Q */
-#define EC_MAX_VALUE_LEN 72     /* max len of ANSI X9.62 private value d */
-#define EC_MAX_SIG_LEN 144      /* max signature len for supported curves */
-#define EC_MIN_KEY_LEN  112     /* min key length in bits */
-#define EC_MAX_KEY_LEN  571     /* max key length in bits */
-#define EC_MAX_OID_LEN 10       /* max length of OID buffer */
-
-/*
- * Various structures and definitions from NSS are here.
- */
-
-#ifdef _KERNEL
-#define PORT_ArenaAlloc(a, n, f)        kmem_alloc((n), (f))
-#define PORT_ArenaZAlloc(a, n, f)       kmem_zalloc((n), (f))
-#define PORT_ArenaGrow(a, b, c, d)      NULL
-#define PORT_ZAlloc(n, f)               kmem_zalloc((n), (f))
-#define PORT_Alloc(n, f)                kmem_alloc((n), (f))
-#else
-#define PORT_ArenaAlloc(a, n, f)        malloc((n))
-#define PORT_ArenaZAlloc(a, n, f)       calloc(1, (n))
-#define PORT_ArenaGrow(a, b, c, d)      NULL
-#define PORT_ZAlloc(n, f)               calloc(1, (n))
-#define PORT_Alloc(n, f)                malloc((n))
-#endif
-
-#define PORT_NewArena(b)                (char *)12345
-#define PORT_ArenaMark(a)               NULL
-#define PORT_ArenaUnmark(a, b)
-#define PORT_ArenaRelease(a, m)
-#define PORT_FreeArena(a, b)
-#define PORT_Strlen(s)                  strlen((s))
-#define PORT_SetError(e)
-
-#define PRBool                          boolean_t
-#define PR_TRUE                         B_TRUE
-#define PR_FALSE                        B_FALSE
-
-#ifdef _KERNEL
-#define PORT_Assert                     ASSERT
-#define PORT_Memcpy(t, f, l)            bcopy((f), (t), (l))
-#else
-#define PORT_Assert                     assert
-#define PORT_Memcpy(t, f, l)            memcpy((t), (f), (l))
-#endif
-
-#define CHECK_OK(func) if (func == NULL) goto cleanup
-#define CHECK_SEC_OK(func) if (SECSuccess != (rv = func)) goto cleanup
-
-typedef enum {
-        siBuffer = 0,
-        siClearDataBuffer = 1,
-        siCipherDataBuffer = 2,
-        siDERCertBuffer = 3,
-        siEncodedCertBuffer = 4,
-        siDERNameBuffer = 5,
-        siEncodedNameBuffer = 6,
-        siAsciiNameString = 7,
-        siAsciiString = 8,
-        siDEROID = 9,
-        siUnsignedInteger = 10,
-        siUTCTime = 11,
-        siGeneralizedTime = 12
-} SECItemType;
-
-typedef struct SECItemStr SECItem;
-
-struct SECItemStr {
-        SECItemType type;
-        unsigned char *data;
-        unsigned int len;
-};
-
-typedef SECItem SECKEYECParams;
-
-typedef enum { ec_params_explicit,
-               ec_params_named
-} ECParamsType;
-
-typedef enum { ec_field_GFp = 1,
-               ec_field_GF2m
-} ECFieldType;
-
-struct ECFieldIDStr {
-    int         size;   /* field size in bits */
-    ECFieldType type;
-    union {
-        SECItem  prime; /* prime p for (GFp) */
-        SECItem  poly;  /* irreducible binary polynomial for (GF2m) */
-    } u;
-    int         k1;     /* first coefficient of pentanomial or
-                         * the only coefficient of trinomial
-                         */
-    int         k2;     /* two remaining coefficients of pentanomial */
-    int         k3;
-};
-typedef struct ECFieldIDStr ECFieldID;
-
-struct ECCurveStr {
-        SECItem a;      /* contains octet stream encoding of
-                         * field element (X9.62 section 4.3.3)
-                         */
-        SECItem b;
-        SECItem seed;
-};
-typedef struct ECCurveStr ECCurve;
-
-typedef void PRArenaPool;
-
-struct ECParamsStr {
-    PRArenaPool * arena;
-    ECParamsType  type;
-    ECFieldID     fieldID;
-    ECCurve       curve;
-    SECItem       base;
-    SECItem       order;
-    int           cofactor;
-    SECItem       DEREncoding;
-    ECCurveName   name;
-    SECItem       curveOID;
-};
-typedef struct ECParamsStr ECParams;
-
-struct ECPublicKeyStr {
-    ECParams ecParams;
-    SECItem publicValue;   /* elliptic curve point encoded as
-                            * octet stream.
-                            */
-};
-typedef struct ECPublicKeyStr ECPublicKey;
-
-struct ECPrivateKeyStr {
-    ECParams ecParams;
-    SECItem publicValue;   /* encoded ec point */
-    SECItem privateValue;  /* private big integer */
-    SECItem version;       /* As per SEC 1, Appendix C, Section C.4 */
-};
-typedef struct ECPrivateKeyStr ECPrivateKey;
-
-typedef enum _SECStatus {
-        SECBufferTooSmall = -3,
-        SECWouldBlock = -2,
-        SECFailure = -1,
-        SECSuccess = 0
-} SECStatus;
-
-#ifdef _KERNEL
-#define RNG_GenerateGlobalRandomBytes(p,l) ecc_knzero_random_generator((p), (l))
-#else
-/*
- This function is no longer required because the random bytes are now
- supplied by the caller. Force a failure.
-VR
-#define RNG_GenerateGlobalRandomBytes(p,l) SECFailure
-*/
-#define RNG_GenerateGlobalRandomBytes(p,l) SECSuccess
-#endif
-#define CHECK_MPI_OK(func) if (MP_OKAY > (err = func)) goto cleanup
-#define MP_TO_SEC_ERROR(err)
-
-#define SECITEM_TO_MPINT(it, mp)                                        \
-        CHECK_MPI_OK(mp_read_unsigned_octets((mp), (it).data, (it).len))
-
-extern int ecc_knzero_random_generator(uint8_t *, size_t);
-extern ulong_t soft_nzero_random_generator(uint8_t *, ulong_t);
-
-extern SECStatus EC_DecodeParams(const SECItem *, ECParams **, int);
-extern SECItem * SECITEM_AllocItem(PRArenaPool *, SECItem *, unsigned int, int);
-extern SECStatus SECITEM_CopyItem(PRArenaPool *, SECItem *, const SECItem *,
-    int);
-extern void SECITEM_FreeItem(SECItem *, boolean_t);
-extern SECStatus EC_NewKey(ECParams *ecParams, ECPrivateKey **privKey, const unsigned char* random, int randomlen, int);
-extern SECStatus EC_NewKeyFromSeed(ECParams *ecParams, ECPrivateKey **privKey,
-    const unsigned char *seed, int seedlen, int kmflag);
-extern SECStatus ECDSA_SignDigest(ECPrivateKey *, SECItem *, const SECItem *,
-    const unsigned char* randon, int randomlen, int);
-extern SECStatus ECDSA_SignDigestWithSeed(ECPrivateKey *, SECItem *,
-    const SECItem *, const unsigned char *seed, int seedlen, int kmflag);
-extern SECStatus ECDSA_VerifyDigest(ECPublicKey *, const SECItem *,
-    const SECItem *, int);
-extern SECStatus ECDH_Derive(SECItem *, ECParams *, SECItem *, boolean_t,
-    SECItem *, int);
-
-#ifdef  __cplusplus
-}
-#endif
-
-#endif /* _ECC_IMPL_H */
--- a/jdk/src/share/native/sun/security/ec/ecdecode.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,632 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Elliptic Curve Cryptography library.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Dr Vipul Gupta <vipul.gupta@sun.com> and
- *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include <sys/types.h>
-
-#ifndef _WIN32
-#ifndef __linux__
-#include <sys/systm.h>
-#endif /* __linux__ */
-#include <sys/param.h>
-#endif /* _WIN32 */
-
-#ifdef _KERNEL
-#include <sys/kmem.h>
-#else
-#include <string.h>
-#endif
-#include "ec.h"
-#include "ecl-curve.h"
-#include "ecc_impl.h"
-
-#define MAX_ECKEY_LEN           72
-#define SEC_ASN1_OBJECT_ID      0x06
-
-/*
- * Initializes a SECItem from a hexadecimal string
- *
- * Warning: This function ignores leading 00's, so any leading 00's
- * in the hexadecimal string must be optional.
- */
-static SECItem *
-hexString2SECItem(PRArenaPool *arena, SECItem *item, const char *str,
-    int kmflag)
-{
-    int i = 0;
-    int byteval = 0;
-    int tmp = strlen(str);
-
-    if ((tmp % 2) != 0) return NULL;
-
-    /* skip leading 00's unless the hex string is "00" */
-    while ((tmp > 2) && (str[0] == '0') && (str[1] == '0')) {
-        str += 2;
-        tmp -= 2;
-    }
-
-    item->data = (unsigned char *) PORT_ArenaAlloc(arena, tmp/2, kmflag);
-    if (item->data == NULL) return NULL;
-    item->len = tmp/2;
-
-    while (str[i]) {
-        if ((str[i] >= '0') && (str[i] <= '9'))
-            tmp = str[i] - '0';
-        else if ((str[i] >= 'a') && (str[i] <= 'f'))
-            tmp = str[i] - 'a' + 10;
-        else if ((str[i] >= 'A') && (str[i] <= 'F'))
-            tmp = str[i] - 'A' + 10;
-        else
-            return NULL;
-
-        byteval = byteval * 16 + tmp;
-        if ((i % 2) != 0) {
-            item->data[i/2] = byteval;
-            byteval = 0;
-        }
-        i++;
-    }
-
-    return item;
-}
-
-static SECStatus
-gf_populate_params(ECCurveName name, ECFieldType field_type, ECParams *params,
-    int kmflag)
-{
-    SECStatus rv = SECFailure;
-    const ECCurveParams *curveParams;
-    /* 2 ['0'+'4'] + MAX_ECKEY_LEN * 2 [x,y] * 2 [hex string] + 1 ['\0'] */
-    char genenc[3 + 2 * 2 * MAX_ECKEY_LEN];
-
-    if ((name < ECCurve_noName) || (name > ECCurve_pastLastCurve)) goto cleanup;
-    params->name = name;
-    curveParams = ecCurve_map[params->name];
-    CHECK_OK(curveParams);
-    params->fieldID.size = curveParams->size;
-    params->fieldID.type = field_type;
-    if (field_type == ec_field_GFp) {
-        CHECK_OK(hexString2SECItem(NULL, &params->fieldID.u.prime,
-            curveParams->irr, kmflag));
-    } else {
-        CHECK_OK(hexString2SECItem(NULL, &params->fieldID.u.poly,
-            curveParams->irr, kmflag));
-    }
-    CHECK_OK(hexString2SECItem(NULL, &params->curve.a,
-        curveParams->curvea, kmflag));
-    CHECK_OK(hexString2SECItem(NULL, &params->curve.b,
-        curveParams->curveb, kmflag));
-    genenc[0] = '0';
-    genenc[1] = '4';
-    genenc[2] = '\0';
-    strcat(genenc, curveParams->genx);
-    strcat(genenc, curveParams->geny);
-    CHECK_OK(hexString2SECItem(NULL, &params->base, genenc, kmflag));
-    CHECK_OK(hexString2SECItem(NULL, &params->order,
-        curveParams->order, kmflag));
-    params->cofactor = curveParams->cofactor;
-
-    rv = SECSuccess;
-
-cleanup:
-    return rv;
-}
-
-ECCurveName SECOID_FindOIDTag(const SECItem *);
-
-SECStatus
-EC_FillParams(PRArenaPool *arena, const SECItem *encodedParams,
-    ECParams *params, int kmflag)
-{
-    SECStatus rv = SECFailure;
-    ECCurveName tag;
-    SECItem oid = { siBuffer, NULL, 0};
-
-#if EC_DEBUG
-    int i;
-
-    printf("Encoded params in EC_DecodeParams: ");
-    for (i = 0; i < encodedParams->len; i++) {
-            printf("%02x:", encodedParams->data[i]);
-    }
-    printf("\n");
-#endif
-
-    if ((encodedParams->len != ANSI_X962_CURVE_OID_TOTAL_LEN) &&
-        (encodedParams->len != SECG_CURVE_OID_TOTAL_LEN)) {
-            PORT_SetError(SEC_ERROR_UNSUPPORTED_ELLIPTIC_CURVE);
-            return SECFailure;
-    };
-
-    oid.len = encodedParams->len - 2;
-    oid.data = encodedParams->data + 2;
-    if ((encodedParams->data[0] != SEC_ASN1_OBJECT_ID) ||
-        ((tag = SECOID_FindOIDTag(&oid)) == ECCurve_noName)) {
-            PORT_SetError(SEC_ERROR_UNSUPPORTED_ELLIPTIC_CURVE);
-            return SECFailure;
-    }
-
-    params->arena = arena;
-    params->cofactor = 0;
-    params->type = ec_params_named;
-    params->name = ECCurve_noName;
-
-    /* For named curves, fill out curveOID */
-    params->curveOID.len = oid.len;
-    params->curveOID.data = (unsigned char *) PORT_ArenaAlloc(NULL, oid.len,
-        kmflag);
-    if (params->curveOID.data == NULL) goto cleanup;
-    memcpy(params->curveOID.data, oid.data, oid.len);
-
-#if EC_DEBUG
-#ifndef SECOID_FindOIDTagDescription
-    printf("Curve: %s\n", ecCurve_map[tag]->text);
-#else
-    printf("Curve: %s\n", SECOID_FindOIDTagDescription(tag));
-#endif
-#endif
-
-    switch (tag) {
-
-    /* Binary curves */
-
-    case ECCurve_X9_62_CHAR2_PNB163V1:
-        /* Populate params for c2pnb163v1 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_PNB163V1, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_X9_62_CHAR2_PNB163V2:
-        /* Populate params for c2pnb163v2 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_PNB163V2, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_X9_62_CHAR2_PNB163V3:
-        /* Populate params for c2pnb163v3 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_PNB163V3, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_X9_62_CHAR2_PNB176V1:
-        /* Populate params for c2pnb176v1 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_PNB176V1, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_X9_62_CHAR2_TNB191V1:
-        /* Populate params for c2tnb191v1 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_TNB191V1, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_X9_62_CHAR2_TNB191V2:
-        /* Populate params for c2tnb191v2 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_TNB191V2, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_X9_62_CHAR2_TNB191V3:
-        /* Populate params for c2tnb191v3 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_TNB191V3, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_X9_62_CHAR2_PNB208W1:
-        /* Populate params for c2pnb208w1 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_PNB208W1, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_X9_62_CHAR2_TNB239V1:
-        /* Populate params for c2tnb239v1 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_TNB239V1, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_X9_62_CHAR2_TNB239V2:
-        /* Populate params for c2tnb239v2 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_TNB239V2, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_X9_62_CHAR2_TNB239V3:
-        /* Populate params for c2tnb239v3 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_TNB239V3, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_X9_62_CHAR2_PNB272W1:
-        /* Populate params for c2pnb272w1 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_PNB272W1, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_X9_62_CHAR2_PNB304W1:
-        /* Populate params for c2pnb304w1 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_PNB304W1, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_X9_62_CHAR2_TNB359V1:
-        /* Populate params for c2tnb359v1 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_TNB359V1, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_X9_62_CHAR2_PNB368W1:
-        /* Populate params for c2pnb368w1 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_PNB368W1, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_X9_62_CHAR2_TNB431R1:
-        /* Populate params for c2tnb431r1 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_TNB431R1, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_CHAR2_113R1:
-        /* Populate params for sect113r1 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_113R1, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_CHAR2_113R2:
-        /* Populate params for sect113r2 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_113R2, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_CHAR2_131R1:
-        /* Populate params for sect131r1 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_131R1, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_CHAR2_131R2:
-        /* Populate params for sect131r2 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_131R2, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_CHAR2_163K1:
-        /* Populate params for sect163k1
-         * (the NIST K-163 curve)
-         */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_163K1, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_CHAR2_163R1:
-        /* Populate params for sect163r1 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_163R1, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_CHAR2_163R2:
-        /* Populate params for sect163r2
-         * (the NIST B-163 curve)
-         */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_163R2, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_CHAR2_193R1:
-        /* Populate params for sect193r1 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_193R1, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_CHAR2_193R2:
-        /* Populate params for sect193r2 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_193R2, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_CHAR2_233K1:
-        /* Populate params for sect233k1
-         * (the NIST K-233 curve)
-         */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_233K1, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_CHAR2_233R1:
-        /* Populate params for sect233r1
-         * (the NIST B-233 curve)
-         */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_233R1, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_CHAR2_239K1:
-        /* Populate params for sect239k1 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_239K1, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_CHAR2_283K1:
-        /* Populate params for sect283k1
-         * (the NIST K-283 curve)
-         */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_283K1, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_CHAR2_283R1:
-        /* Populate params for sect283r1
-         * (the NIST B-283 curve)
-         */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_283R1, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_CHAR2_409K1:
-        /* Populate params for sect409k1
-         * (the NIST K-409 curve)
-         */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_409K1, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_CHAR2_409R1:
-        /* Populate params for sect409r1
-         * (the NIST B-409 curve)
-         */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_409R1, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_CHAR2_571K1:
-        /* Populate params for sect571k1
-         * (the NIST K-571 curve)
-         */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_571K1, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_CHAR2_571R1:
-        /* Populate params for sect571r1
-         * (the NIST B-571 curve)
-         */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_571R1, ec_field_GF2m,
-            params, kmflag) );
-        break;
-
-    /* Prime curves */
-
-    case ECCurve_X9_62_PRIME_192V1:
-        /* Populate params for prime192v1 aka secp192r1
-         * (the NIST P-192 curve)
-         */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_PRIME_192V1, ec_field_GFp,
-            params, kmflag) );
-        break;
-
-    case ECCurve_X9_62_PRIME_192V2:
-        /* Populate params for prime192v2 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_PRIME_192V2, ec_field_GFp,
-            params, kmflag) );
-        break;
-
-    case ECCurve_X9_62_PRIME_192V3:
-        /* Populate params for prime192v3 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_PRIME_192V3, ec_field_GFp,
-            params, kmflag) );
-        break;
-
-    case ECCurve_X9_62_PRIME_239V1:
-        /* Populate params for prime239v1 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_PRIME_239V1, ec_field_GFp,
-            params, kmflag) );
-        break;
-
-    case ECCurve_X9_62_PRIME_239V2:
-        /* Populate params for prime239v2 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_PRIME_239V2, ec_field_GFp,
-            params, kmflag) );
-        break;
-
-    case ECCurve_X9_62_PRIME_239V3:
-        /* Populate params for prime239v3 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_PRIME_239V3, ec_field_GFp,
-            params, kmflag) );
-        break;
-
-    case ECCurve_X9_62_PRIME_256V1:
-        /* Populate params for prime256v1 aka secp256r1
-         * (the NIST P-256 curve)
-         */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_PRIME_256V1, ec_field_GFp,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_PRIME_112R1:
-        /* Populate params for secp112r1 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_112R1, ec_field_GFp,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_PRIME_112R2:
-        /* Populate params for secp112r2 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_112R2, ec_field_GFp,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_PRIME_128R1:
-        /* Populate params for secp128r1 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_128R1, ec_field_GFp,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_PRIME_128R2:
-        /* Populate params for secp128r2 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_128R2, ec_field_GFp,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_PRIME_160K1:
-        /* Populate params for secp160k1 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_160K1, ec_field_GFp,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_PRIME_160R1:
-        /* Populate params for secp160r1 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_160R1, ec_field_GFp,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_PRIME_160R2:
-        /* Populate params for secp160r1 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_160R2, ec_field_GFp,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_PRIME_192K1:
-        /* Populate params for secp192k1 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_192K1, ec_field_GFp,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_PRIME_224K1:
-        /* Populate params for secp224k1 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_224K1, ec_field_GFp,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_PRIME_224R1:
-        /* Populate params for secp224r1
-         * (the NIST P-224 curve)
-         */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_224R1, ec_field_GFp,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_PRIME_256K1:
-        /* Populate params for secp256k1 */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_256K1, ec_field_GFp,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_PRIME_384R1:
-        /* Populate params for secp384r1
-         * (the NIST P-384 curve)
-         */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_384R1, ec_field_GFp,
-            params, kmflag) );
-        break;
-
-    case ECCurve_SECG_PRIME_521R1:
-        /* Populate params for secp521r1
-         * (the NIST P-521 curve)
-         */
-        CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_521R1, ec_field_GFp,
-            params, kmflag) );
-        break;
-
-    default:
-        break;
-    };
-
-cleanup:
-    if (!params->cofactor) {
-        PORT_SetError(SEC_ERROR_UNSUPPORTED_ELLIPTIC_CURVE);
-#if EC_DEBUG
-        printf("Unrecognized curve, returning NULL params\n");
-#endif
-    }
-
-    return rv;
-}
-
-SECStatus
-EC_DecodeParams(const SECItem *encodedParams, ECParams **ecparams, int kmflag)
-{
-    PRArenaPool *arena;
-    ECParams *params;
-    SECStatus rv = SECFailure;
-
-    /* Initialize an arena for the ECParams structure */
-    if (!(arena = PORT_NewArena(NSS_FREEBL_DEFAULT_CHUNKSIZE)))
-        return SECFailure;
-
-    params = (ECParams *)PORT_ArenaZAlloc(NULL, sizeof(ECParams), kmflag);
-    if (!params) {
-        PORT_FreeArena(NULL, B_TRUE);
-        return SECFailure;
-    }
-
-    /* Copy the encoded params */
-    SECITEM_AllocItem(arena, &(params->DEREncoding), encodedParams->len,
-        kmflag);
-    memcpy(params->DEREncoding.data, encodedParams->data, encodedParams->len);
-
-    /* Fill out the rest of the ECParams structure based on
-     * the encoded params
-     */
-    rv = EC_FillParams(NULL, encodedParams, params, kmflag);
-    if (rv == SECFailure) {
-        PORT_FreeArena(NULL, B_TRUE);
-        return SECFailure;
-    } else {
-        *ecparams = params;;
-        return SECSuccess;
-    }
-}
--- a/jdk/src/share/native/sun/security/ec/ecl-curve.h	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,710 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _ECL_CURVE_H
-#define _ECL_CURVE_H
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "ecl-exp.h"
-#ifndef _KERNEL
-#include <stdlib.h>
-#endif
-
-/* NIST prime curves */
-static const ECCurveParams ecCurve_NIST_P192 = {
-        "NIST-P192", ECField_GFp, 192,
-        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF",
-        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC",
-        "64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1",
-        "188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012",
-        "07192B95FFC8DA78631011ED6B24CDD573F977A11E794811",
-        "FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831", 1
-};
-
-static const ECCurveParams ecCurve_NIST_P224 = {
-        "NIST-P224", ECField_GFp, 224,
-        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001",
-        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE",
-        "B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4",
-        "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21",
-        "BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34",
-        "FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D", 1
-};
-
-static const ECCurveParams ecCurve_NIST_P256 = {
-        "NIST-P256", ECField_GFp, 256,
-        "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF",
-        "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC",
-        "5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B",
-        "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296",
-        "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5",
-        "FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551", 1
-};
-
-static const ECCurveParams ecCurve_NIST_P384 = {
-        "NIST-P384", ECField_GFp, 384,
-        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF",
-        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC",
-        "B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF",
-        "AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B9859F741E082542A385502F25DBF55296C3A545E3872760AB7",
-        "3617DE4A96262C6F5D9E98BF9292DC29F8F41DBD289A147CE9DA3113B5F0B8C00A60B1CE1D7E819D7A431D7C90EA0E5F",
-        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973",
-        1
-};
-
-static const ECCurveParams ecCurve_NIST_P521 = {
-        "NIST-P521", ECField_GFp, 521,
-        "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
-        "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC",
-        "0051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00",
-        "00C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66",
-        "011839296A789A3BC0045C8A5FB42C7D1BD998F54449579B446817AFBD17273E662C97EE72995EF42640C550B9013FAD0761353C7086A272C24088BE94769FD16650",
-        "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409",
-        1
-};
-
-/* NIST binary curves */
-static const ECCurveParams ecCurve_NIST_K163 = {
-        "NIST-K163", ECField_GF2m, 163,
-        "0800000000000000000000000000000000000000C9",
-        "000000000000000000000000000000000000000001",
-        "000000000000000000000000000000000000000001",
-        "02FE13C0537BBC11ACAA07D793DE4E6D5E5C94EEE8",
-        "0289070FB05D38FF58321F2E800536D538CCDAA3D9",
-        "04000000000000000000020108A2E0CC0D99F8A5EF", 2
-};
-
-static const ECCurveParams ecCurve_NIST_B163 = {
-        "NIST-B163", ECField_GF2m, 163,
-        "0800000000000000000000000000000000000000C9",
-        "000000000000000000000000000000000000000001",
-        "020A601907B8C953CA1481EB10512F78744A3205FD",
-        "03F0EBA16286A2D57EA0991168D4994637E8343E36",
-        "00D51FBC6C71A0094FA2CDD545B11C5C0C797324F1",
-        "040000000000000000000292FE77E70C12A4234C33", 2
-};
-
-static const ECCurveParams ecCurve_NIST_K233 = {
-        "NIST-K233", ECField_GF2m, 233,
-        "020000000000000000000000000000000000000004000000000000000001",
-        "000000000000000000000000000000000000000000000000000000000000",
-        "000000000000000000000000000000000000000000000000000000000001",
-        "017232BA853A7E731AF129F22FF4149563A419C26BF50A4C9D6EEFAD6126",
-        "01DB537DECE819B7F70F555A67C427A8CD9BF18AEB9B56E0C11056FAE6A3",
-        "008000000000000000000000000000069D5BB915BCD46EFB1AD5F173ABDF", 4
-};
-
-static const ECCurveParams ecCurve_NIST_B233 = {
-        "NIST-B233", ECField_GF2m, 233,
-        "020000000000000000000000000000000000000004000000000000000001",
-        "000000000000000000000000000000000000000000000000000000000001",
-        "0066647EDE6C332C7F8C0923BB58213B333B20E9CE4281FE115F7D8F90AD",
-        "00FAC9DFCBAC8313BB2139F1BB755FEF65BC391F8B36F8F8EB7371FD558B",
-        "01006A08A41903350678E58528BEBF8A0BEFF867A7CA36716F7E01F81052",
-        "01000000000000000000000000000013E974E72F8A6922031D2603CFE0D7", 2
-};
-
-static const ECCurveParams ecCurve_NIST_K283 = {
-        "NIST-K283", ECField_GF2m, 283,
-        "0800000000000000000000000000000000000000000000000000000000000000000010A1",
-        "000000000000000000000000000000000000000000000000000000000000000000000000",
-        "000000000000000000000000000000000000000000000000000000000000000000000001",
-        "0503213F78CA44883F1A3B8162F188E553CD265F23C1567A16876913B0C2AC2458492836",
-        "01CCDA380F1C9E318D90F95D07E5426FE87E45C0E8184698E45962364E34116177DD2259",
-        "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE9AE2ED07577265DFF7F94451E061E163C61", 4
-};
-
-static const ECCurveParams ecCurve_NIST_B283 = {
-        "NIST-B283", ECField_GF2m, 283,
-        "0800000000000000000000000000000000000000000000000000000000000000000010A1",
-        "000000000000000000000000000000000000000000000000000000000000000000000001",
-        "027B680AC8B8596DA5A4AF8A19A0303FCA97FD7645309FA2A581485AF6263E313B79A2F5",
-        "05F939258DB7DD90E1934F8C70B0DFEC2EED25B8557EAC9C80E2E198F8CDBECD86B12053",
-        "03676854FE24141CB98FE6D4B20D02B4516FF702350EDDB0826779C813F0DF45BE8112F4",
-        "03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEF90399660FC938A90165B042A7CEFADB307", 2
-};
-
-static const ECCurveParams ecCurve_NIST_K409 = {
-        "NIST-K409", ECField_GF2m, 409,
-        "02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001",
-        "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
-        "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
-        "0060F05F658F49C1AD3AB1890F7184210EFD0987E307C84C27ACCFB8F9F67CC2C460189EB5AAAA62EE222EB1B35540CFE9023746",
-        "01E369050B7C4E42ACBA1DACBF04299C3460782F918EA427E6325165E9EA10E3DA5F6C42E9C55215AA9CA27A5863EC48D8E0286B",
-        "007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE5F83B2D4EA20400EC4557D5ED3E3E7CA5B4B5C83B8E01E5FCF", 4
-};
-
-static const ECCurveParams ecCurve_NIST_B409 = {
-        "NIST-B409", ECField_GF2m, 409,
-        "02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001",
-        "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
-        "0021A5C2C8EE9FEB5C4B9A753B7B476B7FD6422EF1F3DD674761FA99D6AC27C8A9A197B272822F6CD57A55AA4F50AE317B13545F",
-        "015D4860D088DDB3496B0C6064756260441CDE4AF1771D4DB01FFE5B34E59703DC255A868A1180515603AEAB60794E54BB7996A7",
-        "0061B1CFAB6BE5F32BBFA78324ED106A7636B9C5A7BD198D0158AA4F5488D08F38514F1FDF4B4F40D2181B3681C364BA0273C706",
-        "010000000000000000000000000000000000000000000000000001E2AAD6A612F33307BE5FA47C3C9E052F838164CD37D9A21173", 2
-};
-
-static const ECCurveParams ecCurve_NIST_K571 = {
-        "NIST-K571", ECField_GF2m, 571,
-        "080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425",
-        "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
-        "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
-        "026EB7A859923FBC82189631F8103FE4AC9CA2970012D5D46024804801841CA44370958493B205E647DA304DB4CEB08CBBD1BA39494776FB988B47174DCA88C7E2945283A01C8972",
-        "0349DC807F4FBF374F4AEADE3BCA95314DD58CEC9F307A54FFC61EFC006D8A2C9D4979C0AC44AEA74FBEBBB9F772AEDCB620B01A7BA7AF1B320430C8591984F601CD4C143EF1C7A3",
-        "020000000000000000000000000000000000000000000000000000000000000000000000131850E1F19A63E4B391A8DB917F4138B630D84BE5D639381E91DEB45CFE778F637C1001", 4
-};
-
-static const ECCurveParams ecCurve_NIST_B571 = {
-        "NIST-B571", ECField_GF2m, 571,
-        "080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425",
-        "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
-        "02F40E7E2221F295DE297117B7F3D62F5C6A97FFCB8CEFF1CD6BA8CE4A9A18AD84FFABBD8EFA59332BE7AD6756A66E294AFD185A78FF12AA520E4DE739BACA0C7FFEFF7F2955727A",
-        "0303001D34B856296C16C0D40D3CD7750A93D1D2955FA80AA5F40FC8DB7B2ABDBDE53950F4C0D293CDD711A35B67FB1499AE60038614F1394ABFA3B4C850D927E1E7769C8EEC2D19",
-        "037BF27342DA639B6DCCFFFEB73D69D78C6C27A6009CBBCA1980F8533921E8A684423E43BAB08A576291AF8F461BB2A8B3531D2F0485C19B16E2F1516E23DD3C1A4827AF1B8AC15B",
-        "03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE661CE18FF55987308059B186823851EC7DD9CA1161DE93D5174D66E8382E9BB2FE84E47", 2
-};
-
-/* ANSI X9.62 prime curves */
-static const ECCurveParams ecCurve_X9_62_PRIME_192V2 = {
-        "X9.62 P-192V2", ECField_GFp, 192,
-        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF",
-        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC",
-        "CC22D6DFB95C6B25E49C0D6364A4E5980C393AA21668D953",
-        "EEA2BAE7E1497842F2DE7769CFE9C989C072AD696F48034A",
-        "6574D11D69B6EC7A672BB82A083DF2F2B0847DE970B2DE15",
-        "FFFFFFFFFFFFFFFFFFFFFFFE5FB1A724DC80418648D8DD31", 1
-};
-
-static const ECCurveParams ecCurve_X9_62_PRIME_192V3 = {
-        "X9.62 P-192V3", ECField_GFp, 192,
-        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF",
-        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC",
-        "22123DC2395A05CAA7423DAECCC94760A7D462256BD56916",
-        "7D29778100C65A1DA1783716588DCE2B8B4AEE8E228F1896",
-        "38A90F22637337334B49DCB66A6DC8F9978ACA7648A943B0",
-        "FFFFFFFFFFFFFFFFFFFFFFFF7A62D031C83F4294F640EC13", 1
-};
-
-static const ECCurveParams ecCurve_X9_62_PRIME_239V1 = {
-        "X9.62 P-239V1", ECField_GFp, 239,
-        "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFF",
-        "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFC",
-        "6B016C3BDCF18941D0D654921475CA71A9DB2FB27D1D37796185C2942C0A",
-        "0FFA963CDCA8816CCC33B8642BEDF905C3D358573D3F27FBBD3B3CB9AAAF",
-        "7DEBE8E4E90A5DAE6E4054CA530BA04654B36818CE226B39FCCB7B02F1AE",
-        "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFF9E5E9A9F5D9071FBD1522688909D0B", 1
-};
-
-static const ECCurveParams ecCurve_X9_62_PRIME_239V2 = {
-        "X9.62 P-239V2", ECField_GFp, 239,
-        "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFF",
-        "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFC",
-        "617FAB6832576CBBFED50D99F0249C3FEE58B94BA0038C7AE84C8C832F2C",
-        "38AF09D98727705120C921BB5E9E26296A3CDCF2F35757A0EAFD87B830E7",
-        "5B0125E4DBEA0EC7206DA0FC01D9B081329FB555DE6EF460237DFF8BE4BA",
-        "7FFFFFFFFFFFFFFFFFFFFFFF800000CFA7E8594377D414C03821BC582063", 1
-};
-
-static const ECCurveParams ecCurve_X9_62_PRIME_239V3 = {
-        "X9.62 P-239V3", ECField_GFp, 239,
-        "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFF",
-        "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFC",
-        "255705FA2A306654B1F4CB03D6A750A30C250102D4988717D9BA15AB6D3E",
-        "6768AE8E18BB92CFCF005C949AA2C6D94853D0E660BBF854B1C9505FE95A",
-        "1607E6898F390C06BC1D552BAD226F3B6FCFE48B6E818499AF18E3ED6CF3",
-        "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFF975DEB41B3A6057C3C432146526551", 1
-};
-
-/* ANSI X9.62 binary curves */
-static const ECCurveParams ecCurve_X9_62_CHAR2_PNB163V1 = {
-        "X9.62 C2-PNB163V1", ECField_GF2m, 163,
-        "080000000000000000000000000000000000000107",
-        "072546B5435234A422E0789675F432C89435DE5242",
-        "00C9517D06D5240D3CFF38C74B20B6CD4D6F9DD4D9",
-        "07AF69989546103D79329FCC3D74880F33BBE803CB",
-        "01EC23211B5966ADEA1D3F87F7EA5848AEF0B7CA9F",
-        "0400000000000000000001E60FC8821CC74DAEAFC1", 2
-};
-
-static const ECCurveParams ecCurve_X9_62_CHAR2_PNB163V2 = {
-        "X9.62 C2-PNB163V2", ECField_GF2m, 163,
-        "080000000000000000000000000000000000000107",
-        "0108B39E77C4B108BED981ED0E890E117C511CF072",
-        "0667ACEB38AF4E488C407433FFAE4F1C811638DF20",
-        "0024266E4EB5106D0A964D92C4860E2671DB9B6CC5",
-        "079F684DDF6684C5CD258B3890021B2386DFD19FC5",
-        "03FFFFFFFFFFFFFFFFFFFDF64DE1151ADBB78F10A7", 2
-};
-
-static const ECCurveParams ecCurve_X9_62_CHAR2_PNB163V3 = {
-        "X9.62 C2-PNB163V3", ECField_GF2m, 163,
-        "080000000000000000000000000000000000000107",
-        "07A526C63D3E25A256A007699F5447E32AE456B50E",
-        "03F7061798EB99E238FD6F1BF95B48FEEB4854252B",
-        "02F9F87B7C574D0BDECF8A22E6524775F98CDEBDCB",
-        "05B935590C155E17EA48EB3FF3718B893DF59A05D0",
-        "03FFFFFFFFFFFFFFFFFFFE1AEE140F110AFF961309", 2
-};
-
-static const ECCurveParams ecCurve_X9_62_CHAR2_PNB176V1 = {
-        "X9.62 C2-PNB176V1", ECField_GF2m, 176,
-        "0100000000000000000000000000000000080000000007",
-        "E4E6DB2995065C407D9D39B8D0967B96704BA8E9C90B",
-        "5DDA470ABE6414DE8EC133AE28E9BBD7FCEC0AE0FFF2",
-        "8D16C2866798B600F9F08BB4A8E860F3298CE04A5798",
-        "6FA4539C2DADDDD6BAB5167D61B436E1D92BB16A562C",
-        "00010092537397ECA4F6145799D62B0A19CE06FE26AD", 0xFF6E
-};
-
-static const ECCurveParams ecCurve_X9_62_CHAR2_TNB191V1 = {
-        "X9.62 C2-TNB191V1", ECField_GF2m, 191,
-        "800000000000000000000000000000000000000000000201",
-        "2866537B676752636A68F56554E12640276B649EF7526267",
-        "2E45EF571F00786F67B0081B9495A3D95462F5DE0AA185EC",
-        "36B3DAF8A23206F9C4F299D7B21A9C369137F2C84AE1AA0D",
-        "765BE73433B3F95E332932E70EA245CA2418EA0EF98018FB",
-        "40000000000000000000000004A20E90C39067C893BBB9A5", 2
-};
-
-static const ECCurveParams ecCurve_X9_62_CHAR2_TNB191V2 = {
-        "X9.62 C2-TNB191V2", ECField_GF2m, 191,
-        "800000000000000000000000000000000000000000000201",
-        "401028774D7777C7B7666D1366EA432071274F89FF01E718",
-        "0620048D28BCBD03B6249C99182B7C8CD19700C362C46A01",
-        "3809B2B7CC1B28CC5A87926AAD83FD28789E81E2C9E3BF10",
-        "17434386626D14F3DBF01760D9213A3E1CF37AEC437D668A",
-        "20000000000000000000000050508CB89F652824E06B8173", 4
-};
-
-static const ECCurveParams ecCurve_X9_62_CHAR2_TNB191V3 = {
-        "X9.62 C2-TNB191V3", ECField_GF2m, 191,
-        "800000000000000000000000000000000000000000000201",
-        "6C01074756099122221056911C77D77E77A777E7E7E77FCB",
-        "71FE1AF926CF847989EFEF8DB459F66394D90F32AD3F15E8",
-        "375D4CE24FDE434489DE8746E71786015009E66E38A926DD",
-        "545A39176196575D985999366E6AD34CE0A77CD7127B06BE",
-        "155555555555555555555555610C0B196812BFB6288A3EA3", 6
-};
-
-static const ECCurveParams ecCurve_X9_62_CHAR2_PNB208W1 = {
-        "X9.62 C2-PNB208W1", ECField_GF2m, 208,
-        "010000000000000000000000000000000800000000000000000007",
-        "0000000000000000000000000000000000000000000000000000",
-        "C8619ED45A62E6212E1160349E2BFA844439FAFC2A3FD1638F9E",
-        "89FDFBE4ABE193DF9559ECF07AC0CE78554E2784EB8C1ED1A57A",
-        "0F55B51A06E78E9AC38A035FF520D8B01781BEB1A6BB08617DE3",
-        "000101BAF95C9723C57B6C21DA2EFF2D5ED588BDD5717E212F9D", 0xFE48
-};
-
-static const ECCurveParams ecCurve_X9_62_CHAR2_TNB239V1 = {
-        "X9.62 C2-TNB239V1", ECField_GF2m, 239,
-        "800000000000000000000000000000000000000000000000001000000001",
-        "32010857077C5431123A46B808906756F543423E8D27877578125778AC76",
-        "790408F2EEDAF392B012EDEFB3392F30F4327C0CA3F31FC383C422AA8C16",
-        "57927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D",
-        "61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305",
-        "2000000000000000000000000000000F4D42FFE1492A4993F1CAD666E447", 4
-};
-
-static const ECCurveParams ecCurve_X9_62_CHAR2_TNB239V2 = {
-        "X9.62 C2-TNB239V2", ECField_GF2m, 239,
-        "800000000000000000000000000000000000000000000000001000000001",
-        "4230017757A767FAE42398569B746325D45313AF0766266479B75654E65F",
-        "5037EA654196CFF0CD82B2C14A2FCF2E3FF8775285B545722F03EACDB74B",
-        "28F9D04E900069C8DC47A08534FE76D2B900B7D7EF31F5709F200C4CA205",
-        "5667334C45AFF3B5A03BAD9DD75E2C71A99362567D5453F7FA6E227EC833",
-        "1555555555555555555555555555553C6F2885259C31E3FCDF154624522D", 6
-};
-
-static const ECCurveParams ecCurve_X9_62_CHAR2_TNB239V3 = {
-        "X9.62 C2-TNB239V3", ECField_GF2m, 239,
-        "800000000000000000000000000000000000000000000000001000000001",
-        "01238774666A67766D6676F778E676B66999176666E687666D8766C66A9F",
-        "6A941977BA9F6A435199ACFC51067ED587F519C5ECB541B8E44111DE1D40",
-        "70F6E9D04D289C4E89913CE3530BFDE903977D42B146D539BF1BDE4E9C92",
-        "2E5A0EAF6E5E1305B9004DCE5C0ED7FE59A35608F33837C816D80B79F461",
-        "0CCCCCCCCCCCCCCCCCCCCCCCCCCCCCAC4912D2D9DF903EF9888B8A0E4CFF", 0xA
-};
-
-static const ECCurveParams ecCurve_X9_62_CHAR2_PNB272W1 = {
-        "X9.62 C2-PNB272W1", ECField_GF2m, 272,
-        "010000000000000000000000000000000000000000000000000000010000000000000B",
-        "91A091F03B5FBA4AB2CCF49C4EDD220FB028712D42BE752B2C40094DBACDB586FB20",
-        "7167EFC92BB2E3CE7C8AAAFF34E12A9C557003D7C73A6FAF003F99F6CC8482E540F7",
-        "6108BABB2CEEBCF787058A056CBE0CFE622D7723A289E08A07AE13EF0D10D171DD8D",
-        "10C7695716851EEF6BA7F6872E6142FBD241B830FF5EFCACECCAB05E02005DDE9D23",
-        "000100FAF51354E0E39E4892DF6E319C72C8161603FA45AA7B998A167B8F1E629521",
-        0xFF06
-};
-
-static const ECCurveParams ecCurve_X9_62_CHAR2_PNB304W1 = {
-        "X9.62 C2-PNB304W1", ECField_GF2m, 304,
-        "010000000000000000000000000000000000000000000000000000000000000000000000000807",
-        "FD0D693149A118F651E6DCE6802085377E5F882D1B510B44160074C1288078365A0396C8E681",
-        "BDDB97E555A50A908E43B01C798EA5DAA6788F1EA2794EFCF57166B8C14039601E55827340BE",
-        "197B07845E9BE2D96ADB0F5F3C7F2CFFBD7A3EB8B6FEC35C7FD67F26DDF6285A644F740A2614",
-        "E19FBEB76E0DA171517ECF401B50289BF014103288527A9B416A105E80260B549FDC1B92C03B",
-        "000101D556572AABAC800101D556572AABAC8001022D5C91DD173F8FB561DA6899164443051D", 0xFE2E
-};
-
-static const ECCurveParams ecCurve_X9_62_CHAR2_TNB359V1 = {
-        "X9.62 C2-TNB359V1", ECField_GF2m, 359,
-        "800000000000000000000000000000000000000000000000000000000000000000000000100000000000000001",
-        "5667676A654B20754F356EA92017D946567C46675556F19556A04616B567D223A5E05656FB549016A96656A557",
-        "2472E2D0197C49363F1FE7F5B6DB075D52B6947D135D8CA445805D39BC345626089687742B6329E70680231988",
-        "3C258EF3047767E7EDE0F1FDAA79DAEE3841366A132E163ACED4ED2401DF9C6BDCDE98E8E707C07A2239B1B097",
-        "53D7E08529547048121E9C95F3791DD804963948F34FAE7BF44EA82365DC7868FE57E4AE2DE211305A407104BD",
-        "01AF286BCA1AF286BCA1AF286BCA1AF286BCA1AF286BC9FB8F6B85C556892C20A7EB964FE7719E74F490758D3B", 0x4C
-};
-
-static const ECCurveParams ecCurve_X9_62_CHAR2_PNB368W1 = {
-        "X9.62 C2-PNB368W1", ECField_GF2m, 368,
-        "0100000000000000000000000000000000000000000000000000000000000000000000002000000000000000000007",
-        "E0D2EE25095206F5E2A4F9ED229F1F256E79A0E2B455970D8D0D865BD94778C576D62F0AB7519CCD2A1A906AE30D",
-        "FC1217D4320A90452C760A58EDCD30C8DD069B3C34453837A34ED50CB54917E1C2112D84D164F444F8F74786046A",
-        "1085E2755381DCCCE3C1557AFA10C2F0C0C2825646C5B34A394CBCFA8BC16B22E7E789E927BE216F02E1FB136A5F",
-        "7B3EB1BDDCBA62D5D8B2059B525797FC73822C59059C623A45FF3843CEE8F87CD1855ADAA81E2A0750B80FDA2310",
-        "00010090512DA9AF72B08349D98A5DD4C7B0532ECA51CE03E2D10F3B7AC579BD87E909AE40A6F131E9CFCE5BD967", 0xFF70
-};
-
-static const ECCurveParams ecCurve_X9_62_CHAR2_TNB431R1 = {
-        "X9.62 C2-TNB431R1", ECField_GF2m, 431,
-        "800000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000001",
-        "1A827EF00DD6FC0E234CAF046C6A5D8A85395B236CC4AD2CF32A0CADBDC9DDF620B0EB9906D0957F6C6FEACD615468DF104DE296CD8F",
-        "10D9B4A3D9047D8B154359ABFB1B7F5485B04CEB868237DDC9DEDA982A679A5A919B626D4E50A8DD731B107A9962381FB5D807BF2618",
-        "120FC05D3C67A99DE161D2F4092622FECA701BE4F50F4758714E8A87BBF2A658EF8C21E7C5EFE965361F6C2999C0C247B0DBD70CE6B7",
-        "20D0AF8903A96F8D5FA2C255745D3C451B302C9346D9B7E485E7BCE41F6B591F3E8F6ADDCBB0BC4C2F947A7DE1A89B625D6A598B3760",
-        "0340340340340340340340340340340340340340340340340340340323C313FAB50589703B5EC68D3587FEC60D161CC149C1AD4A91", 0x2760
-};
-
-/* SEC2 prime curves */
-static const ECCurveParams ecCurve_SECG_PRIME_112R1 = {
-        "SECP-112R1", ECField_GFp, 112,
-        "DB7C2ABF62E35E668076BEAD208B",
-        "DB7C2ABF62E35E668076BEAD2088",
-        "659EF8BA043916EEDE8911702B22",
-        "09487239995A5EE76B55F9C2F098",
-        "A89CE5AF8724C0A23E0E0FF77500",
-        "DB7C2ABF62E35E7628DFAC6561C5", 1
-};
-
-static const ECCurveParams ecCurve_SECG_PRIME_112R2 = {
-        "SECP-112R2", ECField_GFp, 112,
-        "DB7C2ABF62E35E668076BEAD208B",
-        "6127C24C05F38A0AAAF65C0EF02C",
-        "51DEF1815DB5ED74FCC34C85D709",
-        "4BA30AB5E892B4E1649DD0928643",
-        "adcd46f5882e3747def36e956e97",
-        "36DF0AAFD8B8D7597CA10520D04B", 4
-};
-
-static const ECCurveParams ecCurve_SECG_PRIME_128R1 = {
-        "SECP-128R1", ECField_GFp, 128,
-        "FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF",
-        "FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFC",
-        "E87579C11079F43DD824993C2CEE5ED3",
-        "161FF7528B899B2D0C28607CA52C5B86",
-        "CF5AC8395BAFEB13C02DA292DDED7A83",
-        "FFFFFFFE0000000075A30D1B9038A115", 1
-};
-
-static const ECCurveParams ecCurve_SECG_PRIME_128R2 = {
-        "SECP-128R2", ECField_GFp, 128,
-        "FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF",
-        "D6031998D1B3BBFEBF59CC9BBFF9AEE1",
-        "5EEEFCA380D02919DC2C6558BB6D8A5D",
-        "7B6AA5D85E572983E6FB32A7CDEBC140",
-        "27B6916A894D3AEE7106FE805FC34B44",
-        "3FFFFFFF7FFFFFFFBE0024720613B5A3", 4
-};
-
-static const ECCurveParams ecCurve_SECG_PRIME_160K1 = {
-        "SECP-160K1", ECField_GFp, 160,
-        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73",
-        "0000000000000000000000000000000000000000",
-        "0000000000000000000000000000000000000007",
-        "3B4C382CE37AA192A4019E763036F4F5DD4D7EBB",
-        "938CF935318FDCED6BC28286531733C3F03C4FEE",
-        "0100000000000000000001B8FA16DFAB9ACA16B6B3", 1
-};
-
-static const ECCurveParams ecCurve_SECG_PRIME_160R1 = {
-        "SECP-160R1", ECField_GFp, 160,
-        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF",
-        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC",
-        "1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45",
-        "4A96B5688EF573284664698968C38BB913CBFC82",
-        "23A628553168947D59DCC912042351377AC5FB32",
-        "0100000000000000000001F4C8F927AED3CA752257", 1
-};
-
-static const ECCurveParams ecCurve_SECG_PRIME_160R2 = {
-        "SECP-160R2", ECField_GFp, 160,
-        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73",
-        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC70",
-        "B4E134D3FB59EB8BAB57274904664D5AF50388BA",
-        "52DCB034293A117E1F4FF11B30F7199D3144CE6D",
-        "FEAFFEF2E331F296E071FA0DF9982CFEA7D43F2E",
-        "0100000000000000000000351EE786A818F3A1A16B", 1
-};
-
-static const ECCurveParams ecCurve_SECG_PRIME_192K1 = {
-        "SECP-192K1", ECField_GFp, 192,
-        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFEE37",
-        "000000000000000000000000000000000000000000000000",
-        "000000000000000000000000000000000000000000000003",
-        "DB4FF10EC057E9AE26B07D0280B7F4341DA5D1B1EAE06C7D",
-        "9B2F2F6D9C5628A7844163D015BE86344082AA88D95E2F9D",
-        "FFFFFFFFFFFFFFFFFFFFFFFE26F2FC170F69466A74DEFD8D", 1
-};
-
-static const ECCurveParams ecCurve_SECG_PRIME_224K1 = {
-        "SECP-224K1", ECField_GFp, 224,
-        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFE56D",
-        "00000000000000000000000000000000000000000000000000000000",
-        "00000000000000000000000000000000000000000000000000000005",
-        "A1455B334DF099DF30FC28A169A467E9E47075A90F7E650EB6B7A45C",
-        "7E089FED7FBA344282CAFBD6F7E319F7C0B0BD59E2CA4BDB556D61A5",
-        "010000000000000000000000000001DCE8D2EC6184CAF0A971769FB1F7", 1
-};
-
-static const ECCurveParams ecCurve_SECG_PRIME_256K1 = {
-        "SECP-256K1", ECField_GFp, 256,
-        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F",
-        "0000000000000000000000000000000000000000000000000000000000000000",
-        "0000000000000000000000000000000000000000000000000000000000000007",
-        "79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798",
-        "483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8",
-        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", 1
-};
-
-/* SEC2 binary curves */
-static const ECCurveParams ecCurve_SECG_CHAR2_113R1 = {
-        "SECT-113R1", ECField_GF2m, 113,
-        "020000000000000000000000000201",
-        "003088250CA6E7C7FE649CE85820F7",
-        "00E8BEE4D3E2260744188BE0E9C723",
-        "009D73616F35F4AB1407D73562C10F",
-        "00A52830277958EE84D1315ED31886",
-        "0100000000000000D9CCEC8A39E56F", 2
-};
-
-static const ECCurveParams ecCurve_SECG_CHAR2_113R2 = {
-        "SECT-113R2", ECField_GF2m, 113,
-        "020000000000000000000000000201",
-        "00689918DBEC7E5A0DD6DFC0AA55C7",
-        "0095E9A9EC9B297BD4BF36E059184F",
-        "01A57A6A7B26CA5EF52FCDB8164797",
-        "00B3ADC94ED1FE674C06E695BABA1D",
-        "010000000000000108789B2496AF93", 2
-};
-
-static const ECCurveParams ecCurve_SECG_CHAR2_131R1 = {
-        "SECT-131R1", ECField_GF2m, 131,
-        "080000000000000000000000000000010D",
-        "07A11B09A76B562144418FF3FF8C2570B8",
-        "0217C05610884B63B9C6C7291678F9D341",
-        "0081BAF91FDF9833C40F9C181343638399",
-        "078C6E7EA38C001F73C8134B1B4EF9E150",
-        "0400000000000000023123953A9464B54D", 2
-};
-
-static const ECCurveParams ecCurve_SECG_CHAR2_131R2 = {
-        "SECT-131R2", ECField_GF2m, 131,
-        "080000000000000000000000000000010D",
-        "03E5A88919D7CAFCBF415F07C2176573B2",
-        "04B8266A46C55657AC734CE38F018F2192",
-        "0356DCD8F2F95031AD652D23951BB366A8",
-        "0648F06D867940A5366D9E265DE9EB240F",
-        "0400000000000000016954A233049BA98F", 2
-};
-
-static const ECCurveParams ecCurve_SECG_CHAR2_163R1 = {
-        "SECT-163R1", ECField_GF2m, 163,
-        "0800000000000000000000000000000000000000C9",
-        "07B6882CAAEFA84F9554FF8428BD88E246D2782AE2",
-        "0713612DCDDCB40AAB946BDA29CA91F73AF958AFD9",
-        "0369979697AB43897789566789567F787A7876A654",
-        "00435EDB42EFAFB2989D51FEFCE3C80988F41FF883",
-        "03FFFFFFFFFFFFFFFFFFFF48AAB689C29CA710279B", 2
-};
-
-static const ECCurveParams ecCurve_SECG_CHAR2_193R1 = {
-        "SECT-193R1", ECField_GF2m, 193,
-        "02000000000000000000000000000000000000000000008001",
-        "0017858FEB7A98975169E171F77B4087DE098AC8A911DF7B01",
-        "00FDFB49BFE6C3A89FACADAA7A1E5BBC7CC1C2E5D831478814",
-        "01F481BC5F0FF84A74AD6CDF6FDEF4BF6179625372D8C0C5E1",
-        "0025E399F2903712CCF3EA9E3A1AD17FB0B3201B6AF7CE1B05",
-        "01000000000000000000000000C7F34A778F443ACC920EBA49", 2
-};
-
-static const ECCurveParams ecCurve_SECG_CHAR2_193R2 = {
-        "SECT-193R2", ECField_GF2m, 193,
-        "02000000000000000000000000000000000000000000008001",
-        "0163F35A5137C2CE3EA6ED8667190B0BC43ECD69977702709B",
-        "00C9BB9E8927D4D64C377E2AB2856A5B16E3EFB7F61D4316AE",
-        "00D9B67D192E0367C803F39E1A7E82CA14A651350AAE617E8F",
-        "01CE94335607C304AC29E7DEFBD9CA01F596F927224CDECF6C",
-        "010000000000000000000000015AAB561B005413CCD4EE99D5", 2
-};
-
-static const ECCurveParams ecCurve_SECG_CHAR2_239K1 = {
-        "SECT-239K1", ECField_GF2m, 239,
-        "800000000000000000004000000000000000000000000000000000000001",
-        "000000000000000000000000000000000000000000000000000000000000",
-        "000000000000000000000000000000000000000000000000000000000001",
-        "29A0B6A887A983E9730988A68727A8B2D126C44CC2CC7B2A6555193035DC",
-        "76310804F12E549BDB011C103089E73510ACB275FC312A5DC6B76553F0CA",
-        "2000000000000000000000000000005A79FEC67CB6E91F1C1DA800E478A5", 4
-};
-
-/* WTLS curves */
-static const ECCurveParams ecCurve_WTLS_1 = {
-        "WTLS-1", ECField_GF2m, 113,
-        "020000000000000000000000000201",
-        "000000000000000000000000000001",
-        "000000000000000000000000000001",
-        "01667979A40BA497E5D5C270780617",
-        "00F44B4AF1ECC2630E08785CEBCC15",
-        "00FFFFFFFFFFFFFFFDBF91AF6DEA73", 2
-};
-
-static const ECCurveParams ecCurve_WTLS_8 = {
-        "WTLS-8", ECField_GFp, 112,
-        "FFFFFFFFFFFFFFFFFFFFFFFFFDE7",
-        "0000000000000000000000000000",
-        "0000000000000000000000000003",
-        "0000000000000000000000000001",
-        "0000000000000000000000000002",
-        "0100000000000001ECEA551AD837E9", 1
-};
-
-static const ECCurveParams ecCurve_WTLS_9 = {
-        "WTLS-9", ECField_GFp, 160,
-        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC808F",
-        "0000000000000000000000000000000000000000",
-        "0000000000000000000000000000000000000003",
-        "0000000000000000000000000000000000000001",
-        "0000000000000000000000000000000000000002",
-        "0100000000000000000001CDC98AE0E2DE574ABF33", 1
-};
-
-/* mapping between ECCurveName enum and pointers to ECCurveParams */
-static const ECCurveParams *ecCurve_map[] = {
-    NULL,                               /* ECCurve_noName */
-    &ecCurve_NIST_P192,                 /* ECCurve_NIST_P192 */
-    &ecCurve_NIST_P224,                 /* ECCurve_NIST_P224 */
-    &ecCurve_NIST_P256,                 /* ECCurve_NIST_P256 */
-    &ecCurve_NIST_P384,                 /* ECCurve_NIST_P384 */
-    &ecCurve_NIST_P521,                 /* ECCurve_NIST_P521 */
-    &ecCurve_NIST_K163,                 /* ECCurve_NIST_K163 */
-    &ecCurve_NIST_B163,                 /* ECCurve_NIST_B163 */
-    &ecCurve_NIST_K233,                 /* ECCurve_NIST_K233 */
-    &ecCurve_NIST_B233,                 /* ECCurve_NIST_B233 */
-    &ecCurve_NIST_K283,                 /* ECCurve_NIST_K283 */
-    &ecCurve_NIST_B283,                 /* ECCurve_NIST_B283 */
-    &ecCurve_NIST_K409,                 /* ECCurve_NIST_K409 */
-    &ecCurve_NIST_B409,                 /* ECCurve_NIST_B409 */
-    &ecCurve_NIST_K571,                 /* ECCurve_NIST_K571 */
-    &ecCurve_NIST_B571,                 /* ECCurve_NIST_B571 */
-    &ecCurve_X9_62_PRIME_192V2,         /* ECCurve_X9_62_PRIME_192V2 */
-    &ecCurve_X9_62_PRIME_192V3,         /* ECCurve_X9_62_PRIME_192V3 */
-    &ecCurve_X9_62_PRIME_239V1,         /* ECCurve_X9_62_PRIME_239V1 */
-    &ecCurve_X9_62_PRIME_239V2,         /* ECCurve_X9_62_PRIME_239V2 */
-    &ecCurve_X9_62_PRIME_239V3,         /* ECCurve_X9_62_PRIME_239V3 */
-    &ecCurve_X9_62_CHAR2_PNB163V1,      /* ECCurve_X9_62_CHAR2_PNB163V1 */
-    &ecCurve_X9_62_CHAR2_PNB163V2,      /* ECCurve_X9_62_CHAR2_PNB163V2 */
-    &ecCurve_X9_62_CHAR2_PNB163V3,      /* ECCurve_X9_62_CHAR2_PNB163V3 */
-    &ecCurve_X9_62_CHAR2_PNB176V1,      /* ECCurve_X9_62_CHAR2_PNB176V1 */
-    &ecCurve_X9_62_CHAR2_TNB191V1,      /* ECCurve_X9_62_CHAR2_TNB191V1 */
-    &ecCurve_X9_62_CHAR2_TNB191V2,      /* ECCurve_X9_62_CHAR2_TNB191V2 */
-    &ecCurve_X9_62_CHAR2_TNB191V3,      /* ECCurve_X9_62_CHAR2_TNB191V3 */
-    &ecCurve_X9_62_CHAR2_PNB208W1,      /* ECCurve_X9_62_CHAR2_PNB208W1 */
-    &ecCurve_X9_62_CHAR2_TNB239V1,      /* ECCurve_X9_62_CHAR2_TNB239V1 */
-    &ecCurve_X9_62_CHAR2_TNB239V2,      /* ECCurve_X9_62_CHAR2_TNB239V2 */
-    &ecCurve_X9_62_CHAR2_TNB239V3,      /* ECCurve_X9_62_CHAR2_TNB239V3 */
-    &ecCurve_X9_62_CHAR2_PNB272W1,      /* ECCurve_X9_62_CHAR2_PNB272W1 */
-    &ecCurve_X9_62_CHAR2_PNB304W1,      /* ECCurve_X9_62_CHAR2_PNB304W1 */
-    &ecCurve_X9_62_CHAR2_TNB359V1,      /* ECCurve_X9_62_CHAR2_TNB359V1 */
-    &ecCurve_X9_62_CHAR2_PNB368W1,      /* ECCurve_X9_62_CHAR2_PNB368W1 */
-    &ecCurve_X9_62_CHAR2_TNB431R1,      /* ECCurve_X9_62_CHAR2_TNB431R1 */
-    &ecCurve_SECG_PRIME_112R1,          /* ECCurve_SECG_PRIME_112R1 */
-    &ecCurve_SECG_PRIME_112R2,          /* ECCurve_SECG_PRIME_112R2 */
-    &ecCurve_SECG_PRIME_128R1,          /* ECCurve_SECG_PRIME_128R1 */
-    &ecCurve_SECG_PRIME_128R2,          /* ECCurve_SECG_PRIME_128R2 */
-    &ecCurve_SECG_PRIME_160K1,          /* ECCurve_SECG_PRIME_160K1 */
-    &ecCurve_SECG_PRIME_160R1,          /* ECCurve_SECG_PRIME_160R1 */
-    &ecCurve_SECG_PRIME_160R2,          /* ECCurve_SECG_PRIME_160R2 */
-    &ecCurve_SECG_PRIME_192K1,          /* ECCurve_SECG_PRIME_192K1 */
-    &ecCurve_SECG_PRIME_224K1,          /* ECCurve_SECG_PRIME_224K1 */
-    &ecCurve_SECG_PRIME_256K1,          /* ECCurve_SECG_PRIME_256K1 */
-    &ecCurve_SECG_CHAR2_113R1,          /* ECCurve_SECG_CHAR2_113R1 */
-    &ecCurve_SECG_CHAR2_113R2,          /* ECCurve_SECG_CHAR2_113R2 */
-    &ecCurve_SECG_CHAR2_131R1,          /* ECCurve_SECG_CHAR2_131R1 */
-    &ecCurve_SECG_CHAR2_131R2,          /* ECCurve_SECG_CHAR2_131R2 */
-    &ecCurve_SECG_CHAR2_163R1,          /* ECCurve_SECG_CHAR2_163R1 */
-    &ecCurve_SECG_CHAR2_193R1,          /* ECCurve_SECG_CHAR2_193R1 */
-    &ecCurve_SECG_CHAR2_193R2,          /* ECCurve_SECG_CHAR2_193R2 */
-    &ecCurve_SECG_CHAR2_239K1,          /* ECCurve_SECG_CHAR2_239K1 */
-    &ecCurve_WTLS_1,                    /* ECCurve_WTLS_1 */
-    &ecCurve_WTLS_8,                    /* ECCurve_WTLS_8 */
-    &ecCurve_WTLS_9,                    /* ECCurve_WTLS_9 */
-    NULL                                /* ECCurve_pastLastCurve */
-};
-
-#endif /* _ECL_CURVE_H */
--- a/jdk/src/share/native/sun/security/ec/ecl-exp.h	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,216 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _ECL_EXP_H
-#define _ECL_EXP_H
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-/* Curve field type */
-typedef enum {
-        ECField_GFp,
-        ECField_GF2m
-} ECField;
-
-/* Hexadecimal encoding of curve parameters */
-struct ECCurveParamsStr {
-        char *text;
-        ECField field;
-        unsigned int size;
-        char *irr;
-        char *curvea;
-        char *curveb;
-        char *genx;
-        char *geny;
-        char *order;
-        int cofactor;
-};
-typedef struct ECCurveParamsStr ECCurveParams;
-
-/* Named curve parameters */
-typedef enum {
-
-        ECCurve_noName = 0,
-
-        /* NIST prime curves */
-        ECCurve_NIST_P192,
-        ECCurve_NIST_P224,
-        ECCurve_NIST_P256,
-        ECCurve_NIST_P384,
-        ECCurve_NIST_P521,
-
-        /* NIST binary curves */
-        ECCurve_NIST_K163,
-        ECCurve_NIST_B163,
-        ECCurve_NIST_K233,
-        ECCurve_NIST_B233,
-        ECCurve_NIST_K283,
-        ECCurve_NIST_B283,
-        ECCurve_NIST_K409,
-        ECCurve_NIST_B409,
-        ECCurve_NIST_K571,
-        ECCurve_NIST_B571,
-
-        /* ANSI X9.62 prime curves */
-        /* ECCurve_X9_62_PRIME_192V1 == ECCurve_NIST_P192 */
-        ECCurve_X9_62_PRIME_192V2,
-        ECCurve_X9_62_PRIME_192V3,
-        ECCurve_X9_62_PRIME_239V1,
-        ECCurve_X9_62_PRIME_239V2,
-        ECCurve_X9_62_PRIME_239V3,
-        /* ECCurve_X9_62_PRIME_256V1 == ECCurve_NIST_P256 */
-
-        /* ANSI X9.62 binary curves */
-        ECCurve_X9_62_CHAR2_PNB163V1,
-        ECCurve_X9_62_CHAR2_PNB163V2,
-        ECCurve_X9_62_CHAR2_PNB163V3,
-        ECCurve_X9_62_CHAR2_PNB176V1,
-        ECCurve_X9_62_CHAR2_TNB191V1,
-        ECCurve_X9_62_CHAR2_TNB191V2,
-        ECCurve_X9_62_CHAR2_TNB191V3,
-        ECCurve_X9_62_CHAR2_PNB208W1,
-        ECCurve_X9_62_CHAR2_TNB239V1,
-        ECCurve_X9_62_CHAR2_TNB239V2,
-        ECCurve_X9_62_CHAR2_TNB239V3,
-        ECCurve_X9_62_CHAR2_PNB272W1,
-        ECCurve_X9_62_CHAR2_PNB304W1,
-        ECCurve_X9_62_CHAR2_TNB359V1,
-        ECCurve_X9_62_CHAR2_PNB368W1,
-        ECCurve_X9_62_CHAR2_TNB431R1,
-
-        /* SEC2 prime curves */
-        ECCurve_SECG_PRIME_112R1,
-        ECCurve_SECG_PRIME_112R2,
-        ECCurve_SECG_PRIME_128R1,
-        ECCurve_SECG_PRIME_128R2,
-        ECCurve_SECG_PRIME_160K1,
-        ECCurve_SECG_PRIME_160R1,
-        ECCurve_SECG_PRIME_160R2,
-        ECCurve_SECG_PRIME_192K1,
-        /* ECCurve_SECG_PRIME_192R1 == ECCurve_NIST_P192 */
-        ECCurve_SECG_PRIME_224K1,
-        /* ECCurve_SECG_PRIME_224R1 == ECCurve_NIST_P224 */
-        ECCurve_SECG_PRIME_256K1,
-        /* ECCurve_SECG_PRIME_256R1 == ECCurve_NIST_P256 */
-        /* ECCurve_SECG_PRIME_384R1 == ECCurve_NIST_P384 */
-        /* ECCurve_SECG_PRIME_521R1 == ECCurve_NIST_P521 */
-
-        /* SEC2 binary curves */
-        ECCurve_SECG_CHAR2_113R1,
-        ECCurve_SECG_CHAR2_113R2,
-        ECCurve_SECG_CHAR2_131R1,
-        ECCurve_SECG_CHAR2_131R2,
-        /* ECCurve_SECG_CHAR2_163K1 == ECCurve_NIST_K163 */
-        ECCurve_SECG_CHAR2_163R1,
-        /* ECCurve_SECG_CHAR2_163R2 == ECCurve_NIST_B163 */
-        ECCurve_SECG_CHAR2_193R1,
-        ECCurve_SECG_CHAR2_193R2,
-        /* ECCurve_SECG_CHAR2_233K1 == ECCurve_NIST_K233 */
-        /* ECCurve_SECG_CHAR2_233R1 == ECCurve_NIST_B233 */
-        ECCurve_SECG_CHAR2_239K1,
-        /* ECCurve_SECG_CHAR2_283K1 == ECCurve_NIST_K283 */
-        /* ECCurve_SECG_CHAR2_283R1 == ECCurve_NIST_B283 */
-        /* ECCurve_SECG_CHAR2_409K1 == ECCurve_NIST_K409 */
-        /* ECCurve_SECG_CHAR2_409R1 == ECCurve_NIST_B409 */
-        /* ECCurve_SECG_CHAR2_571K1 == ECCurve_NIST_K571 */
-        /* ECCurve_SECG_CHAR2_571R1 == ECCurve_NIST_B571 */
-
-        /* WTLS curves */
-        ECCurve_WTLS_1,
-        /* there is no WTLS 2 curve */
-        /* ECCurve_WTLS_3 == ECCurve_NIST_K163 */
-        /* ECCurve_WTLS_4 == ECCurve_SECG_CHAR2_113R1 */
-        /* ECCurve_WTLS_5 == ECCurve_X9_62_CHAR2_PNB163V1 */
-        /* ECCurve_WTLS_6 == ECCurve_SECG_PRIME_112R1 */
-        /* ECCurve_WTLS_7 == ECCurve_SECG_PRIME_160R1 */
-        ECCurve_WTLS_8,
-        ECCurve_WTLS_9,
-        /* ECCurve_WTLS_10 == ECCurve_NIST_K233 */
-        /* ECCurve_WTLS_11 == ECCurve_NIST_B233 */
-        /* ECCurve_WTLS_12 == ECCurve_NIST_P224 */
-
-        ECCurve_pastLastCurve
-} ECCurveName;
-
-/* Aliased named curves */
-
-#define ECCurve_X9_62_PRIME_192V1 ECCurve_NIST_P192
-#define ECCurve_X9_62_PRIME_256V1 ECCurve_NIST_P256
-#define ECCurve_SECG_PRIME_192R1 ECCurve_NIST_P192
-#define ECCurve_SECG_PRIME_224R1 ECCurve_NIST_P224
-#define ECCurve_SECG_PRIME_256R1 ECCurve_NIST_P256
-#define ECCurve_SECG_PRIME_384R1 ECCurve_NIST_P384
-#define ECCurve_SECG_PRIME_521R1 ECCurve_NIST_P521
-#define ECCurve_SECG_CHAR2_163K1 ECCurve_NIST_K163
-#define ECCurve_SECG_CHAR2_163R2 ECCurve_NIST_B163
-#define ECCurve_SECG_CHAR2_233K1 ECCurve_NIST_K233
-#define ECCurve_SECG_CHAR2_233R1 ECCurve_NIST_B233
-#define ECCurve_SECG_CHAR2_283K1 ECCurve_NIST_K283
-#define ECCurve_SECG_CHAR2_283R1 ECCurve_NIST_B283
-#define ECCurve_SECG_CHAR2_409K1 ECCurve_NIST_K409
-#define ECCurve_SECG_CHAR2_409R1 ECCurve_NIST_B409
-#define ECCurve_SECG_CHAR2_571K1 ECCurve_NIST_K571
-#define ECCurve_SECG_CHAR2_571R1 ECCurve_NIST_B571
-#define ECCurve_WTLS_3 ECCurve_NIST_K163
-#define ECCurve_WTLS_4 ECCurve_SECG_CHAR2_113R1
-#define ECCurve_WTLS_5 ECCurve_X9_62_CHAR2_PNB163V1
-#define ECCurve_WTLS_6 ECCurve_SECG_PRIME_112R1
-#define ECCurve_WTLS_7 ECCurve_SECG_PRIME_160R1
-#define ECCurve_WTLS_10 ECCurve_NIST_K233
-#define ECCurve_WTLS_11 ECCurve_NIST_B233
-#define ECCurve_WTLS_12 ECCurve_NIST_P224
-
-#endif /* _ECL_EXP_H */
--- a/jdk/src/share/native/sun/security/ec/ecl-priv.h	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,304 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Stephen Fung <fungstep@hotmail.com> and
- *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _ECL_PRIV_H
-#define _ECL_PRIV_H
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "ecl.h"
-#include "mpi.h"
-#include "mplogic.h"
-
-/* MAX_FIELD_SIZE_DIGITS is the maximum size of field element supported */
-/* the following needs to go away... */
-#if defined(MP_USE_LONG_LONG_DIGIT) || defined(MP_USE_LONG_DIGIT)
-#define ECL_SIXTY_FOUR_BIT
-#else
-#define ECL_THIRTY_TWO_BIT
-#endif
-
-#define ECL_CURVE_DIGITS(curve_size_in_bits) \
-        (((curve_size_in_bits)+(sizeof(mp_digit)*8-1))/(sizeof(mp_digit)*8))
-#define ECL_BITS (sizeof(mp_digit)*8)
-#define ECL_MAX_FIELD_SIZE_DIGITS (80/sizeof(mp_digit))
-
-/* Gets the i'th bit in the binary representation of a. If i >= length(a),
- * then return 0. (The above behaviour differs from mpl_get_bit, which
- * causes an error if i >= length(a).) */
-#define MP_GET_BIT(a, i) \
-        ((i) >= mpl_significant_bits((a))) ? 0 : mpl_get_bit((a), (i))
-
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD)
-#define MP_ADD_CARRY(a1, a2, s, cin, cout)   \
-    { mp_word w; \
-    w = ((mp_word)(cin)) + (a1) + (a2); \
-    s = ACCUM(w); \
-    cout = CARRYOUT(w); }
-
-#define MP_SUB_BORROW(a1, a2, s, bin, bout)   \
-    { mp_word w; \
-    w = ((mp_word)(a1)) - (a2) - (bin); \
-    s = ACCUM(w); \
-    bout = (w >> MP_DIGIT_BIT) & 1; }
-
-#else
-/* NOTE,
- * cin and cout could be the same variable.
- * bin and bout could be the same variable.
- * a1 or a2 and s could be the same variable.
- * don't trash those outputs until their respective inputs have
- * been read. */
-#define MP_ADD_CARRY(a1, a2, s, cin, cout)   \
-    { mp_digit tmp,sum; \
-    tmp = (a1); \
-    sum = tmp + (a2); \
-    tmp = (sum < tmp);                     /* detect overflow */ \
-    s = sum += (cin); \
-    cout = tmp + (sum < (cin)); }
-
-#define MP_SUB_BORROW(a1, a2, s, bin, bout)   \
-    { mp_digit tmp; \
-    tmp = (a1); \
-    s = tmp - (a2); \
-    tmp = (s > tmp);                    /* detect borrow */ \
-    if ((bin) && !s--) tmp++;   \
-    bout = tmp; }
-#endif
-
-
-struct GFMethodStr;
-typedef struct GFMethodStr GFMethod;
-struct GFMethodStr {
-        /* Indicates whether the structure was constructed from dynamic memory
-         * or statically created. */
-        int constructed;
-        /* Irreducible that defines the field. For prime fields, this is the
-         * prime p. For binary polynomial fields, this is the bitstring
-         * representation of the irreducible polynomial. */
-        mp_int irr;
-        /* For prime fields, the value irr_arr[0] is the number of bits in the
-         * field. For binary polynomial fields, the irreducible polynomial
-         * f(t) is represented as an array of unsigned int[], where f(t) is
-         * of the form: f(t) = t^p[0] + t^p[1] + ... + t^p[4] where m = p[0]
-         * > p[1] > ... > p[4] = 0. */
-        unsigned int irr_arr[5];
-        /* Field arithmetic methods. All methods (except field_enc and
-         * field_dec) are assumed to take field-encoded parameters and return
-         * field-encoded values. All methods (except field_enc and field_dec)
-         * are required to be implemented. */
-        mp_err (*field_add) (const mp_int *a, const mp_int *b, mp_int *r,
-                                                 const GFMethod *meth);
-        mp_err (*field_neg) (const mp_int *a, mp_int *r, const GFMethod *meth);
-        mp_err (*field_sub) (const mp_int *a, const mp_int *b, mp_int *r,
-                                                 const GFMethod *meth);
-        mp_err (*field_mod) (const mp_int *a, mp_int *r, const GFMethod *meth);
-        mp_err (*field_mul) (const mp_int *a, const mp_int *b, mp_int *r,
-                                                 const GFMethod *meth);
-        mp_err (*field_sqr) (const mp_int *a, mp_int *r, const GFMethod *meth);
-        mp_err (*field_div) (const mp_int *a, const mp_int *b, mp_int *r,
-                                                 const GFMethod *meth);
-        mp_err (*field_enc) (const mp_int *a, mp_int *r, const GFMethod *meth);
-        mp_err (*field_dec) (const mp_int *a, mp_int *r, const GFMethod *meth);
-        /* Extra storage for implementation-specific data.  Any memory
-         * allocated to these extra fields will be cleared by extra_free. */
-        void *extra1;
-        void *extra2;
-        void (*extra_free) (GFMethod *meth);
-};
-
-/* Construct generic GFMethods. */
-GFMethod *GFMethod_consGFp(const mp_int *irr);
-GFMethod *GFMethod_consGFp_mont(const mp_int *irr);
-GFMethod *GFMethod_consGF2m(const mp_int *irr,
-                                                        const unsigned int irr_arr[5]);
-/* Free the memory allocated (if any) to a GFMethod object. */
-void GFMethod_free(GFMethod *meth);
-
-struct ECGroupStr {
-        /* Indicates whether the structure was constructed from dynamic memory
-         * or statically created. */
-        int constructed;
-        /* Field definition and arithmetic. */
-        GFMethod *meth;
-        /* Textual representation of curve name, if any. */
-        char *text;
-#ifdef _KERNEL
-        int text_len;
-#endif
-        /* Curve parameters, field-encoded. */
-        mp_int curvea, curveb;
-        /* x and y coordinates of the base point, field-encoded. */
-        mp_int genx, geny;
-        /* Order and cofactor of the base point. */
-        mp_int order;
-        int cofactor;
-        /* Point arithmetic methods. All methods are assumed to take
-         * field-encoded parameters and return field-encoded values. All
-         * methods (except base_point_mul and points_mul) are required to be
-         * implemented. */
-        mp_err (*point_add) (const mp_int *px, const mp_int *py,
-                                                 const mp_int *qx, const mp_int *qy, mp_int *rx,
-                                                 mp_int *ry, const ECGroup *group);
-        mp_err (*point_sub) (const mp_int *px, const mp_int *py,
-                                                 const mp_int *qx, const mp_int *qy, mp_int *rx,
-                                                 mp_int *ry, const ECGroup *group);
-        mp_err (*point_dbl) (const mp_int *px, const mp_int *py, mp_int *rx,
-                                                 mp_int *ry, const ECGroup *group);
-        mp_err (*point_mul) (const mp_int *n, const mp_int *px,
-                                                 const mp_int *py, mp_int *rx, mp_int *ry,
-                                                 const ECGroup *group);
-        mp_err (*base_point_mul) (const mp_int *n, mp_int *rx, mp_int *ry,
-                                                          const ECGroup *group);
-        mp_err (*points_mul) (const mp_int *k1, const mp_int *k2,
-                                                  const mp_int *px, const mp_int *py, mp_int *rx,
-                                                  mp_int *ry, const ECGroup *group);
-        mp_err (*validate_point) (const mp_int *px, const mp_int *py, const ECGroup *group);
-        /* Extra storage for implementation-specific data.  Any memory
-         * allocated to these extra fields will be cleared by extra_free. */
-        void *extra1;
-        void *extra2;
-        void (*extra_free) (ECGroup *group);
-};
-
-/* Wrapper functions for generic prime field arithmetic. */
-mp_err ec_GFp_add(const mp_int *a, const mp_int *b, mp_int *r,
-                                  const GFMethod *meth);
-mp_err ec_GFp_neg(const mp_int *a, mp_int *r, const GFMethod *meth);
-mp_err ec_GFp_sub(const mp_int *a, const mp_int *b, mp_int *r,
-                                  const GFMethod *meth);
-
-/* fixed length in-line adds. Count is in words */
-mp_err ec_GFp_add_3(const mp_int *a, const mp_int *b, mp_int *r,
-                                  const GFMethod *meth);
-mp_err ec_GFp_add_4(const mp_int *a, const mp_int *b, mp_int *r,
-                                  const GFMethod *meth);
-mp_err ec_GFp_add_5(const mp_int *a, const mp_int *b, mp_int *r,
-                                  const GFMethod *meth);
-mp_err ec_GFp_add_6(const mp_int *a, const mp_int *b, mp_int *r,
-                                  const GFMethod *meth);
-mp_err ec_GFp_sub_3(const mp_int *a, const mp_int *b, mp_int *r,
-                                  const GFMethod *meth);
-mp_err ec_GFp_sub_4(const mp_int *a, const mp_int *b, mp_int *r,
-                                  const GFMethod *meth);
-mp_err ec_GFp_sub_5(const mp_int *a, const mp_int *b, mp_int *r,
-                                  const GFMethod *meth);
-mp_err ec_GFp_sub_6(const mp_int *a, const mp_int *b, mp_int *r,
-                                  const GFMethod *meth);
-
-mp_err ec_GFp_mod(const mp_int *a, mp_int *r, const GFMethod *meth);
-mp_err ec_GFp_mul(const mp_int *a, const mp_int *b, mp_int *r,
-                                  const GFMethod *meth);
-mp_err ec_GFp_sqr(const mp_int *a, mp_int *r, const GFMethod *meth);
-mp_err ec_GFp_div(const mp_int *a, const mp_int *b, mp_int *r,
-                                  const GFMethod *meth);
-/* Wrapper functions for generic binary polynomial field arithmetic. */
-mp_err ec_GF2m_add(const mp_int *a, const mp_int *b, mp_int *r,
-                                   const GFMethod *meth);
-mp_err ec_GF2m_neg(const mp_int *a, mp_int *r, const GFMethod *meth);
-mp_err ec_GF2m_mod(const mp_int *a, mp_int *r, const GFMethod *meth);
-mp_err ec_GF2m_mul(const mp_int *a, const mp_int *b, mp_int *r,
-                                   const GFMethod *meth);
-mp_err ec_GF2m_sqr(const mp_int *a, mp_int *r, const GFMethod *meth);
-mp_err ec_GF2m_div(const mp_int *a, const mp_int *b, mp_int *r,
-                                   const GFMethod *meth);
-
-/* Montgomery prime field arithmetic. */
-mp_err ec_GFp_mul_mont(const mp_int *a, const mp_int *b, mp_int *r,
-                                           const GFMethod *meth);
-mp_err ec_GFp_sqr_mont(const mp_int *a, mp_int *r, const GFMethod *meth);
-mp_err ec_GFp_div_mont(const mp_int *a, const mp_int *b, mp_int *r,
-                                           const GFMethod *meth);
-mp_err ec_GFp_enc_mont(const mp_int *a, mp_int *r, const GFMethod *meth);
-mp_err ec_GFp_dec_mont(const mp_int *a, mp_int *r, const GFMethod *meth);
-void ec_GFp_extra_free_mont(GFMethod *meth);
-
-/* point multiplication */
-mp_err ec_pts_mul_basic(const mp_int *k1, const mp_int *k2,
-                                                const mp_int *px, const mp_int *py, mp_int *rx,
-                                                mp_int *ry, const ECGroup *group);
-mp_err ec_pts_mul_simul_w2(const mp_int *k1, const mp_int *k2,
-                                                   const mp_int *px, const mp_int *py, mp_int *rx,
-                                                   mp_int *ry, const ECGroup *group);
-
-/* Computes the windowed non-adjacent-form (NAF) of a scalar. Out should
- * be an array of signed char's to output to, bitsize should be the number
- * of bits of out, in is the original scalar, and w is the window size.
- * NAF is discussed in the paper: D. Hankerson, J. Hernandez and A.
- * Menezes, "Software implementation of elliptic curve cryptography over
- * binary fields", Proc. CHES 2000. */
-mp_err ec_compute_wNAF(signed char *out, int bitsize, const mp_int *in,
-                                           int w);
-
-/* Optimized field arithmetic */
-mp_err ec_group_set_gfp192(ECGroup *group, ECCurveName);
-mp_err ec_group_set_gfp224(ECGroup *group, ECCurveName);
-mp_err ec_group_set_gfp256(ECGroup *group, ECCurveName);
-mp_err ec_group_set_gfp384(ECGroup *group, ECCurveName);
-mp_err ec_group_set_gfp521(ECGroup *group, ECCurveName);
-mp_err ec_group_set_gf2m163(ECGroup *group, ECCurveName name);
-mp_err ec_group_set_gf2m193(ECGroup *group, ECCurveName name);
-mp_err ec_group_set_gf2m233(ECGroup *group, ECCurveName name);
-
-/* Optimized floating-point arithmetic */
-#ifdef ECL_USE_FP
-mp_err ec_group_set_secp160r1_fp(ECGroup *group);
-mp_err ec_group_set_nistp192_fp(ECGroup *group);
-mp_err ec_group_set_nistp224_fp(ECGroup *group);
-#endif
-
-#endif /* _ECL_PRIV_H */
--- a/jdk/src/share/native/sun/security/ec/ecl.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,475 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "mpi.h"
-#include "mplogic.h"
-#include "ecl.h"
-#include "ecl-priv.h"
-#include "ec2.h"
-#include "ecp.h"
-#ifndef _KERNEL
-#include <stdlib.h>
-#include <string.h>
-#endif
-
-/* Allocate memory for a new ECGroup object. */
-ECGroup *
-ECGroup_new(int kmflag)
-{
-        mp_err res = MP_OKAY;
-        ECGroup *group;
-#ifdef _KERNEL
-        group = (ECGroup *) kmem_alloc(sizeof(ECGroup), kmflag);
-#else
-        group = (ECGroup *) malloc(sizeof(ECGroup));
-#endif
-        if (group == NULL)
-                return NULL;
-        group->constructed = MP_YES;
-        group->meth = NULL;
-        group->text = NULL;
-        MP_DIGITS(&group->curvea) = 0;
-        MP_DIGITS(&group->curveb) = 0;
-        MP_DIGITS(&group->genx) = 0;
-        MP_DIGITS(&group->geny) = 0;
-        MP_DIGITS(&group->order) = 0;
-        group->base_point_mul = NULL;
-        group->points_mul = NULL;
-        group->validate_point = NULL;
-        group->extra1 = NULL;
-        group->extra2 = NULL;
-        group->extra_free = NULL;
-        MP_CHECKOK(mp_init(&group->curvea, kmflag));
-        MP_CHECKOK(mp_init(&group->curveb, kmflag));
-        MP_CHECKOK(mp_init(&group->genx, kmflag));
-        MP_CHECKOK(mp_init(&group->geny, kmflag));
-        MP_CHECKOK(mp_init(&group->order, kmflag));
-
-  CLEANUP:
-        if (res != MP_OKAY) {
-                ECGroup_free(group);
-                return NULL;
-        }
-        return group;
-}
-
-/* Construct a generic ECGroup for elliptic curves over prime fields. */
-ECGroup *
-ECGroup_consGFp(const mp_int *irr, const mp_int *curvea,
-                                const mp_int *curveb, const mp_int *genx,
-                                const mp_int *geny, const mp_int *order, int cofactor)
-{
-        mp_err res = MP_OKAY;
-        ECGroup *group = NULL;
-
-        group = ECGroup_new(FLAG(irr));
-        if (group == NULL)
-                return NULL;
-
-        group->meth = GFMethod_consGFp(irr);
-        if (group->meth == NULL) {
-                res = MP_MEM;
-                goto CLEANUP;
-        }
-        MP_CHECKOK(mp_copy(curvea, &group->curvea));
-        MP_CHECKOK(mp_copy(curveb, &group->curveb));
-        MP_CHECKOK(mp_copy(genx, &group->genx));
-        MP_CHECKOK(mp_copy(geny, &group->geny));
-        MP_CHECKOK(mp_copy(order, &group->order));
-        group->cofactor = cofactor;
-        group->point_add = &ec_GFp_pt_add_aff;
-        group->point_sub = &ec_GFp_pt_sub_aff;
-        group->point_dbl = &ec_GFp_pt_dbl_aff;
-        group->point_mul = &ec_GFp_pt_mul_jm_wNAF;
-        group->base_point_mul = NULL;
-        group->points_mul = &ec_GFp_pts_mul_jac;
-        group->validate_point = &ec_GFp_validate_point;
-
-  CLEANUP:
-        if (res != MP_OKAY) {
-                ECGroup_free(group);
-                return NULL;
-        }
-        return group;
-}
-
-/* Construct a generic ECGroup for elliptic curves over prime fields with
- * field arithmetic implemented in Montgomery coordinates. */
-ECGroup *
-ECGroup_consGFp_mont(const mp_int *irr, const mp_int *curvea,
-                                         const mp_int *curveb, const mp_int *genx,
-                                         const mp_int *geny, const mp_int *order, int cofactor)
-{
-        mp_err res = MP_OKAY;
-        ECGroup *group = NULL;
-
-        group = ECGroup_new(FLAG(irr));
-        if (group == NULL)
-                return NULL;
-
-        group->meth = GFMethod_consGFp_mont(irr);
-        if (group->meth == NULL) {
-                res = MP_MEM;
-                goto CLEANUP;
-        }
-        MP_CHECKOK(group->meth->
-                           field_enc(curvea, &group->curvea, group->meth));
-        MP_CHECKOK(group->meth->
-                           field_enc(curveb, &group->curveb, group->meth));
-        MP_CHECKOK(group->meth->field_enc(genx, &group->genx, group->meth));
-        MP_CHECKOK(group->meth->field_enc(geny, &group->geny, group->meth));
-        MP_CHECKOK(mp_copy(order, &group->order));
-        group->cofactor = cofactor;
-        group->point_add = &ec_GFp_pt_add_aff;
-        group->point_sub = &ec_GFp_pt_sub_aff;
-        group->point_dbl = &ec_GFp_pt_dbl_aff;
-        group->point_mul = &ec_GFp_pt_mul_jm_wNAF;
-        group->base_point_mul = NULL;
-        group->points_mul = &ec_GFp_pts_mul_jac;
-        group->validate_point = &ec_GFp_validate_point;
-
-  CLEANUP:
-        if (res != MP_OKAY) {
-                ECGroup_free(group);
-                return NULL;
-        }
-        return group;
-}
-
-#ifdef NSS_ECC_MORE_THAN_SUITE_B
-/* Construct a generic ECGroup for elliptic curves over binary polynomial
- * fields. */
-ECGroup *
-ECGroup_consGF2m(const mp_int *irr, const unsigned int irr_arr[5],
-                                 const mp_int *curvea, const mp_int *curveb,
-                                 const mp_int *genx, const mp_int *geny,
-                                 const mp_int *order, int cofactor)
-{
-        mp_err res = MP_OKAY;
-        ECGroup *group = NULL;
-
-        group = ECGroup_new(FLAG(irr));
-        if (group == NULL)
-                return NULL;
-
-        group->meth = GFMethod_consGF2m(irr, irr_arr);
-        if (group->meth == NULL) {
-                res = MP_MEM;
-                goto CLEANUP;
-        }
-        MP_CHECKOK(mp_copy(curvea, &group->curvea));
-        MP_CHECKOK(mp_copy(curveb, &group->curveb));
-        MP_CHECKOK(mp_copy(genx, &group->genx));
-        MP_CHECKOK(mp_copy(geny, &group->geny));
-        MP_CHECKOK(mp_copy(order, &group->order));
-        group->cofactor = cofactor;
-        group->point_add = &ec_GF2m_pt_add_aff;
-        group->point_sub = &ec_GF2m_pt_sub_aff;
-        group->point_dbl = &ec_GF2m_pt_dbl_aff;
-        group->point_mul = &ec_GF2m_pt_mul_mont;
-        group->base_point_mul = NULL;
-        group->points_mul = &ec_pts_mul_basic;
-        group->validate_point = &ec_GF2m_validate_point;
-
-  CLEANUP:
-        if (res != MP_OKAY) {
-                ECGroup_free(group);
-                return NULL;
-        }
-        return group;
-}
-#endif
-
-/* Construct ECGroup from hex parameters and name, if any. Called by
- * ECGroup_fromHex and ECGroup_fromName. */
-ECGroup *
-ecgroup_fromNameAndHex(const ECCurveName name,
-                                   const ECCurveParams * params, int kmflag)
-{
-        mp_int irr, curvea, curveb, genx, geny, order;
-        int bits;
-        ECGroup *group = NULL;
-        mp_err res = MP_OKAY;
-
-        /* initialize values */
-        MP_DIGITS(&irr) = 0;
-        MP_DIGITS(&curvea) = 0;
-        MP_DIGITS(&curveb) = 0;
-        MP_DIGITS(&genx) = 0;
-        MP_DIGITS(&geny) = 0;
-        MP_DIGITS(&order) = 0;
-        MP_CHECKOK(mp_init(&irr, kmflag));
-        MP_CHECKOK(mp_init(&curvea, kmflag));
-        MP_CHECKOK(mp_init(&curveb, kmflag));
-        MP_CHECKOK(mp_init(&genx, kmflag));
-        MP_CHECKOK(mp_init(&geny, kmflag));
-        MP_CHECKOK(mp_init(&order, kmflag));
-        MP_CHECKOK(mp_read_radix(&irr, params->irr, 16));
-        MP_CHECKOK(mp_read_radix(&curvea, params->curvea, 16));
-        MP_CHECKOK(mp_read_radix(&curveb, params->curveb, 16));
-        MP_CHECKOK(mp_read_radix(&genx, params->genx, 16));
-        MP_CHECKOK(mp_read_radix(&geny, params->geny, 16));
-        MP_CHECKOK(mp_read_radix(&order, params->order, 16));
-
-        /* determine number of bits */
-        bits = mpl_significant_bits(&irr) - 1;
-        if (bits < MP_OKAY) {
-                res = bits;
-                goto CLEANUP;
-        }
-
-        /* determine which optimizations (if any) to use */
-        if (params->field == ECField_GFp) {
-#ifdef NSS_ECC_MORE_THAN_SUITE_B
-            switch (name) {
-#ifdef ECL_USE_FP
-                case ECCurve_SECG_PRIME_160R1:
-                        group =
-                                ECGroup_consGFp(&irr, &curvea, &curveb, &genx, &geny,
-                                                                &order, params->cofactor);
-                        if (group == NULL) { res = MP_UNDEF; goto CLEANUP; }
-                        MP_CHECKOK(ec_group_set_secp160r1_fp(group));
-                        break;
-#endif
-                case ECCurve_SECG_PRIME_192R1:
-#ifdef ECL_USE_FP
-                        group =
-                                ECGroup_consGFp(&irr, &curvea, &curveb, &genx, &geny,
-                                                                &order, params->cofactor);
-                        if (group == NULL) { res = MP_UNDEF; goto CLEANUP; }
-                        MP_CHECKOK(ec_group_set_nistp192_fp(group));
-#else
-                        group =
-                                ECGroup_consGFp(&irr, &curvea, &curveb, &genx, &geny,
-                                                                &order, params->cofactor);
-                        if (group == NULL) { res = MP_UNDEF; goto CLEANUP; }
-                        MP_CHECKOK(ec_group_set_gfp192(group, name));
-#endif
-                        break;
-                case ECCurve_SECG_PRIME_224R1:
-#ifdef ECL_USE_FP
-                        group =
-                                ECGroup_consGFp(&irr, &curvea, &curveb, &genx, &geny,
-                                                                &order, params->cofactor);
-                        if (group == NULL) { res = MP_UNDEF; goto CLEANUP; }
-                        MP_CHECKOK(ec_group_set_nistp224_fp(group));
-#else
-                        group =
-                                ECGroup_consGFp(&irr, &curvea, &curveb, &genx, &geny,
-                                                                &order, params->cofactor);
-                        if (group == NULL) { res = MP_UNDEF; goto CLEANUP; }
-                        MP_CHECKOK(ec_group_set_gfp224(group, name));
-#endif
-                        break;
-                case ECCurve_SECG_PRIME_256R1:
-                        group =
-                                ECGroup_consGFp(&irr, &curvea, &curveb, &genx, &geny,
-                                                                &order, params->cofactor);
-                        if (group == NULL) { res = MP_UNDEF; goto CLEANUP; }
-                        MP_CHECKOK(ec_group_set_gfp256(group, name));
-                        break;
-                case ECCurve_SECG_PRIME_521R1:
-                        group =
-                                ECGroup_consGFp(&irr, &curvea, &curveb, &genx, &geny,
-                                                                &order, params->cofactor);
-                        if (group == NULL) { res = MP_UNDEF; goto CLEANUP; }
-                        MP_CHECKOK(ec_group_set_gfp521(group, name));
-                        break;
-                default:
-                        /* use generic arithmetic */
-#endif
-                        group =
-                                ECGroup_consGFp_mont(&irr, &curvea, &curveb, &genx, &geny,
-                                                                         &order, params->cofactor);
-                        if (group == NULL) { res = MP_UNDEF; goto CLEANUP; }
-#ifdef NSS_ECC_MORE_THAN_SUITE_B
-                }
-        } else if (params->field == ECField_GF2m) {
-                group = ECGroup_consGF2m(&irr, NULL, &curvea, &curveb, &genx, &geny, &order, params->cofactor);
-                if (group == NULL) { res = MP_UNDEF; goto CLEANUP; }
-                if ((name == ECCurve_NIST_K163) ||
-                    (name == ECCurve_NIST_B163) ||
-                    (name == ECCurve_SECG_CHAR2_163R1)) {
-                        MP_CHECKOK(ec_group_set_gf2m163(group, name));
-                } else if ((name == ECCurve_SECG_CHAR2_193R1) ||
-                           (name == ECCurve_SECG_CHAR2_193R2)) {
-                        MP_CHECKOK(ec_group_set_gf2m193(group, name));
-                } else if ((name == ECCurve_NIST_K233) ||
-                           (name == ECCurve_NIST_B233)) {
-                        MP_CHECKOK(ec_group_set_gf2m233(group, name));
-                }
-#endif
-        } else {
-                res = MP_UNDEF;
-                goto CLEANUP;
-        }
-
-        /* set name, if any */
-        if ((group != NULL) && (params->text != NULL)) {
-#ifdef _KERNEL
-                int n = strlen(params->text) + 1;
-
-                group->text = kmem_alloc(n, kmflag);
-                if (group->text == NULL) {
-                        res = MP_MEM;
-                        goto CLEANUP;
-                }
-                bcopy(params->text, group->text, n);
-                group->text_len = n;
-#else
-                group->text = strdup(params->text);
-                if (group->text == NULL) {
-                        res = MP_MEM;
-                }
-#endif
-        }
-
-  CLEANUP:
-        mp_clear(&irr);
-        mp_clear(&curvea);
-        mp_clear(&curveb);
-        mp_clear(&genx);
-        mp_clear(&geny);
-        mp_clear(&order);
-        if (res != MP_OKAY) {
-                ECGroup_free(group);
-                return NULL;
-        }
-        return group;
-}
-
-/* Construct ECGroup from hexadecimal representations of parameters. */
-ECGroup *
-ECGroup_fromHex(const ECCurveParams * params, int kmflag)
-{
-        return ecgroup_fromNameAndHex(ECCurve_noName, params, kmflag);
-}
-
-/* Construct ECGroup from named parameters. */
-ECGroup *
-ECGroup_fromName(const ECCurveName name, int kmflag)
-{
-        ECGroup *group = NULL;
-        ECCurveParams *params = NULL;
-        mp_err res = MP_OKAY;
-
-        params = EC_GetNamedCurveParams(name, kmflag);
-        if (params == NULL) {
-                res = MP_UNDEF;
-                goto CLEANUP;
-        }
-
-        /* construct actual group */
-        group = ecgroup_fromNameAndHex(name, params, kmflag);
-        if (group == NULL) {
-                res = MP_UNDEF;
-                goto CLEANUP;
-        }
-
-  CLEANUP:
-        EC_FreeCurveParams(params);
-        if (res != MP_OKAY) {
-                ECGroup_free(group);
-                return NULL;
-        }
-        return group;
-}
-
-/* Validates an EC public key as described in Section 5.2.2 of X9.62. */
-mp_err ECPoint_validate(const ECGroup *group, const mp_int *px, const
-                                        mp_int *py)
-{
-    /* 1: Verify that publicValue is not the point at infinity */
-    /* 2: Verify that the coordinates of publicValue are elements
-     *    of the field.
-     */
-    /* 3: Verify that publicValue is on the curve. */
-    /* 4: Verify that the order of the curve times the publicValue
-     *    is the point at infinity.
-     */
-        return group->validate_point(px, py, group);
-}
-
-/* Free the memory allocated (if any) to an ECGroup object. */
-void
-ECGroup_free(ECGroup *group)
-{
-        if (group == NULL)
-                return;
-        GFMethod_free(group->meth);
-        if (group->constructed == MP_NO)
-                return;
-        mp_clear(&group->curvea);
-        mp_clear(&group->curveb);
-        mp_clear(&group->genx);
-        mp_clear(&group->geny);
-        mp_clear(&group->order);
-        if (group->text != NULL)
-#ifdef _KERNEL
-                kmem_free(group->text, group->text_len);
-#else
-                free(group->text);
-#endif
-        if (group->extra_free != NULL)
-                group->extra_free(group);
-#ifdef _KERNEL
-        kmem_free(group, sizeof (ECGroup));
-#else
-        free(group);
-#endif
-}
--- a/jdk/src/share/native/sun/security/ec/ecl.h	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,111 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _ECL_H
-#define _ECL_H
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-/* Although this is not an exported header file, code which uses elliptic
- * curve point operations will need to include it. */
-
-#include "ecl-exp.h"
-#include "mpi.h"
-
-struct ECGroupStr;
-typedef struct ECGroupStr ECGroup;
-
-/* Construct ECGroup from hexadecimal representations of parameters. */
-ECGroup *ECGroup_fromHex(const ECCurveParams * params, int kmflag);
-
-/* Construct ECGroup from named parameters. */
-ECGroup *ECGroup_fromName(const ECCurveName name, int kmflag);
-
-/* Free an allocated ECGroup. */
-void ECGroup_free(ECGroup *group);
-
-/* Construct ECCurveParams from an ECCurveName */
-ECCurveParams *EC_GetNamedCurveParams(const ECCurveName name, int kmflag);
-
-/* Duplicates an ECCurveParams */
-ECCurveParams *ECCurveParams_dup(const ECCurveParams * params, int kmflag);
-
-/* Free an allocated ECCurveParams */
-void EC_FreeCurveParams(ECCurveParams * params);
-
-/* Elliptic curve scalar-point multiplication. Computes Q(x, y) = k * P(x,
- * y).  If x, y = NULL, then P is assumed to be the generator (base point)
- * of the group of points on the elliptic curve. Input and output values
- * are assumed to be NOT field-encoded. */
-mp_err ECPoint_mul(const ECGroup *group, const mp_int *k, const mp_int *px,
-                                   const mp_int *py, mp_int *qx, mp_int *qy);
-
-/* Elliptic curve scalar-point multiplication. Computes Q(x, y) = k1 * G +
- * k2 * P(x, y), where G is the generator (base point) of the group of
- * points on the elliptic curve. Input and output values are assumed to
- * be NOT field-encoded. */
-mp_err ECPoints_mul(const ECGroup *group, const mp_int *k1,
-                                        const mp_int *k2, const mp_int *px, const mp_int *py,
-                                        mp_int *qx, mp_int *qy);
-
-/* Validates an EC public key as described in Section 5.2.2 of X9.62.
- * Returns MP_YES if the public key is valid, MP_NO if the public key
- * is invalid, or an error code if the validation could not be
- * performed. */
-mp_err ECPoint_validate(const ECGroup *group, const mp_int *px, const
-                                        mp_int *py);
-
-#endif /* _ECL_H */
--- a/jdk/src/share/native/sun/security/ec/ecl_curve.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,216 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "ecl.h"
-#include "ecl-curve.h"
-#include "ecl-priv.h"
-#ifndef _KERNEL
-#include <stdlib.h>
-#include <string.h>
-#endif
-
-#define CHECK(func) if ((func) == NULL) { res = 0; goto CLEANUP; }
-
-/* Duplicates an ECCurveParams */
-ECCurveParams *
-ECCurveParams_dup(const ECCurveParams * params, int kmflag)
-{
-        int res = 1;
-        ECCurveParams *ret = NULL;
-
-#ifdef _KERNEL
-        ret = (ECCurveParams *) kmem_zalloc(sizeof(ECCurveParams), kmflag);
-#else
-        CHECK(ret = (ECCurveParams *) calloc(1, sizeof(ECCurveParams)));
-#endif
-        if (params->text != NULL) {
-#ifdef _KERNEL
-                ret->text = kmem_alloc(strlen(params->text) + 1, kmflag);
-                bcopy(params->text, ret->text, strlen(params->text) + 1);
-#else
-                CHECK(ret->text = strdup(params->text));
-#endif
-        }
-        ret->field = params->field;
-        ret->size = params->size;
-        if (params->irr != NULL) {
-#ifdef _KERNEL
-                ret->irr = kmem_alloc(strlen(params->irr) + 1, kmflag);
-                bcopy(params->irr, ret->irr, strlen(params->irr) + 1);
-#else
-                CHECK(ret->irr = strdup(params->irr));
-#endif
-        }
-        if (params->curvea != NULL) {
-#ifdef _KERNEL
-                ret->curvea = kmem_alloc(strlen(params->curvea) + 1, kmflag);
-                bcopy(params->curvea, ret->curvea, strlen(params->curvea) + 1);
-#else
-                CHECK(ret->curvea = strdup(params->curvea));
-#endif
-        }
-        if (params->curveb != NULL) {
-#ifdef _KERNEL
-                ret->curveb = kmem_alloc(strlen(params->curveb) + 1, kmflag);
-                bcopy(params->curveb, ret->curveb, strlen(params->curveb) + 1);
-#else
-                CHECK(ret->curveb = strdup(params->curveb));
-#endif
-        }
-        if (params->genx != NULL) {
-#ifdef _KERNEL
-                ret->genx = kmem_alloc(strlen(params->genx) + 1, kmflag);
-                bcopy(params->genx, ret->genx, strlen(params->genx) + 1);
-#else
-                CHECK(ret->genx = strdup(params->genx));
-#endif
-        }
-        if (params->geny != NULL) {
-#ifdef _KERNEL
-                ret->geny = kmem_alloc(strlen(params->geny) + 1, kmflag);
-                bcopy(params->geny, ret->geny, strlen(params->geny) + 1);
-#else
-                CHECK(ret->geny = strdup(params->geny));
-#endif
-        }
-        if (params->order != NULL) {
-#ifdef _KERNEL
-                ret->order = kmem_alloc(strlen(params->order) + 1, kmflag);
-                bcopy(params->order, ret->order, strlen(params->order) + 1);
-#else
-                CHECK(ret->order = strdup(params->order));
-#endif
-        }
-        ret->cofactor = params->cofactor;
-
-  CLEANUP:
-        if (res != 1) {
-                EC_FreeCurveParams(ret);
-                return NULL;
-        }
-        return ret;
-}
-
-#undef CHECK
-
-/* Construct ECCurveParams from an ECCurveName */
-ECCurveParams *
-EC_GetNamedCurveParams(const ECCurveName name, int kmflag)
-{
-        if ((name <= ECCurve_noName) || (ECCurve_pastLastCurve <= name) ||
-                                        (ecCurve_map[name] == NULL)) {
-                return NULL;
-        } else {
-                return ECCurveParams_dup(ecCurve_map[name], kmflag);
-        }
-}
-
-/* Free the memory allocated (if any) to an ECCurveParams object. */
-void
-EC_FreeCurveParams(ECCurveParams * params)
-{
-        if (params == NULL)
-                return;
-        if (params->text != NULL)
-#ifdef _KERNEL
-                kmem_free(params->text, strlen(params->text) + 1);
-#else
-                free(params->text);
-#endif
-        if (params->irr != NULL)
-#ifdef _KERNEL
-                kmem_free(params->irr, strlen(params->irr) + 1);
-#else
-                free(params->irr);
-#endif
-        if (params->curvea != NULL)
-#ifdef _KERNEL
-                kmem_free(params->curvea, strlen(params->curvea) + 1);
-#else
-                free(params->curvea);
-#endif
-        if (params->curveb != NULL)
-#ifdef _KERNEL
-                kmem_free(params->curveb, strlen(params->curveb) + 1);
-#else
-                free(params->curveb);
-#endif
-        if (params->genx != NULL)
-#ifdef _KERNEL
-                kmem_free(params->genx, strlen(params->genx) + 1);
-#else
-                free(params->genx);
-#endif
-        if (params->geny != NULL)
-#ifdef _KERNEL
-                kmem_free(params->geny, strlen(params->geny) + 1);
-#else
-                free(params->geny);
-#endif
-        if (params->order != NULL)
-#ifdef _KERNEL
-                kmem_free(params->order, strlen(params->order) + 1);
-#else
-                free(params->order);
-#endif
-#ifdef _KERNEL
-        kmem_free(params, sizeof(ECCurveParams));
-#else
-        free(params);
-#endif
-}
--- a/jdk/src/share/native/sun/security/ec/ecl_gf.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1062 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Stephen Fung <fungstep@hotmail.com> and
- *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "mpi.h"
-#include "mp_gf2m.h"
-#include "ecl-priv.h"
-#include "mpi-priv.h"
-#ifndef _KERNEL
-#include <stdlib.h>
-#endif
-
-/* Allocate memory for a new GFMethod object. */
-GFMethod *
-GFMethod_new(int kmflag)
-{
-        mp_err res = MP_OKAY;
-        GFMethod *meth;
-#ifdef _KERNEL
-        meth = (GFMethod *) kmem_alloc(sizeof(GFMethod), kmflag);
-#else
-        meth = (GFMethod *) malloc(sizeof(GFMethod));
-        if (meth == NULL)
-                return NULL;
-#endif
-        meth->constructed = MP_YES;
-        MP_DIGITS(&meth->irr) = 0;
-        meth->extra_free = NULL;
-        MP_CHECKOK(mp_init(&meth->irr, kmflag));
-
-  CLEANUP:
-        if (res != MP_OKAY) {
-                GFMethod_free(meth);
-                return NULL;
-        }
-        return meth;
-}
-
-/* Construct a generic GFMethod for arithmetic over prime fields with
- * irreducible irr. */
-GFMethod *
-GFMethod_consGFp(const mp_int *irr)
-{
-        mp_err res = MP_OKAY;
-        GFMethod *meth = NULL;
-
-        meth = GFMethod_new(FLAG(irr));
-        if (meth == NULL)
-                return NULL;
-
-        MP_CHECKOK(mp_copy(irr, &meth->irr));
-        meth->irr_arr[0] = mpl_significant_bits(irr);
-        meth->irr_arr[1] = meth->irr_arr[2] = meth->irr_arr[3] =
-                meth->irr_arr[4] = 0;
-        switch(MP_USED(&meth->irr)) {
-        /* maybe we need 1 and 2 words here as well?*/
-        case 3:
-                meth->field_add = &ec_GFp_add_3;
-                meth->field_sub = &ec_GFp_sub_3;
-                break;
-        case 4:
-                meth->field_add = &ec_GFp_add_4;
-                meth->field_sub = &ec_GFp_sub_4;
-                break;
-        case 5:
-                meth->field_add = &ec_GFp_add_5;
-                meth->field_sub = &ec_GFp_sub_5;
-                break;
-        case 6:
-                meth->field_add = &ec_GFp_add_6;
-                meth->field_sub = &ec_GFp_sub_6;
-                break;
-        default:
-                meth->field_add = &ec_GFp_add;
-                meth->field_sub = &ec_GFp_sub;
-        }
-        meth->field_neg = &ec_GFp_neg;
-        meth->field_mod = &ec_GFp_mod;
-        meth->field_mul = &ec_GFp_mul;
-        meth->field_sqr = &ec_GFp_sqr;
-        meth->field_div = &ec_GFp_div;
-        meth->field_enc = NULL;
-        meth->field_dec = NULL;
-        meth->extra1 = NULL;
-        meth->extra2 = NULL;
-        meth->extra_free = NULL;
-
-  CLEANUP:
-        if (res != MP_OKAY) {
-                GFMethod_free(meth);
-                return NULL;
-        }
-        return meth;
-}
-
-/* Construct a generic GFMethod for arithmetic over binary polynomial
- * fields with irreducible irr that has array representation irr_arr (see
- * ecl-priv.h for description of the representation).  If irr_arr is NULL,
- * then it is constructed from the bitstring representation. */
-GFMethod *
-GFMethod_consGF2m(const mp_int *irr, const unsigned int irr_arr[5])
-{
-        mp_err res = MP_OKAY;
-        int ret;
-        GFMethod *meth = NULL;
-
-        meth = GFMethod_new(FLAG(irr));
-        if (meth == NULL)
-                return NULL;
-
-        MP_CHECKOK(mp_copy(irr, &meth->irr));
-        if (irr_arr != NULL) {
-                /* Irreducible polynomials are either trinomials or pentanomials. */
-                meth->irr_arr[0] = irr_arr[0];
-                meth->irr_arr[1] = irr_arr[1];
-                meth->irr_arr[2] = irr_arr[2];
-                if (irr_arr[2] > 0) {
-                        meth->irr_arr[3] = irr_arr[3];
-                        meth->irr_arr[4] = irr_arr[4];
-                } else {
-                        meth->irr_arr[3] = meth->irr_arr[4] = 0;
-                }
-        } else {
-                ret = mp_bpoly2arr(irr, meth->irr_arr, 5);
-                /* Irreducible polynomials are either trinomials or pentanomials. */
-                if ((ret != 5) && (ret != 3)) {
-                        res = MP_UNDEF;
-                        goto CLEANUP;
-                }
-        }
-        meth->field_add = &ec_GF2m_add;
-        meth->field_neg = &ec_GF2m_neg;
-        meth->field_sub = &ec_GF2m_add;
-        meth->field_mod = &ec_GF2m_mod;
-        meth->field_mul = &ec_GF2m_mul;
-        meth->field_sqr = &ec_GF2m_sqr;
-        meth->field_div = &ec_GF2m_div;
-        meth->field_enc = NULL;
-        meth->field_dec = NULL;
-        meth->extra1 = NULL;
-        meth->extra2 = NULL;
-        meth->extra_free = NULL;
-
-  CLEANUP:
-        if (res != MP_OKAY) {
-                GFMethod_free(meth);
-                return NULL;
-        }
-        return meth;
-}
-
-/* Free the memory allocated (if any) to a GFMethod object. */
-void
-GFMethod_free(GFMethod *meth)
-{
-        if (meth == NULL)
-                return;
-        if (meth->constructed == MP_NO)
-                return;
-        mp_clear(&meth->irr);
-        if (meth->extra_free != NULL)
-                meth->extra_free(meth);
-#ifdef _KERNEL
-        kmem_free(meth, sizeof(GFMethod));
-#else
-        free(meth);
-#endif
-}
-
-/* Wrapper functions for generic prime field arithmetic. */
-
-/* Add two field elements.  Assumes that 0 <= a, b < meth->irr */
-mp_err
-ec_GFp_add(const mp_int *a, const mp_int *b, mp_int *r,
-                   const GFMethod *meth)
-{
-        /* PRE: 0 <= a, b < p = meth->irr POST: 0 <= r < p, r = a + b (mod p) */
-        mp_err res;
-
-        if ((res = mp_add(a, b, r)) != MP_OKAY) {
-                return res;
-        }
-        if (mp_cmp(r, &meth->irr) >= 0) {
-                return mp_sub(r, &meth->irr, r);
-        }
-        return res;
-}
-
-/* Negates a field element.  Assumes that 0 <= a < meth->irr */
-mp_err
-ec_GFp_neg(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        /* PRE: 0 <= a < p = meth->irr POST: 0 <= r < p, r = -a (mod p) */
-
-        if (mp_cmp_z(a) == 0) {
-                mp_zero(r);
-                return MP_OKAY;
-        }
-        return mp_sub(&meth->irr, a, r);
-}
-
-/* Subtracts two field elements.  Assumes that 0 <= a, b < meth->irr */
-mp_err
-ec_GFp_sub(const mp_int *a, const mp_int *b, mp_int *r,
-                   const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-
-        /* PRE: 0 <= a, b < p = meth->irr POST: 0 <= r < p, r = a - b (mod p) */
-        res = mp_sub(a, b, r);
-        if (res == MP_RANGE) {
-                MP_CHECKOK(mp_sub(b, a, r));
-                if (mp_cmp_z(r) < 0) {
-                        MP_CHECKOK(mp_add(r, &meth->irr, r));
-                }
-                MP_CHECKOK(ec_GFp_neg(r, r, meth));
-        }
-        if (mp_cmp_z(r) < 0) {
-                MP_CHECKOK(mp_add(r, &meth->irr, r));
-        }
-  CLEANUP:
-        return res;
-}
-/*
- * Inline adds for small curve lengths.
- */
-/* 3 words */
-mp_err
-ec_GFp_add_3(const mp_int *a, const mp_int *b, mp_int *r,
-                        const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_digit a0 = 0, a1 = 0, a2 = 0;
-        mp_digit r0 = 0, r1 = 0, r2 = 0;
-        mp_digit carry;
-
-        switch(MP_USED(a)) {
-        case 3:
-                a2 = MP_DIGIT(a,2);
-        case 2:
-                a1 = MP_DIGIT(a,1);
-        case 1:
-                a0 = MP_DIGIT(a,0);
-        }
-        switch(MP_USED(b)) {
-        case 3:
-                r2 = MP_DIGIT(b,2);
-        case 2:
-                r1 = MP_DIGIT(b,1);
-        case 1:
-                r0 = MP_DIGIT(b,0);
-        }
-
-#ifndef MPI_AMD64_ADD
-        MP_ADD_CARRY(a0, r0, r0, 0,     carry);
-        MP_ADD_CARRY(a1, r1, r1, carry, carry);
-        MP_ADD_CARRY(a2, r2, r2, carry, carry);
-#else
-        __asm__ (
-                "xorq   %3,%3           \n\t"
-                "addq   %4,%0           \n\t"
-                "adcq   %5,%1           \n\t"
-                "adcq   %6,%2           \n\t"
-                "adcq   $0,%3           \n\t"
-                : "=r"(r0), "=r"(r1), "=r"(r2), "=r"(carry)
-                : "r" (a0), "r" (a1), "r" (a2),
-                  "0" (r0), "1" (r1), "2" (r2)
-                : "%cc" );
-#endif
-
-        MP_CHECKOK(s_mp_pad(r, 3));
-        MP_DIGIT(r, 2) = r2;
-        MP_DIGIT(r, 1) = r1;
-        MP_DIGIT(r, 0) = r0;
-        MP_SIGN(r) = MP_ZPOS;
-        MP_USED(r) = 3;
-
-        /* Do quick 'subract' if we've gone over
-         * (add the 2's complement of the curve field) */
-         a2 = MP_DIGIT(&meth->irr,2);
-        if (carry ||  r2 >  a2 ||
-                ((r2 == a2) && mp_cmp(r,&meth->irr) != MP_LT)) {
-                a1 = MP_DIGIT(&meth->irr,1);
-                a0 = MP_DIGIT(&meth->irr,0);
-#ifndef MPI_AMD64_ADD
-                MP_SUB_BORROW(r0, a0, r0, 0,     carry);
-                MP_SUB_BORROW(r1, a1, r1, carry, carry);
-                MP_SUB_BORROW(r2, a2, r2, carry, carry);
-#else
-                __asm__ (
-                        "subq   %3,%0           \n\t"
-                        "sbbq   %4,%1           \n\t"
-                        "sbbq   %5,%2           \n\t"
-                        : "=r"(r0), "=r"(r1), "=r"(r2)
-                        : "r" (a0), "r" (a1), "r" (a2),
-                          "0" (r0), "1" (r1), "2" (r2)
-                        : "%cc" );
-#endif
-                MP_DIGIT(r, 2) = r2;
-                MP_DIGIT(r, 1) = r1;
-                MP_DIGIT(r, 0) = r0;
-        }
-
-        s_mp_clamp(r);
-
-  CLEANUP:
-        return res;
-}
-
-/* 4 words */
-mp_err
-ec_GFp_add_4(const mp_int *a, const mp_int *b, mp_int *r,
-                        const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_digit a0 = 0, a1 = 0, a2 = 0, a3 = 0;
-        mp_digit r0 = 0, r1 = 0, r2 = 0, r3 = 0;
-        mp_digit carry;
-
-        switch(MP_USED(a)) {
-        case 4:
-                a3 = MP_DIGIT(a,3);
-        case 3:
-                a2 = MP_DIGIT(a,2);
-        case 2:
-                a1 = MP_DIGIT(a,1);
-        case 1:
-                a0 = MP_DIGIT(a,0);
-        }
-        switch(MP_USED(b)) {
-        case 4:
-                r3 = MP_DIGIT(b,3);
-        case 3:
-                r2 = MP_DIGIT(b,2);
-        case 2:
-                r1 = MP_DIGIT(b,1);
-        case 1:
-                r0 = MP_DIGIT(b,0);
-        }
-
-#ifndef MPI_AMD64_ADD
-        MP_ADD_CARRY(a0, r0, r0, 0,     carry);
-        MP_ADD_CARRY(a1, r1, r1, carry, carry);
-        MP_ADD_CARRY(a2, r2, r2, carry, carry);
-        MP_ADD_CARRY(a3, r3, r3, carry, carry);
-#else
-        __asm__ (
-                "xorq   %4,%4           \n\t"
-                "addq   %5,%0           \n\t"
-                "adcq   %6,%1           \n\t"
-                "adcq   %7,%2           \n\t"
-                "adcq   %8,%3           \n\t"
-                "adcq   $0,%4           \n\t"
-                : "=r"(r0), "=r"(r1), "=r"(r2), "=r"(r3), "=r"(carry)
-                : "r" (a0), "r" (a1), "r" (a2), "r" (a3),
-                  "0" (r0), "1" (r1), "2" (r2), "3" (r3)
-                : "%cc" );
-#endif
-
-        MP_CHECKOK(s_mp_pad(r, 4));
-        MP_DIGIT(r, 3) = r3;
-        MP_DIGIT(r, 2) = r2;
-        MP_DIGIT(r, 1) = r1;
-        MP_DIGIT(r, 0) = r0;
-        MP_SIGN(r) = MP_ZPOS;
-        MP_USED(r) = 4;
-
-        /* Do quick 'subract' if we've gone over
-         * (add the 2's complement of the curve field) */
-         a3 = MP_DIGIT(&meth->irr,3);
-        if (carry ||  r3 >  a3 ||
-                ((r3 == a3) && mp_cmp(r,&meth->irr) != MP_LT)) {
-                a2 = MP_DIGIT(&meth->irr,2);
-                a1 = MP_DIGIT(&meth->irr,1);
-                a0 = MP_DIGIT(&meth->irr,0);
-#ifndef MPI_AMD64_ADD
-                MP_SUB_BORROW(r0, a0, r0, 0,     carry);
-                MP_SUB_BORROW(r1, a1, r1, carry, carry);
-                MP_SUB_BORROW(r2, a2, r2, carry, carry);
-                MP_SUB_BORROW(r3, a3, r3, carry, carry);
-#else
-                __asm__ (
-                        "subq   %4,%0           \n\t"
-                        "sbbq   %5,%1           \n\t"
-                        "sbbq   %6,%2           \n\t"
-                        "sbbq   %7,%3           \n\t"
-                        : "=r"(r0), "=r"(r1), "=r"(r2), "=r"(r3)
-                        : "r" (a0), "r" (a1), "r" (a2), "r" (a3),
-                          "0" (r0), "1" (r1), "2" (r2), "3" (r3)
-                        : "%cc" );
-#endif
-                MP_DIGIT(r, 3) = r3;
-                MP_DIGIT(r, 2) = r2;
-                MP_DIGIT(r, 1) = r1;
-                MP_DIGIT(r, 0) = r0;
-        }
-
-        s_mp_clamp(r);
-
-  CLEANUP:
-        return res;
-}
-
-/* 5 words */
-mp_err
-ec_GFp_add_5(const mp_int *a, const mp_int *b, mp_int *r,
-                        const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_digit a0 = 0, a1 = 0, a2 = 0, a3 = 0, a4 = 0;
-        mp_digit r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0;
-        mp_digit carry;
-
-        switch(MP_USED(a)) {
-        case 5:
-                a4 = MP_DIGIT(a,4);
-        case 4:
-                a3 = MP_DIGIT(a,3);
-        case 3:
-                a2 = MP_DIGIT(a,2);
-        case 2:
-                a1 = MP_DIGIT(a,1);
-        case 1:
-                a0 = MP_DIGIT(a,0);
-        }
-        switch(MP_USED(b)) {
-        case 5:
-                r4 = MP_DIGIT(b,4);
-        case 4:
-                r3 = MP_DIGIT(b,3);
-        case 3:
-                r2 = MP_DIGIT(b,2);
-        case 2:
-                r1 = MP_DIGIT(b,1);
-        case 1:
-                r0 = MP_DIGIT(b,0);
-        }
-
-        MP_ADD_CARRY(a0, r0, r0, 0,     carry);
-        MP_ADD_CARRY(a1, r1, r1, carry, carry);
-        MP_ADD_CARRY(a2, r2, r2, carry, carry);
-        MP_ADD_CARRY(a3, r3, r3, carry, carry);
-        MP_ADD_CARRY(a4, r4, r4, carry, carry);
-
-        MP_CHECKOK(s_mp_pad(r, 5));
-        MP_DIGIT(r, 4) = r4;
-        MP_DIGIT(r, 3) = r3;
-        MP_DIGIT(r, 2) = r2;
-        MP_DIGIT(r, 1) = r1;
-        MP_DIGIT(r, 0) = r0;
-        MP_SIGN(r) = MP_ZPOS;
-        MP_USED(r) = 5;
-
-        /* Do quick 'subract' if we've gone over
-         * (add the 2's complement of the curve field) */
-         a4 = MP_DIGIT(&meth->irr,4);
-        if (carry ||  r4 >  a4 ||
-                ((r4 == a4) && mp_cmp(r,&meth->irr) != MP_LT)) {
-                a3 = MP_DIGIT(&meth->irr,3);
-                a2 = MP_DIGIT(&meth->irr,2);
-                a1 = MP_DIGIT(&meth->irr,1);
-                a0 = MP_DIGIT(&meth->irr,0);
-                MP_SUB_BORROW(r0, a0, r0, 0,     carry);
-                MP_SUB_BORROW(r1, a1, r1, carry, carry);
-                MP_SUB_BORROW(r2, a2, r2, carry, carry);
-                MP_SUB_BORROW(r3, a3, r3, carry, carry);
-                MP_SUB_BORROW(r4, a4, r4, carry, carry);
-                MP_DIGIT(r, 4) = r4;
-                MP_DIGIT(r, 3) = r3;
-                MP_DIGIT(r, 2) = r2;
-                MP_DIGIT(r, 1) = r1;
-                MP_DIGIT(r, 0) = r0;
-        }
-
-        s_mp_clamp(r);
-
-  CLEANUP:
-        return res;
-}
-
-/* 6 words */
-mp_err
-ec_GFp_add_6(const mp_int *a, const mp_int *b, mp_int *r,
-                        const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_digit a0 = 0, a1 = 0, a2 = 0, a3 = 0, a4 = 0, a5 = 0;
-        mp_digit r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0, r5 = 0;
-        mp_digit carry;
-
-        switch(MP_USED(a)) {
-        case 6:
-                a5 = MP_DIGIT(a,5);
-        case 5:
-                a4 = MP_DIGIT(a,4);
-        case 4:
-                a3 = MP_DIGIT(a,3);
-        case 3:
-                a2 = MP_DIGIT(a,2);
-        case 2:
-                a1 = MP_DIGIT(a,1);
-        case 1:
-                a0 = MP_DIGIT(a,0);
-        }
-        switch(MP_USED(b)) {
-        case 6:
-                r5 = MP_DIGIT(b,5);
-        case 5:
-                r4 = MP_DIGIT(b,4);
-        case 4:
-                r3 = MP_DIGIT(b,3);
-        case 3:
-                r2 = MP_DIGIT(b,2);
-        case 2:
-                r1 = MP_DIGIT(b,1);
-        case 1:
-                r0 = MP_DIGIT(b,0);
-        }
-
-        MP_ADD_CARRY(a0, r0, r0, 0,     carry);
-        MP_ADD_CARRY(a1, r1, r1, carry, carry);
-        MP_ADD_CARRY(a2, r2, r2, carry, carry);
-        MP_ADD_CARRY(a3, r3, r3, carry, carry);
-        MP_ADD_CARRY(a4, r4, r4, carry, carry);
-        MP_ADD_CARRY(a5, r5, r5, carry, carry);
-
-        MP_CHECKOK(s_mp_pad(r, 6));
-        MP_DIGIT(r, 5) = r5;
-        MP_DIGIT(r, 4) = r4;
-        MP_DIGIT(r, 3) = r3;
-        MP_DIGIT(r, 2) = r2;
-        MP_DIGIT(r, 1) = r1;
-        MP_DIGIT(r, 0) = r0;
-        MP_SIGN(r) = MP_ZPOS;
-        MP_USED(r) = 6;
-
-        /* Do quick 'subract' if we've gone over
-         * (add the 2's complement of the curve field) */
-        a5 = MP_DIGIT(&meth->irr,5);
-        if (carry ||  r5 >  a5 ||
-                ((r5 == a5) && mp_cmp(r,&meth->irr) != MP_LT)) {
-                a4 = MP_DIGIT(&meth->irr,4);
-                a3 = MP_DIGIT(&meth->irr,3);
-                a2 = MP_DIGIT(&meth->irr,2);
-                a1 = MP_DIGIT(&meth->irr,1);
-                a0 = MP_DIGIT(&meth->irr,0);
-                MP_SUB_BORROW(r0, a0, r0, 0,     carry);
-                MP_SUB_BORROW(r1, a1, r1, carry, carry);
-                MP_SUB_BORROW(r2, a2, r2, carry, carry);
-                MP_SUB_BORROW(r3, a3, r3, carry, carry);
-                MP_SUB_BORROW(r4, a4, r4, carry, carry);
-                MP_SUB_BORROW(r5, a5, r5, carry, carry);
-                MP_DIGIT(r, 5) = r5;
-                MP_DIGIT(r, 4) = r4;
-                MP_DIGIT(r, 3) = r3;
-                MP_DIGIT(r, 2) = r2;
-                MP_DIGIT(r, 1) = r1;
-                MP_DIGIT(r, 0) = r0;
-        }
-
-        s_mp_clamp(r);
-
-  CLEANUP:
-        return res;
-}
-
-/*
- * The following subraction functions do in-line subractions based
- * on our curve size.
- *
- * ... 3 words
- */
-mp_err
-ec_GFp_sub_3(const mp_int *a, const mp_int *b, mp_int *r,
-                        const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_digit b0 = 0, b1 = 0, b2 = 0;
-        mp_digit r0 = 0, r1 = 0, r2 = 0;
-        mp_digit borrow;
-
-        switch(MP_USED(a)) {
-        case 3:
-                r2 = MP_DIGIT(a,2);
-        case 2:
-                r1 = MP_DIGIT(a,1);
-        case 1:
-                r0 = MP_DIGIT(a,0);
-        }
-        switch(MP_USED(b)) {
-        case 3:
-                b2 = MP_DIGIT(b,2);
-        case 2:
-                b1 = MP_DIGIT(b,1);
-        case 1:
-                b0 = MP_DIGIT(b,0);
-        }
-
-#ifndef MPI_AMD64_ADD
-        MP_SUB_BORROW(r0, b0, r0, 0,     borrow);
-        MP_SUB_BORROW(r1, b1, r1, borrow, borrow);
-        MP_SUB_BORROW(r2, b2, r2, borrow, borrow);
-#else
-        __asm__ (
-                "xorq   %3,%3           \n\t"
-                "subq   %4,%0           \n\t"
-                "sbbq   %5,%1           \n\t"
-                "sbbq   %6,%2           \n\t"
-                "adcq   $0,%3           \n\t"
-                : "=r"(r0), "=r"(r1), "=r"(r2), "=r" (borrow)
-                : "r" (b0), "r" (b1), "r" (b2),
-                  "0" (r0), "1" (r1), "2" (r2)
-                : "%cc" );
-#endif
-
-        /* Do quick 'add' if we've gone under 0
-         * (subtract the 2's complement of the curve field) */
-        if (borrow) {
-                b2 = MP_DIGIT(&meth->irr,2);
-                b1 = MP_DIGIT(&meth->irr,1);
-                b0 = MP_DIGIT(&meth->irr,0);
-#ifndef MPI_AMD64_ADD
-                MP_ADD_CARRY(b0, r0, r0, 0,      borrow);
-                MP_ADD_CARRY(b1, r1, r1, borrow, borrow);
-                MP_ADD_CARRY(b2, r2, r2, borrow, borrow);
-#else
-                __asm__ (
-                        "addq   %3,%0           \n\t"
-                        "adcq   %4,%1           \n\t"
-                        "adcq   %5,%2           \n\t"
-                        : "=r"(r0), "=r"(r1), "=r"(r2)
-                        : "r" (b0), "r" (b1), "r" (b2),
-                          "0" (r0), "1" (r1), "2" (r2)
-                        : "%cc" );
-#endif
-        }
-
-#ifdef MPI_AMD64_ADD
-        /* compiler fakeout? */
-        if ((r2 == b0) && (r1 == b0) && (r0 == b0)) {
-                MP_CHECKOK(s_mp_pad(r, 4));
-        }
-#endif
-        MP_CHECKOK(s_mp_pad(r, 3));
-        MP_DIGIT(r, 2) = r2;
-        MP_DIGIT(r, 1) = r1;
-        MP_DIGIT(r, 0) = r0;
-        MP_SIGN(r) = MP_ZPOS;
-        MP_USED(r) = 3;
-        s_mp_clamp(r);
-
-  CLEANUP:
-        return res;
-}
-
-/* 4 words */
-mp_err
-ec_GFp_sub_4(const mp_int *a, const mp_int *b, mp_int *r,
-                        const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_digit b0 = 0, b1 = 0, b2 = 0, b3 = 0;
-        mp_digit r0 = 0, r1 = 0, r2 = 0, r3 = 0;
-        mp_digit borrow;
-
-        switch(MP_USED(a)) {
-        case 4:
-                r3 = MP_DIGIT(a,3);
-        case 3:
-                r2 = MP_DIGIT(a,2);
-        case 2:
-                r1 = MP_DIGIT(a,1);
-        case 1:
-                r0 = MP_DIGIT(a,0);
-        }
-        switch(MP_USED(b)) {
-        case 4:
-                b3 = MP_DIGIT(b,3);
-        case 3:
-                b2 = MP_DIGIT(b,2);
-        case 2:
-                b1 = MP_DIGIT(b,1);
-        case 1:
-                b0 = MP_DIGIT(b,0);
-        }
-
-#ifndef MPI_AMD64_ADD
-        MP_SUB_BORROW(r0, b0, r0, 0,     borrow);
-        MP_SUB_BORROW(r1, b1, r1, borrow, borrow);
-        MP_SUB_BORROW(r2, b2, r2, borrow, borrow);
-        MP_SUB_BORROW(r3, b3, r3, borrow, borrow);
-#else
-        __asm__ (
-                "xorq   %4,%4           \n\t"
-                "subq   %5,%0           \n\t"
-                "sbbq   %6,%1           \n\t"
-                "sbbq   %7,%2           \n\t"
-                "sbbq   %8,%3           \n\t"
-                "adcq   $0,%4           \n\t"
-                : "=r"(r0), "=r"(r1), "=r"(r2), "=r"(r3), "=r" (borrow)
-                : "r" (b0), "r" (b1), "r" (b2), "r" (b3),
-                  "0" (r0), "1" (r1), "2" (r2), "3" (r3)
-                : "%cc" );
-#endif
-
-        /* Do quick 'add' if we've gone under 0
-         * (subtract the 2's complement of the curve field) */
-        if (borrow) {
-                b3 = MP_DIGIT(&meth->irr,3);
-                b2 = MP_DIGIT(&meth->irr,2);
-                b1 = MP_DIGIT(&meth->irr,1);
-                b0 = MP_DIGIT(&meth->irr,0);
-#ifndef MPI_AMD64_ADD
-                MP_ADD_CARRY(b0, r0, r0, 0,      borrow);
-                MP_ADD_CARRY(b1, r1, r1, borrow, borrow);
-                MP_ADD_CARRY(b2, r2, r2, borrow, borrow);
-                MP_ADD_CARRY(b3, r3, r3, borrow, borrow);
-#else
-                __asm__ (
-                        "addq   %4,%0           \n\t"
-                        "adcq   %5,%1           \n\t"
-                        "adcq   %6,%2           \n\t"
-                        "adcq   %7,%3           \n\t"
-                        : "=r"(r0), "=r"(r1), "=r"(r2), "=r"(r3)
-                        : "r" (b0), "r" (b1), "r" (b2), "r" (b3),
-                          "0" (r0), "1" (r1), "2" (r2), "3" (r3)
-                        : "%cc" );
-#endif
-        }
-#ifdef MPI_AMD64_ADD
-        /* compiler fakeout? */
-        if ((r3 == b0) && (r1 == b0) && (r0 == b0)) {
-                MP_CHECKOK(s_mp_pad(r, 4));
-        }
-#endif
-        MP_CHECKOK(s_mp_pad(r, 4));
-        MP_DIGIT(r, 3) = r3;
-        MP_DIGIT(r, 2) = r2;
-        MP_DIGIT(r, 1) = r1;
-        MP_DIGIT(r, 0) = r0;
-        MP_SIGN(r) = MP_ZPOS;
-        MP_USED(r) = 4;
-        s_mp_clamp(r);
-
-  CLEANUP:
-        return res;
-}
-
-/* 5 words */
-mp_err
-ec_GFp_sub_5(const mp_int *a, const mp_int *b, mp_int *r,
-                        const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_digit b0 = 0, b1 = 0, b2 = 0, b3 = 0, b4 = 0;
-        mp_digit r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0;
-        mp_digit borrow;
-
-        switch(MP_USED(a)) {
-        case 5:
-                r4 = MP_DIGIT(a,4);
-        case 4:
-                r3 = MP_DIGIT(a,3);
-        case 3:
-                r2 = MP_DIGIT(a,2);
-        case 2:
-                r1 = MP_DIGIT(a,1);
-        case 1:
-                r0 = MP_DIGIT(a,0);
-        }
-        switch(MP_USED(b)) {
-        case 5:
-                b4 = MP_DIGIT(b,4);
-        case 4:
-                b3 = MP_DIGIT(b,3);
-        case 3:
-                b2 = MP_DIGIT(b,2);
-        case 2:
-                b1 = MP_DIGIT(b,1);
-        case 1:
-                b0 = MP_DIGIT(b,0);
-        }
-
-        MP_SUB_BORROW(r0, b0, r0, 0,     borrow);
-        MP_SUB_BORROW(r1, b1, r1, borrow, borrow);
-        MP_SUB_BORROW(r2, b2, r2, borrow, borrow);
-        MP_SUB_BORROW(r3, b3, r3, borrow, borrow);
-        MP_SUB_BORROW(r4, b4, r4, borrow, borrow);
-
-        /* Do quick 'add' if we've gone under 0
-         * (subtract the 2's complement of the curve field) */
-        if (borrow) {
-                b4 = MP_DIGIT(&meth->irr,4);
-                b3 = MP_DIGIT(&meth->irr,3);
-                b2 = MP_DIGIT(&meth->irr,2);
-                b1 = MP_DIGIT(&meth->irr,1);
-                b0 = MP_DIGIT(&meth->irr,0);
-                MP_ADD_CARRY(b0, r0, r0, 0,      borrow);
-                MP_ADD_CARRY(b1, r1, r1, borrow, borrow);
-                MP_ADD_CARRY(b2, r2, r2, borrow, borrow);
-                MP_ADD_CARRY(b3, r3, r3, borrow, borrow);
-        }
-        MP_CHECKOK(s_mp_pad(r, 5));
-        MP_DIGIT(r, 4) = r4;
-        MP_DIGIT(r, 3) = r3;
-        MP_DIGIT(r, 2) = r2;
-        MP_DIGIT(r, 1) = r1;
-        MP_DIGIT(r, 0) = r0;
-        MP_SIGN(r) = MP_ZPOS;
-        MP_USED(r) = 5;
-        s_mp_clamp(r);
-
-  CLEANUP:
-        return res;
-}
-
-/* 6 words */
-mp_err
-ec_GFp_sub_6(const mp_int *a, const mp_int *b, mp_int *r,
-                        const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_digit b0 = 0, b1 = 0, b2 = 0, b3 = 0, b4 = 0, b5 = 0;
-        mp_digit r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0, r5 = 0;
-        mp_digit borrow;
-
-        switch(MP_USED(a)) {
-        case 6:
-                r5 = MP_DIGIT(a,5);
-        case 5:
-                r4 = MP_DIGIT(a,4);
-        case 4:
-                r3 = MP_DIGIT(a,3);
-        case 3:
-                r2 = MP_DIGIT(a,2);
-        case 2:
-                r1 = MP_DIGIT(a,1);
-        case 1:
-                r0 = MP_DIGIT(a,0);
-        }
-        switch(MP_USED(b)) {
-        case 6:
-                b5 = MP_DIGIT(b,5);
-        case 5:
-                b4 = MP_DIGIT(b,4);
-        case 4:
-                b3 = MP_DIGIT(b,3);
-        case 3:
-                b2 = MP_DIGIT(b,2);
-        case 2:
-                b1 = MP_DIGIT(b,1);
-        case 1:
-                b0 = MP_DIGIT(b,0);
-        }
-
-        MP_SUB_BORROW(r0, b0, r0, 0,     borrow);
-        MP_SUB_BORROW(r1, b1, r1, borrow, borrow);
-        MP_SUB_BORROW(r2, b2, r2, borrow, borrow);
-        MP_SUB_BORROW(r3, b3, r3, borrow, borrow);
-        MP_SUB_BORROW(r4, b4, r4, borrow, borrow);
-        MP_SUB_BORROW(r5, b5, r5, borrow, borrow);
-
-        /* Do quick 'add' if we've gone under 0
-         * (subtract the 2's complement of the curve field) */
-        if (borrow) {
-                b5 = MP_DIGIT(&meth->irr,5);
-                b4 = MP_DIGIT(&meth->irr,4);
-                b3 = MP_DIGIT(&meth->irr,3);
-                b2 = MP_DIGIT(&meth->irr,2);
-                b1 = MP_DIGIT(&meth->irr,1);
-                b0 = MP_DIGIT(&meth->irr,0);
-                MP_ADD_CARRY(b0, r0, r0, 0,      borrow);
-                MP_ADD_CARRY(b1, r1, r1, borrow, borrow);
-                MP_ADD_CARRY(b2, r2, r2, borrow, borrow);
-                MP_ADD_CARRY(b3, r3, r3, borrow, borrow);
-                MP_ADD_CARRY(b4, r4, r4, borrow, borrow);
-        }
-
-        MP_CHECKOK(s_mp_pad(r, 6));
-        MP_DIGIT(r, 5) = r5;
-        MP_DIGIT(r, 4) = r4;
-        MP_DIGIT(r, 3) = r3;
-        MP_DIGIT(r, 2) = r2;
-        MP_DIGIT(r, 1) = r1;
-        MP_DIGIT(r, 0) = r0;
-        MP_SIGN(r) = MP_ZPOS;
-        MP_USED(r) = 6;
-        s_mp_clamp(r);
-
-  CLEANUP:
-        return res;
-}
-
-
-/* Reduces an integer to a field element. */
-mp_err
-ec_GFp_mod(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        return mp_mod(a, &meth->irr, r);
-}
-
-/* Multiplies two field elements. */
-mp_err
-ec_GFp_mul(const mp_int *a, const mp_int *b, mp_int *r,
-                   const GFMethod *meth)
-{
-        return mp_mulmod(a, b, &meth->irr, r);
-}
-
-/* Squares a field element. */
-mp_err
-ec_GFp_sqr(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        return mp_sqrmod(a, &meth->irr, r);
-}
-
-/* Divides two field elements. If a is NULL, then returns the inverse of
- * b. */
-mp_err
-ec_GFp_div(const mp_int *a, const mp_int *b, mp_int *r,
-                   const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_int t;
-
-        /* If a is NULL, then return the inverse of b, otherwise return a/b. */
-        if (a == NULL) {
-                return mp_invmod(b, &meth->irr, r);
-        } else {
-                /* MPI doesn't support divmod, so we implement it using invmod and
-                 * mulmod. */
-                MP_CHECKOK(mp_init(&t, FLAG(b)));
-                MP_CHECKOK(mp_invmod(b, &meth->irr, &t));
-                MP_CHECKOK(mp_mulmod(a, &t, &meth->irr, r));
-          CLEANUP:
-                mp_clear(&t);
-                return res;
-        }
-}
-
-/* Wrapper functions for generic binary polynomial field arithmetic. */
-
-/* Adds two field elements. */
-mp_err
-ec_GF2m_add(const mp_int *a, const mp_int *b, mp_int *r,
-                        const GFMethod *meth)
-{
-        return mp_badd(a, b, r);
-}
-
-/* Negates a field element. Note that for binary polynomial fields, the
- * negation of a field element is the field element itself. */
-mp_err
-ec_GF2m_neg(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        if (a == r) {
-                return MP_OKAY;
-        } else {
-                return mp_copy(a, r);
-        }
-}
-
-/* Reduces a binary polynomial to a field element. */
-mp_err
-ec_GF2m_mod(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        return mp_bmod(a, meth->irr_arr, r);
-}
-
-/* Multiplies two field elements. */
-mp_err
-ec_GF2m_mul(const mp_int *a, const mp_int *b, mp_int *r,
-                        const GFMethod *meth)
-{
-        return mp_bmulmod(a, b, meth->irr_arr, r);
-}
-
-/* Squares a field element. */
-mp_err
-ec_GF2m_sqr(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        return mp_bsqrmod(a, meth->irr_arr, r);
-}
-
-/* Divides two field elements. If a is NULL, then returns the inverse of
- * b. */
-mp_err
-ec_GF2m_div(const mp_int *a, const mp_int *b, mp_int *r,
-                        const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_int t;
-
-        /* If a is NULL, then return the inverse of b, otherwise return a/b. */
-        if (a == NULL) {
-                /* The GF(2^m) portion of MPI doesn't support invmod, so we
-                 * compute 1/b. */
-                MP_CHECKOK(mp_init(&t, FLAG(b)));
-                MP_CHECKOK(mp_set_int(&t, 1));
-                MP_CHECKOK(mp_bdivmod(&t, b, &meth->irr, meth->irr_arr, r));
-          CLEANUP:
-                mp_clear(&t);
-                return res;
-        } else {
-                return mp_bdivmod(a, b, &meth->irr, meth->irr_arr, r);
-        }
-}
--- a/jdk/src/share/native/sun/security/ec/ecl_mult.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,378 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "mpi.h"
-#include "mplogic.h"
-#include "ecl.h"
-#include "ecl-priv.h"
-#ifndef _KERNEL
-#include <stdlib.h>
-#endif
-
-/* Elliptic curve scalar-point multiplication. Computes R(x, y) = k * P(x,
- * y).  If x, y = NULL, then P is assumed to be the generator (base point)
- * of the group of points on the elliptic curve. Input and output values
- * are assumed to be NOT field-encoded. */
-mp_err
-ECPoint_mul(const ECGroup *group, const mp_int *k, const mp_int *px,
-                        const mp_int *py, mp_int *rx, mp_int *ry)
-{
-        mp_err res = MP_OKAY;
-        mp_int kt;
-
-        ARGCHK((k != NULL) && (group != NULL), MP_BADARG);
-        MP_DIGITS(&kt) = 0;
-
-        /* want scalar to be less than or equal to group order */
-        if (mp_cmp(k, &group->order) > 0) {
-                MP_CHECKOK(mp_init(&kt, FLAG(k)));
-                MP_CHECKOK(mp_mod(k, &group->order, &kt));
-        } else {
-                MP_SIGN(&kt) = MP_ZPOS;
-                MP_USED(&kt) = MP_USED(k);
-                MP_ALLOC(&kt) = MP_ALLOC(k);
-                MP_DIGITS(&kt) = MP_DIGITS(k);
-        }
-
-        if ((px == NULL) || (py == NULL)) {
-                if (group->base_point_mul) {
-                        MP_CHECKOK(group->base_point_mul(&kt, rx, ry, group));
-                } else {
-                        MP_CHECKOK(group->
-                                           point_mul(&kt, &group->genx, &group->geny, rx, ry,
-                                                                 group));
-                }
-        } else {
-                if (group->meth->field_enc) {
-                        MP_CHECKOK(group->meth->field_enc(px, rx, group->meth));
-                        MP_CHECKOK(group->meth->field_enc(py, ry, group->meth));
-                        MP_CHECKOK(group->point_mul(&kt, rx, ry, rx, ry, group));
-                } else {
-                        MP_CHECKOK(group->point_mul(&kt, px, py, rx, ry, group));
-                }
-        }
-        if (group->meth->field_dec) {
-                MP_CHECKOK(group->meth->field_dec(rx, rx, group->meth));
-                MP_CHECKOK(group->meth->field_dec(ry, ry, group->meth));
-        }
-
-  CLEANUP:
-        if (MP_DIGITS(&kt) != MP_DIGITS(k)) {
-                mp_clear(&kt);
-        }
-        return res;
-}
-
-/* Elliptic curve scalar-point multiplication. Computes R(x, y) = k1 * G +
- * k2 * P(x, y), where G is the generator (base point) of the group of
- * points on the elliptic curve. Allows k1 = NULL or { k2, P } = NULL.
- * Input and output values are assumed to be NOT field-encoded. */
-mp_err
-ec_pts_mul_basic(const mp_int *k1, const mp_int *k2, const mp_int *px,
-                                 const mp_int *py, mp_int *rx, mp_int *ry,
-                                 const ECGroup *group)
-{
-        mp_err res = MP_OKAY;
-        mp_int sx, sy;
-
-        ARGCHK(group != NULL, MP_BADARG);
-        ARGCHK(!((k1 == NULL)
-                         && ((k2 == NULL) || (px == NULL)
-                                 || (py == NULL))), MP_BADARG);
-
-        /* if some arguments are not defined used ECPoint_mul */
-        if (k1 == NULL) {
-                return ECPoint_mul(group, k2, px, py, rx, ry);
-        } else if ((k2 == NULL) || (px == NULL) || (py == NULL)) {
-                return ECPoint_mul(group, k1, NULL, NULL, rx, ry);
-        }
-
-        MP_DIGITS(&sx) = 0;
-        MP_DIGITS(&sy) = 0;
-        MP_CHECKOK(mp_init(&sx, FLAG(k1)));
-        MP_CHECKOK(mp_init(&sy, FLAG(k1)));
-
-        MP_CHECKOK(ECPoint_mul(group, k1, NULL, NULL, &sx, &sy));
-        MP_CHECKOK(ECPoint_mul(group, k2, px, py, rx, ry));
-
-        if (group->meth->field_enc) {
-                MP_CHECKOK(group->meth->field_enc(&sx, &sx, group->meth));
-                MP_CHECKOK(group->meth->field_enc(&sy, &sy, group->meth));
-                MP_CHECKOK(group->meth->field_enc(rx, rx, group->meth));
-                MP_CHECKOK(group->meth->field_enc(ry, ry, group->meth));
-        }
-
-        MP_CHECKOK(group->point_add(&sx, &sy, rx, ry, rx, ry, group));
-
-        if (group->meth->field_dec) {
-                MP_CHECKOK(group->meth->field_dec(rx, rx, group->meth));
-                MP_CHECKOK(group->meth->field_dec(ry, ry, group->meth));
-        }
-
-  CLEANUP:
-        mp_clear(&sx);
-        mp_clear(&sy);
-        return res;
-}
-
-/* Elliptic curve scalar-point multiplication. Computes R(x, y) = k1 * G +
- * k2 * P(x, y), where G is the generator (base point) of the group of
- * points on the elliptic curve. Allows k1 = NULL or { k2, P } = NULL.
- * Input and output values are assumed to be NOT field-encoded. Uses
- * algorithm 15 (simultaneous multiple point multiplication) from Brown,
- * Hankerson, Lopez, Menezes. Software Implementation of the NIST
- * Elliptic Curves over Prime Fields. */
-mp_err
-ec_pts_mul_simul_w2(const mp_int *k1, const mp_int *k2, const mp_int *px,
-                                        const mp_int *py, mp_int *rx, mp_int *ry,
-                                        const ECGroup *group)
-{
-        mp_err res = MP_OKAY;
-        mp_int precomp[4][4][2];
-        const mp_int *a, *b;
-        int i, j;
-        int ai, bi, d;
-
-        ARGCHK(group != NULL, MP_BADARG);
-        ARGCHK(!((k1 == NULL)
-                         && ((k2 == NULL) || (px == NULL)
-                                 || (py == NULL))), MP_BADARG);
-
-        /* if some arguments are not defined used ECPoint_mul */
-        if (k1 == NULL) {
-                return ECPoint_mul(group, k2, px, py, rx, ry);
-        } else if ((k2 == NULL) || (px == NULL) || (py == NULL)) {
-                return ECPoint_mul(group, k1, NULL, NULL, rx, ry);
-        }
-
-        /* initialize precomputation table */
-        for (i = 0; i < 4; i++) {
-                for (j = 0; j < 4; j++) {
-                        MP_DIGITS(&precomp[i][j][0]) = 0;
-                        MP_DIGITS(&precomp[i][j][1]) = 0;
-                }
-        }
-        for (i = 0; i < 4; i++) {
-                for (j = 0; j < 4; j++) {
-                         MP_CHECKOK( mp_init_size(&precomp[i][j][0],
-                                         ECL_MAX_FIELD_SIZE_DIGITS, FLAG(k1)) );
-                         MP_CHECKOK( mp_init_size(&precomp[i][j][1],
-                                         ECL_MAX_FIELD_SIZE_DIGITS, FLAG(k1)) );
-                }
-        }
-
-        /* fill precomputation table */
-        /* assign {k1, k2} = {a, b} such that len(a) >= len(b) */
-        if (mpl_significant_bits(k1) < mpl_significant_bits(k2)) {
-                a = k2;
-                b = k1;
-                if (group->meth->field_enc) {
-                        MP_CHECKOK(group->meth->
-                                           field_enc(px, &precomp[1][0][0], group->meth));
-                        MP_CHECKOK(group->meth->
-                                           field_enc(py, &precomp[1][0][1], group->meth));
-                } else {
-                        MP_CHECKOK(mp_copy(px, &precomp[1][0][0]));
-                        MP_CHECKOK(mp_copy(py, &precomp[1][0][1]));
-                }
-                MP_CHECKOK(mp_copy(&group->genx, &precomp[0][1][0]));
-                MP_CHECKOK(mp_copy(&group->geny, &precomp[0][1][1]));
-        } else {
-                a = k1;
-                b = k2;
-                MP_CHECKOK(mp_copy(&group->genx, &precomp[1][0][0]));
-                MP_CHECKOK(mp_copy(&group->geny, &precomp[1][0][1]));
-                if (group->meth->field_enc) {
-                        MP_CHECKOK(group->meth->
-                                           field_enc(px, &precomp[0][1][0], group->meth));
-                        MP_CHECKOK(group->meth->
-                                           field_enc(py, &precomp[0][1][1], group->meth));
-                } else {
-                        MP_CHECKOK(mp_copy(px, &precomp[0][1][0]));
-                        MP_CHECKOK(mp_copy(py, &precomp[0][1][1]));
-                }
-        }
-        /* precompute [*][0][*] */
-        mp_zero(&precomp[0][0][0]);
-        mp_zero(&precomp[0][0][1]);
-        MP_CHECKOK(group->
-                           point_dbl(&precomp[1][0][0], &precomp[1][0][1],
-                                                 &precomp[2][0][0], &precomp[2][0][1], group));
-        MP_CHECKOK(group->
-                           point_add(&precomp[1][0][0], &precomp[1][0][1],
-                                                 &precomp[2][0][0], &precomp[2][0][1],
-                                                 &precomp[3][0][0], &precomp[3][0][1], group));
-        /* precompute [*][1][*] */
-        for (i = 1; i < 4; i++) {
-                MP_CHECKOK(group->
-                                   point_add(&precomp[0][1][0], &precomp[0][1][1],
-                                                         &precomp[i][0][0], &precomp[i][0][1],
-                                                         &precomp[i][1][0], &precomp[i][1][1], group));
-        }
-        /* precompute [*][2][*] */
-        MP_CHECKOK(group->
-                           point_dbl(&precomp[0][1][0], &precomp[0][1][1],
-                                                 &precomp[0][2][0], &precomp[0][2][1], group));
-        for (i = 1; i < 4; i++) {
-                MP_CHECKOK(group->
-                                   point_add(&precomp[0][2][0], &precomp[0][2][1],
-                                                         &precomp[i][0][0], &precomp[i][0][1],
-                                                         &precomp[i][2][0], &precomp[i][2][1], group));
-        }
-        /* precompute [*][3][*] */
-        MP_CHECKOK(group->
-                           point_add(&precomp[0][1][0], &precomp[0][1][1],
-                                                 &precomp[0][2][0], &precomp[0][2][1],
-                                                 &precomp[0][3][0], &precomp[0][3][1], group));
-        for (i = 1; i < 4; i++) {
-                MP_CHECKOK(group->
-                                   point_add(&precomp[0][3][0], &precomp[0][3][1],
-                                                         &precomp[i][0][0], &precomp[i][0][1],
-                                                         &precomp[i][3][0], &precomp[i][3][1], group));
-        }
-
-        d = (mpl_significant_bits(a) + 1) / 2;
-
-        /* R = inf */
-        mp_zero(rx);
-        mp_zero(ry);
-
-        for (i = d - 1; i >= 0; i--) {
-                ai = MP_GET_BIT(a, 2 * i + 1);
-                ai <<= 1;
-                ai |= MP_GET_BIT(a, 2 * i);
-                bi = MP_GET_BIT(b, 2 * i + 1);
-                bi <<= 1;
-                bi |= MP_GET_BIT(b, 2 * i);
-                /* R = 2^2 * R */
-                MP_CHECKOK(group->point_dbl(rx, ry, rx, ry, group));
-                MP_CHECKOK(group->point_dbl(rx, ry, rx, ry, group));
-                /* R = R + (ai * A + bi * B) */
-                MP_CHECKOK(group->
-                                   point_add(rx, ry, &precomp[ai][bi][0],
-                                                         &precomp[ai][bi][1], rx, ry, group));
-        }
-
-        if (group->meth->field_dec) {
-                MP_CHECKOK(group->meth->field_dec(rx, rx, group->meth));
-                MP_CHECKOK(group->meth->field_dec(ry, ry, group->meth));
-        }
-
-  CLEANUP:
-        for (i = 0; i < 4; i++) {
-                for (j = 0; j < 4; j++) {
-                        mp_clear(&precomp[i][j][0]);
-                        mp_clear(&precomp[i][j][1]);
-                }
-        }
-        return res;
-}
-
-/* Elliptic curve scalar-point multiplication. Computes R(x, y) = k1 * G +
- * k2 * P(x, y), where G is the generator (base point) of the group of
- * points on the elliptic curve. Allows k1 = NULL or { k2, P } = NULL.
- * Input and output values are assumed to be NOT field-encoded. */
-mp_err
-ECPoints_mul(const ECGroup *group, const mp_int *k1, const mp_int *k2,
-                         const mp_int *px, const mp_int *py, mp_int *rx, mp_int *ry)
-{
-        mp_err res = MP_OKAY;
-        mp_int k1t, k2t;
-        const mp_int *k1p, *k2p;
-
-        MP_DIGITS(&k1t) = 0;
-        MP_DIGITS(&k2t) = 0;
-
-        ARGCHK(group != NULL, MP_BADARG);
-
-        /* want scalar to be less than or equal to group order */
-        if (k1 != NULL) {
-                if (mp_cmp(k1, &group->order) >= 0) {
-                        MP_CHECKOK(mp_init(&k1t, FLAG(k1)));
-                        MP_CHECKOK(mp_mod(k1, &group->order, &k1t));
-                        k1p = &k1t;
-                } else {
-                        k1p = k1;
-                }
-        } else {
-                k1p = k1;
-        }
-        if (k2 != NULL) {
-                if (mp_cmp(k2, &group->order) >= 0) {
-                        MP_CHECKOK(mp_init(&k2t, FLAG(k2)));
-                        MP_CHECKOK(mp_mod(k2, &group->order, &k2t));
-                        k2p = &k2t;
-                } else {
-                        k2p = k2;
-                }
-        } else {
-                k2p = k2;
-        }
-
-        /* if points_mul is defined, then use it */
-        if (group->points_mul) {
-                res = group->points_mul(k1p, k2p, px, py, rx, ry, group);
-        } else {
-                res = ec_pts_mul_simul_w2(k1p, k2p, px, py, rx, ry, group);
-        }
-
-  CLEANUP:
-        mp_clear(&k1t);
-        mp_clear(&k2t);
-        return res;
-}
--- a/jdk/src/share/native/sun/security/ec/ecp.h	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,160 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library for prime field curves.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _ECP_H
-#define _ECP_H
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "ecl-priv.h"
-
-/* Checks if point P(px, py) is at infinity.  Uses affine coordinates. */
-mp_err ec_GFp_pt_is_inf_aff(const mp_int *px, const mp_int *py);
-
-/* Sets P(px, py) to be the point at infinity.  Uses affine coordinates. */
-mp_err ec_GFp_pt_set_inf_aff(mp_int *px, mp_int *py);
-
-/* Computes R = P + Q where R is (rx, ry), P is (px, py) and Q is (qx,
- * qy). Uses affine coordinates. */
-mp_err ec_GFp_pt_add_aff(const mp_int *px, const mp_int *py,
-                                                 const mp_int *qx, const mp_int *qy, mp_int *rx,
-                                                 mp_int *ry, const ECGroup *group);
-
-/* Computes R = P - Q.  Uses affine coordinates. */
-mp_err ec_GFp_pt_sub_aff(const mp_int *px, const mp_int *py,
-                                                 const mp_int *qx, const mp_int *qy, mp_int *rx,
-                                                 mp_int *ry, const ECGroup *group);
-
-/* Computes R = 2P.  Uses affine coordinates. */
-mp_err ec_GFp_pt_dbl_aff(const mp_int *px, const mp_int *py, mp_int *rx,
-                                                 mp_int *ry, const ECGroup *group);
-
-/* Validates a point on a GFp curve. */
-mp_err ec_GFp_validate_point(const mp_int *px, const mp_int *py, const ECGroup *group);
-
-#ifdef ECL_ENABLE_GFP_PT_MUL_AFF
-/* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters
- * a, b and p are the elliptic curve coefficients and the prime that
- * determines the field GFp.  Uses affine coordinates. */
-mp_err ec_GFp_pt_mul_aff(const mp_int *n, const mp_int *px,
-                                                 const mp_int *py, mp_int *rx, mp_int *ry,
-                                                 const ECGroup *group);
-#endif
-
-/* Converts a point P(px, py) from affine coordinates to Jacobian
- * projective coordinates R(rx, ry, rz). */
-mp_err ec_GFp_pt_aff2jac(const mp_int *px, const mp_int *py, mp_int *rx,
-                                                 mp_int *ry, mp_int *rz, const ECGroup *group);
-
-/* Converts a point P(px, py, pz) from Jacobian projective coordinates to
- * affine coordinates R(rx, ry). */
-mp_err ec_GFp_pt_jac2aff(const mp_int *px, const mp_int *py,
-                                                 const mp_int *pz, mp_int *rx, mp_int *ry,
-                                                 const ECGroup *group);
-
-/* Checks if point P(px, py, pz) is at infinity.  Uses Jacobian
- * coordinates. */
-mp_err ec_GFp_pt_is_inf_jac(const mp_int *px, const mp_int *py,
-                                                        const mp_int *pz);
-
-/* Sets P(px, py, pz) to be the point at infinity.  Uses Jacobian
- * coordinates. */
-mp_err ec_GFp_pt_set_inf_jac(mp_int *px, mp_int *py, mp_int *pz);
-
-/* Computes R = P + Q where R is (rx, ry, rz), P is (px, py, pz) and Q is
- * (qx, qy, qz).  Uses Jacobian coordinates. */
-mp_err ec_GFp_pt_add_jac_aff(const mp_int *px, const mp_int *py,
-                                                         const mp_int *pz, const mp_int *qx,
-                                                         const mp_int *qy, mp_int *rx, mp_int *ry,
-                                                         mp_int *rz, const ECGroup *group);
-
-/* Computes R = 2P.  Uses Jacobian coordinates. */
-mp_err ec_GFp_pt_dbl_jac(const mp_int *px, const mp_int *py,
-                                                 const mp_int *pz, mp_int *rx, mp_int *ry,
-                                                 mp_int *rz, const ECGroup *group);
-
-#ifdef ECL_ENABLE_GFP_PT_MUL_JAC
-/* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters
- * a, b and p are the elliptic curve coefficients and the prime that
- * determines the field GFp.  Uses Jacobian coordinates. */
-mp_err ec_GFp_pt_mul_jac(const mp_int *n, const mp_int *px,
-                                                 const mp_int *py, mp_int *rx, mp_int *ry,
-                                                 const ECGroup *group);
-#endif
-
-/* Computes R(x, y) = k1 * G + k2 * P(x, y), where G is the generator
- * (base point) of the group of points on the elliptic curve. Allows k1 =
- * NULL or { k2, P } = NULL.  Implemented using mixed Jacobian-affine
- * coordinates. Input and output values are assumed to be NOT
- * field-encoded and are in affine form. */
-mp_err
- ec_GFp_pts_mul_jac(const mp_int *k1, const mp_int *k2, const mp_int *px,
-                                        const mp_int *py, mp_int *rx, mp_int *ry,
-                                        const ECGroup *group);
-
-/* Computes R = nP where R is (rx, ry) and P is the base point. Elliptic
- * curve points P and R can be identical. Uses mixed Modified-Jacobian
- * co-ordinates for doubling and Chudnovsky Jacobian coordinates for
- * additions. Assumes input is already field-encoded using field_enc, and
- * returns output that is still field-encoded. Uses 5-bit window NAF
- * method (algorithm 11) for scalar-point multiplication from Brown,
- * Hankerson, Lopez, Menezes. Software Implementation of the NIST Elliptic
- * Curves Over Prime Fields. */
-mp_err
- ec_GFp_pt_mul_jm_wNAF(const mp_int *n, const mp_int *px, const mp_int *py,
-                                           mp_int *rx, mp_int *ry, const ECGroup *group);
-
-#endif /* _ECP_H */
--- a/jdk/src/share/native/sun/security/ec/ecp_192.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,538 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library for prime field curves.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "ecp.h"
-#include "mpi.h"
-#include "mplogic.h"
-#include "mpi-priv.h"
-#ifndef _KERNEL
-#include <stdlib.h>
-#endif
-
-#define ECP192_DIGITS ECL_CURVE_DIGITS(192)
-
-/* Fast modular reduction for p192 = 2^192 - 2^64 - 1.  a can be r. Uses
- * algorithm 7 from Brown, Hankerson, Lopez, Menezes. Software
- * Implementation of the NIST Elliptic Curves over Prime Fields. */
-mp_err
-ec_GFp_nistp192_mod(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_size a_used = MP_USED(a);
-        mp_digit r3;
-#ifndef MPI_AMD64_ADD
-        mp_digit carry;
-#endif
-#ifdef ECL_THIRTY_TWO_BIT
-        mp_digit a5a = 0, a5b = 0, a4a = 0, a4b = 0, a3a = 0, a3b = 0;
-        mp_digit r0a, r0b, r1a, r1b, r2a, r2b;
-#else
-        mp_digit a5 = 0, a4 = 0, a3 = 0;
-        mp_digit r0, r1, r2;
-#endif
-
-        /* reduction not needed if a is not larger than field size */
-        if (a_used < ECP192_DIGITS) {
-                if (a == r) {
-                        return MP_OKAY;
-                }
-                return mp_copy(a, r);
-        }
-
-        /* for polynomials larger than twice the field size, use regular
-         * reduction */
-        if (a_used > ECP192_DIGITS*2) {
-                MP_CHECKOK(mp_mod(a, &meth->irr, r));
-        } else {
-                /* copy out upper words of a */
-
-#ifdef ECL_THIRTY_TWO_BIT
-
-                /* in all the math below,
-                 * nXb is most signifiant, nXa is least significant */
-                switch (a_used) {
-                case 12:
-                        a5b = MP_DIGIT(a, 11);
-                case 11:
-                        a5a = MP_DIGIT(a, 10);
-                case 10:
-                        a4b = MP_DIGIT(a, 9);
-                case 9:
-                        a4a = MP_DIGIT(a, 8);
-                case 8:
-                        a3b = MP_DIGIT(a, 7);
-                case 7:
-                        a3a = MP_DIGIT(a, 6);
-                }
-
-
-                r2b= MP_DIGIT(a, 5);
-                r2a= MP_DIGIT(a, 4);
-                r1b = MP_DIGIT(a, 3);
-                r1a = MP_DIGIT(a, 2);
-                r0b = MP_DIGIT(a, 1);
-                r0a = MP_DIGIT(a, 0);
-
-                /* implement r = (a2,a1,a0)+(a5,a5,a5)+(a4,a4,0)+(0,a3,a3) */
-                MP_ADD_CARRY(r0a, a3a, r0a, 0,    carry);
-                MP_ADD_CARRY(r0b, a3b, r0b, carry, carry);
-                MP_ADD_CARRY(r1a, a3a, r1a, carry, carry);
-                MP_ADD_CARRY(r1b, a3b, r1b, carry, carry);
-                MP_ADD_CARRY(r2a, a4a, r2a, carry, carry);
-                MP_ADD_CARRY(r2b, a4b, r2b, carry, carry);
-                r3 = carry; carry = 0;
-                MP_ADD_CARRY(r0a, a5a, r0a, 0,     carry);
-                MP_ADD_CARRY(r0b, a5b, r0b, carry, carry);
-                MP_ADD_CARRY(r1a, a5a, r1a, carry, carry);
-                MP_ADD_CARRY(r1b, a5b, r1b, carry, carry);
-                MP_ADD_CARRY(r2a, a5a, r2a, carry, carry);
-                MP_ADD_CARRY(r2b, a5b, r2b, carry, carry);
-                r3 += carry;
-                MP_ADD_CARRY(r1a, a4a, r1a, 0,     carry);
-                MP_ADD_CARRY(r1b, a4b, r1b, carry, carry);
-                MP_ADD_CARRY(r2a,   0, r2a, carry, carry);
-                MP_ADD_CARRY(r2b,   0, r2b, carry, carry);
-                r3 += carry;
-
-                /* reduce out the carry */
-                while (r3) {
-                        MP_ADD_CARRY(r0a, r3, r0a, 0,     carry);
-                        MP_ADD_CARRY(r0b,  0, r0b, carry, carry);
-                        MP_ADD_CARRY(r1a, r3, r1a, carry, carry);
-                        MP_ADD_CARRY(r1b,  0, r1b, carry, carry);
-                        MP_ADD_CARRY(r2a,  0, r2a, carry, carry);
-                        MP_ADD_CARRY(r2b,  0, r2b, carry, carry);
-                        r3 = carry;
-                }
-
-                /* check for final reduction */
-                /*
-                 * our field is 0xffffffffffffffff, 0xfffffffffffffffe,
-                 * 0xffffffffffffffff. That means we can only be over and need
-                 * one more reduction
-                 *  if r2 == 0xffffffffffffffffff (same as r2+1 == 0)
-                 *     and
-                 *     r1 == 0xffffffffffffffffff   or
-                 *     r1 == 0xfffffffffffffffffe and r0 = 0xfffffffffffffffff
-                 * In all cases, we subtract the field (or add the 2's
-                 * complement value (1,1,0)).  (r0, r1, r2)
-                 */
-                if (((r2b == 0xffffffff) && (r2a == 0xffffffff)
-                        && (r1b == 0xffffffff) ) &&
-                           ((r1a == 0xffffffff) ||
-                            (r1a == 0xfffffffe) && (r0a == 0xffffffff) &&
-                                        (r0b == 0xffffffff)) ) {
-                        /* do a quick subtract */
-                        MP_ADD_CARRY(r0a, 1, r0a, 0, carry);
-                        r0b += carry;
-                        r1a = r1b = r2a = r2b = 0;
-                }
-
-                /* set the lower words of r */
-                if (a != r) {
-                        MP_CHECKOK(s_mp_pad(r, 6));
-                }
-                MP_DIGIT(r, 5) = r2b;
-                MP_DIGIT(r, 4) = r2a;
-                MP_DIGIT(r, 3) = r1b;
-                MP_DIGIT(r, 2) = r1a;
-                MP_DIGIT(r, 1) = r0b;
-                MP_DIGIT(r, 0) = r0a;
-                MP_USED(r) = 6;
-#else
-                switch (a_used) {
-                case 6:
-                        a5 = MP_DIGIT(a, 5);
-                case 5:
-                        a4 = MP_DIGIT(a, 4);
-                case 4:
-                        a3 = MP_DIGIT(a, 3);
-                }
-
-                r2 = MP_DIGIT(a, 2);
-                r1 = MP_DIGIT(a, 1);
-                r0 = MP_DIGIT(a, 0);
-
-                /* implement r = (a2,a1,a0)+(a5,a5,a5)+(a4,a4,0)+(0,a3,a3) */
-#ifndef MPI_AMD64_ADD
-                MP_ADD_CARRY(r0, a3, r0, 0,     carry);
-                MP_ADD_CARRY(r1, a3, r1, carry, carry);
-                MP_ADD_CARRY(r2, a4, r2, carry, carry);
-                r3 = carry;
-                MP_ADD_CARRY(r0, a5, r0, 0,     carry);
-                MP_ADD_CARRY(r1, a5, r1, carry, carry);
-                MP_ADD_CARRY(r2, a5, r2, carry, carry);
-                r3 += carry;
-                MP_ADD_CARRY(r1, a4, r1, 0,     carry);
-                MP_ADD_CARRY(r2,  0, r2, carry, carry);
-                r3 += carry;
-
-#else
-                r2 = MP_DIGIT(a, 2);
-                r1 = MP_DIGIT(a, 1);
-                r0 = MP_DIGIT(a, 0);
-
-                /* set the lower words of r */
-                __asm__ (
-                "xorq   %3,%3           \n\t"
-                "addq   %4,%0           \n\t"
-                "adcq   %4,%1           \n\t"
-                "adcq   %5,%2           \n\t"
-                "adcq   $0,%3           \n\t"
-                "addq   %6,%0           \n\t"
-                "adcq   %6,%1           \n\t"
-                "adcq   %6,%2           \n\t"
-                "adcq   $0,%3           \n\t"
-                "addq   %5,%1           \n\t"
-                "adcq   $0,%2           \n\t"
-                "adcq   $0,%3           \n\t"
-                : "=r"(r0), "=r"(r1), "=r"(r2), "=r"(r3), "=r"(a3),
-                  "=r"(a4), "=r"(a5)
-                : "0" (r0), "1" (r1), "2" (r2), "3" (r3),
-                  "4" (a3), "5" (a4), "6"(a5)
-                : "%cc" );
-#endif
-
-                /* reduce out the carry */
-                while (r3) {
-#ifndef MPI_AMD64_ADD
-                        MP_ADD_CARRY(r0, r3, r0, 0,     carry);
-                        MP_ADD_CARRY(r1, r3, r1, carry, carry);
-                        MP_ADD_CARRY(r2,  0, r2, carry, carry);
-                        r3 = carry;
-#else
-                        a3=r3;
-                        __asm__ (
-                        "xorq   %3,%3           \n\t"
-                        "addq   %4,%0           \n\t"
-                        "adcq   %4,%1           \n\t"
-                        "adcq   $0,%2           \n\t"
-                        "adcq   $0,%3           \n\t"
-                        : "=r"(r0), "=r"(r1), "=r"(r2), "=r"(r3), "=r"(a3)
-                        : "0" (r0), "1" (r1), "2" (r2), "3" (r3), "4"(a3)
-                        : "%cc" );
-#endif
-                }
-
-                /* check for final reduction */
-                /*
-                 * our field is 0xffffffffffffffff, 0xfffffffffffffffe,
-                 * 0xffffffffffffffff. That means we can only be over and need
-                 * one more reduction
-                 *  if r2 == 0xffffffffffffffffff (same as r2+1 == 0)
-                 *     and
-                 *     r1 == 0xffffffffffffffffff   or
-                 *     r1 == 0xfffffffffffffffffe and r0 = 0xfffffffffffffffff
-                 * In all cases, we subtract the field (or add the 2's
-                 * complement value (1,1,0)).  (r0, r1, r2)
-                 */
-                if (r3 || ((r2 == MP_DIGIT_MAX) &&
-                      ((r1 == MP_DIGIT_MAX) ||
-                        ((r1 == (MP_DIGIT_MAX-1)) && (r0 == MP_DIGIT_MAX))))) {
-                        /* do a quick subtract */
-                        r0++;
-                        r1 = r2 = 0;
-                }
-                /* set the lower words of r */
-                if (a != r) {
-                        MP_CHECKOK(s_mp_pad(r, 3));
-                }
-                MP_DIGIT(r, 2) = r2;
-                MP_DIGIT(r, 1) = r1;
-                MP_DIGIT(r, 0) = r0;
-                MP_USED(r) = 3;
-#endif
-        }
-
-  CLEANUP:
-        return res;
-}
-
-#ifndef ECL_THIRTY_TWO_BIT
-/* Compute the sum of 192 bit curves. Do the work in-line since the
- * number of words are so small, we don't want to overhead of mp function
- * calls.  Uses optimized modular reduction for p192.
- */
-mp_err
-ec_GFp_nistp192_add(const mp_int *a, const mp_int *b, mp_int *r,
-                        const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_digit a0 = 0, a1 = 0, a2 = 0;
-        mp_digit r0 = 0, r1 = 0, r2 = 0;
-        mp_digit carry;
-
-        switch(MP_USED(a)) {
-        case 3:
-                a2 = MP_DIGIT(a,2);
-        case 2:
-                a1 = MP_DIGIT(a,1);
-        case 1:
-                a0 = MP_DIGIT(a,0);
-        }
-        switch(MP_USED(b)) {
-        case 3:
-                r2 = MP_DIGIT(b,2);
-        case 2:
-                r1 = MP_DIGIT(b,1);
-        case 1:
-                r0 = MP_DIGIT(b,0);
-        }
-
-#ifndef MPI_AMD64_ADD
-        MP_ADD_CARRY(a0, r0, r0, 0,     carry);
-        MP_ADD_CARRY(a1, r1, r1, carry, carry);
-        MP_ADD_CARRY(a2, r2, r2, carry, carry);
-#else
-        __asm__ (
-                "xorq   %3,%3           \n\t"
-                "addq   %4,%0           \n\t"
-                "adcq   %5,%1           \n\t"
-                "adcq   %6,%2           \n\t"
-                "adcq   $0,%3           \n\t"
-                : "=r"(r0), "=r"(r1), "=r"(r2), "=r"(carry)
-                : "r" (a0), "r" (a1), "r" (a2), "0" (r0),
-                  "1" (r1), "2" (r2)
-                : "%cc" );
-#endif
-
-        /* Do quick 'subract' if we've gone over
-         * (add the 2's complement of the curve field) */
-        if (carry || ((r2 == MP_DIGIT_MAX) &&
-                      ((r1 == MP_DIGIT_MAX) ||
-                        ((r1 == (MP_DIGIT_MAX-1)) && (r0 == MP_DIGIT_MAX))))) {
-#ifndef MPI_AMD64_ADD
-                MP_ADD_CARRY(r0, 1, r0, 0,     carry);
-                MP_ADD_CARRY(r1, 1, r1, carry, carry);
-                MP_ADD_CARRY(r2, 0, r2, carry, carry);
-#else
-                __asm__ (
-                        "addq   $1,%0           \n\t"
-                        "adcq   $1,%1           \n\t"
-                        "adcq   $0,%2           \n\t"
-                        : "=r"(r0), "=r"(r1), "=r"(r2)
-                        : "0" (r0), "1" (r1), "2" (r2)
-                        : "%cc" );
-#endif
-        }
-
-
-        MP_CHECKOK(s_mp_pad(r, 3));
-        MP_DIGIT(r, 2) = r2;
-        MP_DIGIT(r, 1) = r1;
-        MP_DIGIT(r, 0) = r0;
-        MP_SIGN(r) = MP_ZPOS;
-        MP_USED(r) = 3;
-        s_mp_clamp(r);
-
-
-  CLEANUP:
-        return res;
-}
-
-/* Compute the diff of 192 bit curves. Do the work in-line since the
- * number of words are so small, we don't want to overhead of mp function
- * calls.  Uses optimized modular reduction for p192.
- */
-mp_err
-ec_GFp_nistp192_sub(const mp_int *a, const mp_int *b, mp_int *r,
-                        const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_digit b0 = 0, b1 = 0, b2 = 0;
-        mp_digit r0 = 0, r1 = 0, r2 = 0;
-        mp_digit borrow;
-
-        switch(MP_USED(a)) {
-        case 3:
-                r2 = MP_DIGIT(a,2);
-        case 2:
-                r1 = MP_DIGIT(a,1);
-        case 1:
-                r0 = MP_DIGIT(a,0);
-        }
-
-        switch(MP_USED(b)) {
-        case 3:
-                b2 = MP_DIGIT(b,2);
-        case 2:
-                b1 = MP_DIGIT(b,1);
-        case 1:
-                b0 = MP_DIGIT(b,0);
-        }
-
-#ifndef MPI_AMD64_ADD
-        MP_SUB_BORROW(r0, b0, r0, 0,     borrow);
-        MP_SUB_BORROW(r1, b1, r1, borrow, borrow);
-        MP_SUB_BORROW(r2, b2, r2, borrow, borrow);
-#else
-        __asm__ (
-                "xorq   %3,%3           \n\t"
-                "subq   %4,%0           \n\t"
-                "sbbq   %5,%1           \n\t"
-                "sbbq   %6,%2           \n\t"
-                "adcq   $0,%3           \n\t"
-                : "=r"(r0), "=r"(r1), "=r"(r2), "=r"(borrow)
-                : "r" (b0), "r" (b1), "r" (b2), "0" (r0),
-                  "1" (r1), "2" (r2)
-                : "%cc" );
-#endif
-
-        /* Do quick 'add' if we've gone under 0
-         * (subtract the 2's complement of the curve field) */
-        if (borrow) {
-#ifndef MPI_AMD64_ADD
-                MP_SUB_BORROW(r0, 1, r0, 0,     borrow);
-                MP_SUB_BORROW(r1, 1, r1, borrow, borrow);
-                MP_SUB_BORROW(r2,  0, r2, borrow, borrow);
-#else
-                __asm__ (
-                        "subq   $1,%0           \n\t"
-                        "sbbq   $1,%1           \n\t"
-                        "sbbq   $0,%2           \n\t"
-                        : "=r"(r0), "=r"(r1), "=r"(r2)
-                        : "0" (r0), "1" (r1), "2" (r2)
-                        : "%cc" );
-#endif
-        }
-
-        MP_CHECKOK(s_mp_pad(r, 3));
-        MP_DIGIT(r, 2) = r2;
-        MP_DIGIT(r, 1) = r1;
-        MP_DIGIT(r, 0) = r0;
-        MP_SIGN(r) = MP_ZPOS;
-        MP_USED(r) = 3;
-        s_mp_clamp(r);
-
-  CLEANUP:
-        return res;
-}
-
-#endif
-
-/* Compute the square of polynomial a, reduce modulo p192. Store the
- * result in r.  r could be a.  Uses optimized modular reduction for p192.
- */
-mp_err
-ec_GFp_nistp192_sqr(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-
-        MP_CHECKOK(mp_sqr(a, r));
-        MP_CHECKOK(ec_GFp_nistp192_mod(r, r, meth));
-  CLEANUP:
-        return res;
-}
-
-/* Compute the product of two polynomials a and b, reduce modulo p192.
- * Store the result in r.  r could be a or b; a could be b.  Uses
- * optimized modular reduction for p192. */
-mp_err
-ec_GFp_nistp192_mul(const mp_int *a, const mp_int *b, mp_int *r,
-                                        const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-
-        MP_CHECKOK(mp_mul(a, b, r));
-        MP_CHECKOK(ec_GFp_nistp192_mod(r, r, meth));
-  CLEANUP:
-        return res;
-}
-
-/* Divides two field elements. If a is NULL, then returns the inverse of
- * b. */
-mp_err
-ec_GFp_nistp192_div(const mp_int *a, const mp_int *b, mp_int *r,
-                   const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_int t;
-
-        /* If a is NULL, then return the inverse of b, otherwise return a/b. */
-        if (a == NULL) {
-                return  mp_invmod(b, &meth->irr, r);
-        } else {
-                /* MPI doesn't support divmod, so we implement it using invmod and
-                 * mulmod. */
-                MP_CHECKOK(mp_init(&t, FLAG(b)));
-                MP_CHECKOK(mp_invmod(b, &meth->irr, &t));
-                MP_CHECKOK(mp_mul(a, &t, r));
-                MP_CHECKOK(ec_GFp_nistp192_mod(r, r, meth));
-          CLEANUP:
-                mp_clear(&t);
-                return res;
-        }
-}
-
-/* Wire in fast field arithmetic and precomputation of base point for
- * named curves. */
-mp_err
-ec_group_set_gfp192(ECGroup *group, ECCurveName name)
-{
-        if (name == ECCurve_NIST_P192) {
-                group->meth->field_mod = &ec_GFp_nistp192_mod;
-                group->meth->field_mul = &ec_GFp_nistp192_mul;
-                group->meth->field_sqr = &ec_GFp_nistp192_sqr;
-                group->meth->field_div = &ec_GFp_nistp192_div;
-#ifndef ECL_THIRTY_TWO_BIT
-                group->meth->field_add = &ec_GFp_nistp192_add;
-                group->meth->field_sub = &ec_GFp_nistp192_sub;
-#endif
-        }
-        return MP_OKAY;
-}
--- a/jdk/src/share/native/sun/security/ec/ecp_224.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,394 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library for prime field curves.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "ecp.h"
-#include "mpi.h"
-#include "mplogic.h"
-#include "mpi-priv.h"
-#ifndef _KERNEL
-#include <stdlib.h>
-#endif
-
-#define ECP224_DIGITS ECL_CURVE_DIGITS(224)
-
-/* Fast modular reduction for p224 = 2^224 - 2^96 + 1.  a can be r. Uses
- * algorithm 7 from Brown, Hankerson, Lopez, Menezes. Software
- * Implementation of the NIST Elliptic Curves over Prime Fields. */
-mp_err
-ec_GFp_nistp224_mod(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_size a_used = MP_USED(a);
-
-        int    r3b;
-        mp_digit carry;
-#ifdef ECL_THIRTY_TWO_BIT
-        mp_digit a6a = 0, a6b = 0,
-                a5a = 0, a5b = 0, a4a = 0, a4b = 0, a3a = 0, a3b = 0;
-        mp_digit r0a, r0b, r1a, r1b, r2a, r2b, r3a;
-#else
-        mp_digit a6 = 0, a5 = 0, a4 = 0, a3b = 0, a5a = 0;
-        mp_digit a6b = 0, a6a_a5b = 0, a5b = 0, a5a_a4b = 0, a4a_a3b = 0;
-        mp_digit r0, r1, r2, r3;
-#endif
-
-        /* reduction not needed if a is not larger than field size */
-        if (a_used < ECP224_DIGITS) {
-                if (a == r) return MP_OKAY;
-                return mp_copy(a, r);
-        }
-        /* for polynomials larger than twice the field size, use regular
-         * reduction */
-        if (a_used > ECL_CURVE_DIGITS(224*2)) {
-                MP_CHECKOK(mp_mod(a, &meth->irr, r));
-        } else {
-#ifdef ECL_THIRTY_TWO_BIT
-                /* copy out upper words of a */
-                switch (a_used) {
-                case 14:
-                        a6b = MP_DIGIT(a, 13);
-                case 13:
-                        a6a = MP_DIGIT(a, 12);
-                case 12:
-                        a5b = MP_DIGIT(a, 11);
-                case 11:
-                        a5a = MP_DIGIT(a, 10);
-                case 10:
-                        a4b = MP_DIGIT(a, 9);
-                case 9:
-                        a4a = MP_DIGIT(a, 8);
-                case 8:
-                        a3b = MP_DIGIT(a, 7);
-                }
-                r3a = MP_DIGIT(a, 6);
-                r2b= MP_DIGIT(a, 5);
-                r2a= MP_DIGIT(a, 4);
-                r1b = MP_DIGIT(a, 3);
-                r1a = MP_DIGIT(a, 2);
-                r0b = MP_DIGIT(a, 1);
-                r0a = MP_DIGIT(a, 0);
-
-
-                /* implement r = (a3a,a2,a1,a0)
-                        +(a5a, a4,a3b,  0)
-                        +(  0, a6,a5b,  0)
-                        -(  0    0,    0|a6b, a6a|a5b )
-                        -(  a6b, a6a|a5b, a5a|a4b, a4a|a3b ) */
-                MP_ADD_CARRY (r1b, a3b, r1b, 0,     carry);
-                MP_ADD_CARRY (r2a, a4a, r2a, carry, carry);
-                MP_ADD_CARRY (r2b, a4b, r2b, carry, carry);
-                MP_ADD_CARRY (r3a, a5a, r3a, carry, carry);
-                r3b = carry;
-                MP_ADD_CARRY (r1b, a5b, r1b, 0,     carry);
-                MP_ADD_CARRY (r2a, a6a, r2a, carry, carry);
-                MP_ADD_CARRY (r2b, a6b, r2b, carry, carry);
-                MP_ADD_CARRY (r3a,   0, r3a, carry, carry);
-                r3b += carry;
-                MP_SUB_BORROW(r0a, a3b, r0a, 0,     carry);
-                MP_SUB_BORROW(r0b, a4a, r0b, carry, carry);
-                MP_SUB_BORROW(r1a, a4b, r1a, carry, carry);
-                MP_SUB_BORROW(r1b, a5a, r1b, carry, carry);
-                MP_SUB_BORROW(r2a, a5b, r2a, carry, carry);
-                MP_SUB_BORROW(r2b, a6a, r2b, carry, carry);
-                MP_SUB_BORROW(r3a, a6b, r3a, carry, carry);
-                r3b -= carry;
-                MP_SUB_BORROW(r0a, a5b, r0a, 0,     carry);
-                MP_SUB_BORROW(r0b, a6a, r0b, carry, carry);
-                MP_SUB_BORROW(r1a, a6b, r1a, carry, carry);
-                if (carry) {
-                        MP_SUB_BORROW(r1b, 0, r1b, carry, carry);
-                        MP_SUB_BORROW(r2a, 0, r2a, carry, carry);
-                        MP_SUB_BORROW(r2b, 0, r2b, carry, carry);
-                        MP_SUB_BORROW(r3a, 0, r3a, carry, carry);
-                        r3b -= carry;
-                }
-
-                while (r3b > 0) {
-                        int tmp;
-                        MP_ADD_CARRY(r1b, r3b, r1b, 0,     carry);
-                        if (carry) {
-                                MP_ADD_CARRY(r2a,  0, r2a, carry, carry);
-                                MP_ADD_CARRY(r2b,  0, r2b, carry, carry);
-                                MP_ADD_CARRY(r3a,  0, r3a, carry, carry);
-                        }
-                        tmp = carry;
-                        MP_SUB_BORROW(r0a, r3b, r0a, 0,     carry);
-                        if (carry) {
-                                MP_SUB_BORROW(r0b, 0, r0b, carry, carry);
-                                MP_SUB_BORROW(r1a, 0, r1a, carry, carry);
-                                MP_SUB_BORROW(r1b, 0, r1b, carry, carry);
-                                MP_SUB_BORROW(r2a, 0, r2a, carry, carry);
-                                MP_SUB_BORROW(r2b, 0, r2b, carry, carry);
-                                MP_SUB_BORROW(r3a, 0, r3a, carry, carry);
-                                tmp -= carry;
-                        }
-                        r3b = tmp;
-                }
-
-                while (r3b < 0) {
-                        mp_digit maxInt = MP_DIGIT_MAX;
-                        MP_ADD_CARRY (r0a, 1, r0a, 0,     carry);
-                        MP_ADD_CARRY (r0b, 0, r0b, carry, carry);
-                        MP_ADD_CARRY (r1a, 0, r1a, carry, carry);
-                        MP_ADD_CARRY (r1b, maxInt, r1b, carry, carry);
-                        MP_ADD_CARRY (r2a, maxInt, r2a, carry, carry);
-                        MP_ADD_CARRY (r2b, maxInt, r2b, carry, carry);
-                        MP_ADD_CARRY (r3a, maxInt, r3a, carry, carry);
-                        r3b += carry;
-                }
-                /* check for final reduction */
-                /* now the only way we are over is if the top 4 words are all ones */
-                if ((r3a == MP_DIGIT_MAX) && (r2b == MP_DIGIT_MAX)
-                        && (r2a == MP_DIGIT_MAX) && (r1b == MP_DIGIT_MAX) &&
-                         ((r1a != 0) || (r0b != 0) || (r0a != 0)) ) {
-                        /* one last subraction */
-                        MP_SUB_BORROW(r0a, 1, r0a, 0,     carry);
-                        MP_SUB_BORROW(r0b, 0, r0b, carry, carry);
-                        MP_SUB_BORROW(r1a, 0, r1a, carry, carry);
-                        r1b = r2a = r2b = r3a = 0;
-                }
-
-
-                if (a != r) {
-                        MP_CHECKOK(s_mp_pad(r, 7));
-                }
-                /* set the lower words of r */
-                MP_SIGN(r) = MP_ZPOS;
-                MP_USED(r) = 7;
-                MP_DIGIT(r, 6) = r3a;
-                MP_DIGIT(r, 5) = r2b;
-                MP_DIGIT(r, 4) = r2a;
-                MP_DIGIT(r, 3) = r1b;
-                MP_DIGIT(r, 2) = r1a;
-                MP_DIGIT(r, 1) = r0b;
-                MP_DIGIT(r, 0) = r0a;
-#else
-                /* copy out upper words of a */
-                switch (a_used) {
-                case 7:
-                        a6 = MP_DIGIT(a, 6);
-                        a6b = a6 >> 32;
-                        a6a_a5b = a6 << 32;
-                case 6:
-                        a5 = MP_DIGIT(a, 5);
-                        a5b = a5 >> 32;
-                        a6a_a5b |= a5b;
-                        a5b = a5b << 32;
-                        a5a_a4b = a5 << 32;
-                        a5a = a5 & 0xffffffff;
-                case 5:
-                        a4 = MP_DIGIT(a, 4);
-                        a5a_a4b |= a4 >> 32;
-                        a4a_a3b = a4 << 32;
-                case 4:
-                        a3b = MP_DIGIT(a, 3) >> 32;
-                        a4a_a3b |= a3b;
-                        a3b = a3b << 32;
-                }
-
-                r3 = MP_DIGIT(a, 3) & 0xffffffff;
-                r2 = MP_DIGIT(a, 2);
-                r1 = MP_DIGIT(a, 1);
-                r0 = MP_DIGIT(a, 0);
-
-                /* implement r = (a3a,a2,a1,a0)
-                        +(a5a, a4,a3b,  0)
-                        +(  0, a6,a5b,  0)
-                        -(  0    0,    0|a6b, a6a|a5b )
-                        -(  a6b, a6a|a5b, a5a|a4b, a4a|a3b ) */
-                MP_ADD_CARRY (r1, a3b, r1, 0,     carry);
-                MP_ADD_CARRY (r2, a4 , r2, carry, carry);
-                MP_ADD_CARRY (r3, a5a, r3, carry, carry);
-                MP_ADD_CARRY (r1, a5b, r1, 0,     carry);
-                MP_ADD_CARRY (r2, a6 , r2, carry, carry);
-                MP_ADD_CARRY (r3,   0, r3, carry, carry);
-
-                MP_SUB_BORROW(r0, a4a_a3b, r0, 0,     carry);
-                MP_SUB_BORROW(r1, a5a_a4b, r1, carry, carry);
-                MP_SUB_BORROW(r2, a6a_a5b, r2, carry, carry);
-                MP_SUB_BORROW(r3, a6b    , r3, carry, carry);
-                MP_SUB_BORROW(r0, a6a_a5b, r0, 0,     carry);
-                MP_SUB_BORROW(r1, a6b    , r1, carry, carry);
-                if (carry) {
-                        MP_SUB_BORROW(r2, 0, r2, carry, carry);
-                        MP_SUB_BORROW(r3, 0, r3, carry, carry);
-                }
-
-
-                /* if the value is negative, r3 has a 2's complement
-                 * high value */
-                r3b = (int)(r3 >>32);
-                while (r3b > 0) {
-                        r3 &= 0xffffffff;
-                        MP_ADD_CARRY(r1,((mp_digit)r3b) << 32, r1, 0, carry);
-                        if (carry) {
-                                MP_ADD_CARRY(r2,  0, r2, carry, carry);
-                                MP_ADD_CARRY(r3,  0, r3, carry, carry);
-                        }
-                        MP_SUB_BORROW(r0, r3b, r0, 0, carry);
-                        if (carry) {
-                                MP_SUB_BORROW(r1, 0, r1, carry, carry);
-                                MP_SUB_BORROW(r2, 0, r2, carry, carry);
-                                MP_SUB_BORROW(r3, 0, r3, carry, carry);
-                        }
-                        r3b = (int)(r3 >>32);
-                }
-
-                while (r3b < 0) {
-                        MP_ADD_CARRY (r0, 1, r0, 0,     carry);
-                        MP_ADD_CARRY (r1, MP_DIGIT_MAX <<32, r1, carry, carry);
-                        MP_ADD_CARRY (r2, MP_DIGIT_MAX, r2, carry, carry);
-                        MP_ADD_CARRY (r3, MP_DIGIT_MAX >> 32, r3, carry, carry);
-                        r3b = (int)(r3 >>32);
-                }
-                /* check for final reduction */
-                /* now the only way we are over is if the top 4 words are all ones */
-                if ((r3 == (MP_DIGIT_MAX >> 32)) && (r2 == MP_DIGIT_MAX)
-                        && ((r1 & MP_DIGIT_MAX << 32)== MP_DIGIT_MAX << 32) &&
-                         ((r1 != MP_DIGIT_MAX << 32 ) || (r0 != 0)) ) {
-                        /* one last subraction */
-                        MP_SUB_BORROW(r0, 1, r0, 0,     carry);
-                        MP_SUB_BORROW(r1, 0, r1, carry, carry);
-                        r2 = r3 = 0;
-                }
-
-
-                if (a != r) {
-                        MP_CHECKOK(s_mp_pad(r, 4));
-                }
-                /* set the lower words of r */
-                MP_SIGN(r) = MP_ZPOS;
-                MP_USED(r) = 4;
-                MP_DIGIT(r, 3) = r3;
-                MP_DIGIT(r, 2) = r2;
-                MP_DIGIT(r, 1) = r1;
-                MP_DIGIT(r, 0) = r0;
-#endif
-        }
-
-  CLEANUP:
-        return res;
-}
-
-/* Compute the square of polynomial a, reduce modulo p224. Store the
- * result in r.  r could be a.  Uses optimized modular reduction for p224.
- */
-mp_err
-ec_GFp_nistp224_sqr(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-
-        MP_CHECKOK(mp_sqr(a, r));
-        MP_CHECKOK(ec_GFp_nistp224_mod(r, r, meth));
-  CLEANUP:
-        return res;
-}
-
-/* Compute the product of two polynomials a and b, reduce modulo p224.
- * Store the result in r.  r could be a or b; a could be b.  Uses
- * optimized modular reduction for p224. */
-mp_err
-ec_GFp_nistp224_mul(const mp_int *a, const mp_int *b, mp_int *r,
-                                        const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-
-        MP_CHECKOK(mp_mul(a, b, r));
-        MP_CHECKOK(ec_GFp_nistp224_mod(r, r, meth));
-  CLEANUP:
-        return res;
-}
-
-/* Divides two field elements. If a is NULL, then returns the inverse of
- * b. */
-mp_err
-ec_GFp_nistp224_div(const mp_int *a, const mp_int *b, mp_int *r,
-                   const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_int t;
-
-        /* If a is NULL, then return the inverse of b, otherwise return a/b. */
-        if (a == NULL) {
-                return  mp_invmod(b, &meth->irr, r);
-        } else {
-                /* MPI doesn't support divmod, so we implement it using invmod and
-                 * mulmod. */
-                MP_CHECKOK(mp_init(&t, FLAG(b)));
-                MP_CHECKOK(mp_invmod(b, &meth->irr, &t));
-                MP_CHECKOK(mp_mul(a, &t, r));
-                MP_CHECKOK(ec_GFp_nistp224_mod(r, r, meth));
-          CLEANUP:
-                mp_clear(&t);
-                return res;
-        }
-}
-
-/* Wire in fast field arithmetic and precomputation of base point for
- * named curves. */
-mp_err
-ec_group_set_gfp224(ECGroup *group, ECCurveName name)
-{
-        if (name == ECCurve_NIST_P224) {
-                group->meth->field_mod = &ec_GFp_nistp224_mod;
-                group->meth->field_mul = &ec_GFp_nistp224_mul;
-                group->meth->field_sqr = &ec_GFp_nistp224_sqr;
-                group->meth->field_div = &ec_GFp_nistp224_div;
-        }
-        return MP_OKAY;
-}
--- a/jdk/src/share/native/sun/security/ec/ecp_256.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,451 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library for prime field curves.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Douglas Stebila <douglas@stebila.ca>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "ecp.h"
-#include "mpi.h"
-#include "mplogic.h"
-#include "mpi-priv.h"
-#ifndef _KERNEL
-#include <stdlib.h>
-#endif
-
-/* Fast modular reduction for p256 = 2^256 - 2^224 + 2^192+ 2^96 - 1.  a can be r.
- * Uses algorithm 2.29 from Hankerson, Menezes, Vanstone. Guide to
- * Elliptic Curve Cryptography. */
-mp_err
-ec_GFp_nistp256_mod(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_size a_used = MP_USED(a);
-        int a_bits = mpl_significant_bits(a);
-        mp_digit carry;
-
-#ifdef ECL_THIRTY_TWO_BIT
-        mp_digit a8=0, a9=0, a10=0, a11=0, a12=0, a13=0, a14=0, a15=0;
-        mp_digit r0, r1, r2, r3, r4, r5, r6, r7;
-        int r8; /* must be a signed value ! */
-#else
-        mp_digit a4=0, a5=0, a6=0, a7=0;
-        mp_digit a4h, a4l, a5h, a5l, a6h, a6l, a7h, a7l;
-        mp_digit r0, r1, r2, r3;
-        int r4; /* must be a signed value ! */
-#endif
-        /* for polynomials larger than twice the field size
-         * use regular reduction */
-        if (a_bits < 256) {
-                if (a == r) return MP_OKAY;
-                return mp_copy(a,r);
-        }
-        if (a_bits > 512)  {
-                MP_CHECKOK(mp_mod(a, &meth->irr, r));
-        } else {
-
-#ifdef ECL_THIRTY_TWO_BIT
-                switch (a_used) {
-                case 16:
-                        a15 = MP_DIGIT(a,15);
-                case 15:
-                        a14 = MP_DIGIT(a,14);
-                case 14:
-                        a13 = MP_DIGIT(a,13);
-                case 13:
-                        a12 = MP_DIGIT(a,12);
-                case 12:
-                        a11 = MP_DIGIT(a,11);
-                case 11:
-                        a10 = MP_DIGIT(a,10);
-                case 10:
-                        a9 = MP_DIGIT(a,9);
-                case 9:
-                        a8 = MP_DIGIT(a,8);
-                }
-
-                r0 = MP_DIGIT(a,0);
-                r1 = MP_DIGIT(a,1);
-                r2 = MP_DIGIT(a,2);
-                r3 = MP_DIGIT(a,3);
-                r4 = MP_DIGIT(a,4);
-                r5 = MP_DIGIT(a,5);
-                r6 = MP_DIGIT(a,6);
-                r7 = MP_DIGIT(a,7);
-
-                /* sum 1 */
-                MP_ADD_CARRY(r3, a11, r3, 0,     carry);
-                MP_ADD_CARRY(r4, a12, r4, carry, carry);
-                MP_ADD_CARRY(r5, a13, r5, carry, carry);
-                MP_ADD_CARRY(r6, a14, r6, carry, carry);
-                MP_ADD_CARRY(r7, a15, r7, carry, carry);
-                r8 = carry;
-                MP_ADD_CARRY(r3, a11, r3, 0,     carry);
-                MP_ADD_CARRY(r4, a12, r4, carry, carry);
-                MP_ADD_CARRY(r5, a13, r5, carry, carry);
-                MP_ADD_CARRY(r6, a14, r6, carry, carry);
-                MP_ADD_CARRY(r7, a15, r7, carry, carry);
-                r8 += carry;
-                /* sum 2 */
-                MP_ADD_CARRY(r3, a12, r3, 0,     carry);
-                MP_ADD_CARRY(r4, a13, r4, carry, carry);
-                MP_ADD_CARRY(r5, a14, r5, carry, carry);
-                MP_ADD_CARRY(r6, a15, r6, carry, carry);
-                MP_ADD_CARRY(r7,   0, r7, carry, carry);
-                r8 += carry;
-                /* combine last bottom of sum 3 with second sum 2 */
-                MP_ADD_CARRY(r0, a8,  r0, 0,     carry);
-                MP_ADD_CARRY(r1, a9,  r1, carry, carry);
-                MP_ADD_CARRY(r2, a10, r2, carry, carry);
-                MP_ADD_CARRY(r3, a12, r3, carry, carry);
-                MP_ADD_CARRY(r4, a13, r4, carry, carry);
-                MP_ADD_CARRY(r5, a14, r5, carry, carry);
-                MP_ADD_CARRY(r6, a15, r6, carry, carry);
-                MP_ADD_CARRY(r7, a15, r7, carry, carry); /* from sum 3 */
-                r8 += carry;
-                /* sum 3 (rest of it)*/
-                MP_ADD_CARRY(r6, a14, r6, 0,     carry);
-                MP_ADD_CARRY(r7,   0, r7, carry, carry);
-                r8 += carry;
-                /* sum 4 (rest of it)*/
-                MP_ADD_CARRY(r0, a9,  r0, 0,     carry);
-                MP_ADD_CARRY(r1, a10, r1, carry, carry);
-                MP_ADD_CARRY(r2, a11, r2, carry, carry);
-                MP_ADD_CARRY(r3, a13, r3, carry, carry);
-                MP_ADD_CARRY(r4, a14, r4, carry, carry);
-                MP_ADD_CARRY(r5, a15, r5, carry, carry);
-                MP_ADD_CARRY(r6, a13, r6, carry, carry);
-                MP_ADD_CARRY(r7, a8,  r7, carry, carry);
-                r8 += carry;
-                /* diff 5 */
-                MP_SUB_BORROW(r0, a11, r0, 0,     carry);
-                MP_SUB_BORROW(r1, a12, r1, carry, carry);
-                MP_SUB_BORROW(r2, a13, r2, carry, carry);
-                MP_SUB_BORROW(r3,   0, r3, carry, carry);
-                MP_SUB_BORROW(r4,   0, r4, carry, carry);
-                MP_SUB_BORROW(r5,   0, r5, carry, carry);
-                MP_SUB_BORROW(r6, a8,  r6, carry, carry);
-                MP_SUB_BORROW(r7, a10, r7, carry, carry);
-                r8 -= carry;
-                /* diff 6 */
-                MP_SUB_BORROW(r0, a12, r0, 0,     carry);
-                MP_SUB_BORROW(r1, a13, r1, carry, carry);
-                MP_SUB_BORROW(r2, a14, r2, carry, carry);
-                MP_SUB_BORROW(r3, a15, r3, carry, carry);
-                MP_SUB_BORROW(r4,   0, r4, carry, carry);
-                MP_SUB_BORROW(r5,   0, r5, carry, carry);
-                MP_SUB_BORROW(r6, a9,  r6, carry, carry);
-                MP_SUB_BORROW(r7, a11, r7, carry, carry);
-                r8 -= carry;
-                /* diff 7 */
-                MP_SUB_BORROW(r0, a13, r0, 0,     carry);
-                MP_SUB_BORROW(r1, a14, r1, carry, carry);
-                MP_SUB_BORROW(r2, a15, r2, carry, carry);
-                MP_SUB_BORROW(r3, a8,  r3, carry, carry);
-                MP_SUB_BORROW(r4, a9,  r4, carry, carry);
-                MP_SUB_BORROW(r5, a10, r5, carry, carry);
-                MP_SUB_BORROW(r6, 0,   r6, carry, carry);
-                MP_SUB_BORROW(r7, a12, r7, carry, carry);
-                r8 -= carry;
-                /* diff 8 */
-                MP_SUB_BORROW(r0, a14, r0, 0,     carry);
-                MP_SUB_BORROW(r1, a15, r1, carry, carry);
-                MP_SUB_BORROW(r2, 0,   r2, carry, carry);
-                MP_SUB_BORROW(r3, a9,  r3, carry, carry);
-                MP_SUB_BORROW(r4, a10, r4, carry, carry);
-                MP_SUB_BORROW(r5, a11, r5, carry, carry);
-                MP_SUB_BORROW(r6, 0,   r6, carry, carry);
-                MP_SUB_BORROW(r7, a13, r7, carry, carry);
-                r8 -= carry;
-
-                /* reduce the overflows */
-                while (r8 > 0) {
-                        mp_digit r8_d = r8;
-                        MP_ADD_CARRY(r0, r8_d,         r0, 0,     carry);
-                        MP_ADD_CARRY(r1, 0,            r1, carry, carry);
-                        MP_ADD_CARRY(r2, 0,            r2, carry, carry);
-                        MP_ADD_CARRY(r3, -r8_d,        r3, carry, carry);
-                        MP_ADD_CARRY(r4, MP_DIGIT_MAX, r4, carry, carry);
-                        MP_ADD_CARRY(r5, MP_DIGIT_MAX, r5, carry, carry);
-                        MP_ADD_CARRY(r6, -(r8_d+1),    r6, carry, carry);
-                        MP_ADD_CARRY(r7, (r8_d-1),     r7, carry, carry);
-                        r8 = carry;
-                }
-
-                /* reduce the underflows */
-                while (r8 < 0) {
-                        mp_digit r8_d = -r8;
-                        MP_SUB_BORROW(r0, r8_d,         r0, 0,     carry);
-                        MP_SUB_BORROW(r1, 0,            r1, carry, carry);
-                        MP_SUB_BORROW(r2, 0,            r2, carry, carry);
-                        MP_SUB_BORROW(r3, -r8_d,        r3, carry, carry);
-                        MP_SUB_BORROW(r4, MP_DIGIT_MAX, r4, carry, carry);
-                        MP_SUB_BORROW(r5, MP_DIGIT_MAX, r5, carry, carry);
-                        MP_SUB_BORROW(r6, -(r8_d+1),    r6, carry, carry);
-                        MP_SUB_BORROW(r7, (r8_d-1),     r7, carry, carry);
-                        r8 = -carry;
-                }
-                if (a != r) {
-                        MP_CHECKOK(s_mp_pad(r,8));
-                }
-                MP_SIGN(r) = MP_ZPOS;
-                MP_USED(r) = 8;
-
-                MP_DIGIT(r,7) = r7;
-                MP_DIGIT(r,6) = r6;
-                MP_DIGIT(r,5) = r5;
-                MP_DIGIT(r,4) = r4;
-                MP_DIGIT(r,3) = r3;
-                MP_DIGIT(r,2) = r2;
-                MP_DIGIT(r,1) = r1;
-                MP_DIGIT(r,0) = r0;
-
-                /* final reduction if necessary */
-                if ((r7 == MP_DIGIT_MAX) &&
-                        ((r6 > 1) || ((r6 == 1) &&
-                        (r5 || r4 || r3 ||
-                                ((r2 == MP_DIGIT_MAX) && (r1 == MP_DIGIT_MAX)
-                                  && (r0 == MP_DIGIT_MAX)))))) {
-                        MP_CHECKOK(mp_sub(r, &meth->irr, r));
-                }
-#ifdef notdef
-
-
-                /* smooth the negatives */
-                while (MP_SIGN(r) != MP_ZPOS) {
-                        MP_CHECKOK(mp_add(r, &meth->irr, r));
-                }
-                while (MP_USED(r) > 8) {
-                        MP_CHECKOK(mp_sub(r, &meth->irr, r));
-                }
-
-                /* final reduction if necessary */
-                if (MP_DIGIT(r,7) >= MP_DIGIT(&meth->irr,7)) {
-                    if (mp_cmp(r,&meth->irr) != MP_LT) {
-                        MP_CHECKOK(mp_sub(r, &meth->irr, r));
-                    }
-                }
-#endif
-                s_mp_clamp(r);
-#else
-                switch (a_used) {
-                case 8:
-                        a7 = MP_DIGIT(a,7);
-                case 7:
-                        a6 = MP_DIGIT(a,6);
-                case 6:
-                        a5 = MP_DIGIT(a,5);
-                case 5:
-                        a4 = MP_DIGIT(a,4);
-                }
-                a7l = a7 << 32;
-                a7h = a7 >> 32;
-                a6l = a6 << 32;
-                a6h = a6 >> 32;
-                a5l = a5 << 32;
-                a5h = a5 >> 32;
-                a4l = a4 << 32;
-                a4h = a4 >> 32;
-                r3 = MP_DIGIT(a,3);
-                r2 = MP_DIGIT(a,2);
-                r1 = MP_DIGIT(a,1);
-                r0 = MP_DIGIT(a,0);
-
-                /* sum 1 */
-                MP_ADD_CARRY(r1, a5h << 32, r1, 0,     carry);
-                MP_ADD_CARRY(r2, a6,        r2, carry, carry);
-                MP_ADD_CARRY(r3, a7,        r3, carry, carry);
-                r4 = carry;
-                MP_ADD_CARRY(r1, a5h << 32, r1, 0,     carry);
-                MP_ADD_CARRY(r2, a6,        r2, carry, carry);
-                MP_ADD_CARRY(r3, a7,        r3, carry, carry);
-                r4 += carry;
-                /* sum 2 */
-                MP_ADD_CARRY(r1, a6l,       r1, 0,     carry);
-                MP_ADD_CARRY(r2, a6h | a7l, r2, carry, carry);
-                MP_ADD_CARRY(r3, a7h,       r3, carry, carry);
-                r4 += carry;
-                MP_ADD_CARRY(r1, a6l,       r1, 0,     carry);
-                MP_ADD_CARRY(r2, a6h | a7l, r2, carry, carry);
-                MP_ADD_CARRY(r3, a7h,       r3, carry, carry);
-                r4 += carry;
-
-                /* sum 3 */
-                MP_ADD_CARRY(r0, a4,        r0, 0,     carry);
-                MP_ADD_CARRY(r1, a5l >> 32, r1, carry, carry);
-                MP_ADD_CARRY(r2, 0,         r2, carry, carry);
-                MP_ADD_CARRY(r3, a7,        r3, carry, carry);
-                r4 += carry;
-                /* sum 4 */
-                MP_ADD_CARRY(r0, a4h | a5l,     r0, 0,     carry);
-                MP_ADD_CARRY(r1, a5h|(a6h<<32), r1, carry, carry);
-                MP_ADD_CARRY(r2, a7,            r2, carry, carry);
-                MP_ADD_CARRY(r3, a6h | a4l,     r3, carry, carry);
-                r4 += carry;
-                /* diff 5 */
-                MP_SUB_BORROW(r0, a5h | a6l,    r0, 0,     carry);
-                MP_SUB_BORROW(r1, a6h,          r1, carry, carry);
-                MP_SUB_BORROW(r2, 0,            r2, carry, carry);
-                MP_SUB_BORROW(r3, (a4l>>32)|a5l,r3, carry, carry);
-                r4 -= carry;
-                /* diff 6 */
-                MP_SUB_BORROW(r0, a6,           r0, 0,     carry);
-                MP_SUB_BORROW(r1, a7,           r1, carry, carry);
-                MP_SUB_BORROW(r2, 0,            r2, carry, carry);
-                MP_SUB_BORROW(r3, a4h|(a5h<<32),r3, carry, carry);
-                r4 -= carry;
-                /* diff 7 */
-                MP_SUB_BORROW(r0, a6h|a7l,      r0, 0,     carry);
-                MP_SUB_BORROW(r1, a7h|a4l,      r1, carry, carry);
-                MP_SUB_BORROW(r2, a4h|a5l,      r2, carry, carry);
-                MP_SUB_BORROW(r3, a6l,          r3, carry, carry);
-                r4 -= carry;
-                /* diff 8 */
-                MP_SUB_BORROW(r0, a7,           r0, 0,     carry);
-                MP_SUB_BORROW(r1, a4h<<32,      r1, carry, carry);
-                MP_SUB_BORROW(r2, a5,           r2, carry, carry);
-                MP_SUB_BORROW(r3, a6h<<32,      r3, carry, carry);
-                r4 -= carry;
-
-                /* reduce the overflows */
-                while (r4 > 0) {
-                        mp_digit r4_long = r4;
-                        mp_digit r4l = (r4_long << 32);
-                        MP_ADD_CARRY(r0, r4_long,      r0, 0,     carry);
-                        MP_ADD_CARRY(r1, -r4l,         r1, carry, carry);
-                        MP_ADD_CARRY(r2, MP_DIGIT_MAX, r2, carry, carry);
-                        MP_ADD_CARRY(r3, r4l-r4_long-1,r3, carry, carry);
-                        r4 = carry;
-                }
-
-                /* reduce the underflows */
-                while (r4 < 0) {
-                        mp_digit r4_long = -r4;
-                        mp_digit r4l = (r4_long << 32);
-                        MP_SUB_BORROW(r0, r4_long,      r0, 0,     carry);
-                        MP_SUB_BORROW(r1, -r4l,         r1, carry, carry);
-                        MP_SUB_BORROW(r2, MP_DIGIT_MAX, r2, carry, carry);
-                        MP_SUB_BORROW(r3, r4l-r4_long-1,r3, carry, carry);
-                        r4 = -carry;
-                }
-
-                if (a != r) {
-                        MP_CHECKOK(s_mp_pad(r,4));
-                }
-                MP_SIGN(r) = MP_ZPOS;
-                MP_USED(r) = 4;
-
-                MP_DIGIT(r,3) = r3;
-                MP_DIGIT(r,2) = r2;
-                MP_DIGIT(r,1) = r1;
-                MP_DIGIT(r,0) = r0;
-
-                /* final reduction if necessary */
-                if ((r3 > 0xFFFFFFFF00000001ULL) ||
-                        ((r3 == 0xFFFFFFFF00000001ULL) &&
-                        (r2 || (r1 >> 32)||
-                               (r1 == 0xFFFFFFFFULL && r0 == MP_DIGIT_MAX)))) {
-                        /* very rare, just use mp_sub */
-                        MP_CHECKOK(mp_sub(r, &meth->irr, r));
-                }
-
-                s_mp_clamp(r);
-#endif
-        }
-
-  CLEANUP:
-        return res;
-}
-
-/* Compute the square of polynomial a, reduce modulo p256. Store the
- * result in r.  r could be a.  Uses optimized modular reduction for p256.
- */
-mp_err
-ec_GFp_nistp256_sqr(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-
-        MP_CHECKOK(mp_sqr(a, r));
-        MP_CHECKOK(ec_GFp_nistp256_mod(r, r, meth));
-  CLEANUP:
-        return res;
-}
-
-/* Compute the product of two polynomials a and b, reduce modulo p256.
- * Store the result in r.  r could be a or b; a could be b.  Uses
- * optimized modular reduction for p256. */
-mp_err
-ec_GFp_nistp256_mul(const mp_int *a, const mp_int *b, mp_int *r,
-                                        const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-
-        MP_CHECKOK(mp_mul(a, b, r));
-        MP_CHECKOK(ec_GFp_nistp256_mod(r, r, meth));
-  CLEANUP:
-        return res;
-}
-
-/* Wire in fast field arithmetic and precomputation of base point for
- * named curves. */
-mp_err
-ec_group_set_gfp256(ECGroup *group, ECCurveName name)
-{
-        if (name == ECCurve_NIST_P256) {
-                group->meth->field_mod = &ec_GFp_nistp256_mod;
-                group->meth->field_mul = &ec_GFp_nistp256_mul;
-                group->meth->field_sqr = &ec_GFp_nistp256_sqr;
-        }
-        return MP_OKAY;
-}
--- a/jdk/src/share/native/sun/security/ec/ecp_384.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,315 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library for prime field curves.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Douglas Stebila <douglas@stebila.ca>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "ecp.h"
-#include "mpi.h"
-#include "mplogic.h"
-#include "mpi-priv.h"
-#ifndef _KERNEL
-#include <stdlib.h>
-#endif
-
-/* Fast modular reduction for p384 = 2^384 - 2^128 - 2^96 + 2^32 - 1.  a can be r.
- * Uses algorithm 2.30 from Hankerson, Menezes, Vanstone. Guide to
- * Elliptic Curve Cryptography. */
-mp_err
-ec_GFp_nistp384_mod(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        int a_bits = mpl_significant_bits(a);
-        int i;
-
-        /* m1, m2 are statically-allocated mp_int of exactly the size we need */
-        mp_int m[10];
-
-#ifdef ECL_THIRTY_TWO_BIT
-        mp_digit s[10][12];
-        for (i = 0; i < 10; i++) {
-                MP_SIGN(&m[i]) = MP_ZPOS;
-                MP_ALLOC(&m[i]) = 12;
-                MP_USED(&m[i]) = 12;
-                MP_DIGITS(&m[i]) = s[i];
-        }
-#else
-        mp_digit s[10][6];
-        for (i = 0; i < 10; i++) {
-                MP_SIGN(&m[i]) = MP_ZPOS;
-                MP_ALLOC(&m[i]) = 6;
-                MP_USED(&m[i]) = 6;
-                MP_DIGITS(&m[i]) = s[i];
-        }
-#endif
-
-#ifdef ECL_THIRTY_TWO_BIT
-        /* for polynomials larger than twice the field size or polynomials
-         * not using all words, use regular reduction */
-        if ((a_bits > 768) || (a_bits <= 736)) {
-                MP_CHECKOK(mp_mod(a, &meth->irr, r));
-        } else {
-                for (i = 0; i < 12; i++) {
-                        s[0][i] = MP_DIGIT(a, i);
-                }
-                s[1][0] = 0;
-                s[1][1] = 0;
-                s[1][2] = 0;
-                s[1][3] = 0;
-                s[1][4] = MP_DIGIT(a, 21);
-                s[1][5] = MP_DIGIT(a, 22);
-                s[1][6] = MP_DIGIT(a, 23);
-                s[1][7] = 0;
-                s[1][8] = 0;
-                s[1][9] = 0;
-                s[1][10] = 0;
-                s[1][11] = 0;
-                for (i = 0; i < 12; i++) {
-                        s[2][i] = MP_DIGIT(a, i+12);
-                }
-                s[3][0] = MP_DIGIT(a, 21);
-                s[3][1] = MP_DIGIT(a, 22);
-                s[3][2] = MP_DIGIT(a, 23);
-                for (i = 3; i < 12; i++) {
-                        s[3][i] = MP_DIGIT(a, i+9);
-                }
-                s[4][0] = 0;
-                s[4][1] = MP_DIGIT(a, 23);
-                s[4][2] = 0;
-                s[4][3] = MP_DIGIT(a, 20);
-                for (i = 4; i < 12; i++) {
-                        s[4][i] = MP_DIGIT(a, i+8);
-                }
-                s[5][0] = 0;
-                s[5][1] = 0;
-                s[5][2] = 0;
-                s[5][3] = 0;
-                s[5][4] = MP_DIGIT(a, 20);
-                s[5][5] = MP_DIGIT(a, 21);
-                s[5][6] = MP_DIGIT(a, 22);
-                s[5][7] = MP_DIGIT(a, 23);
-                s[5][8] = 0;
-                s[5][9] = 0;
-                s[5][10] = 0;
-                s[5][11] = 0;
-                s[6][0] = MP_DIGIT(a, 20);
-                s[6][1] = 0;
-                s[6][2] = 0;
-                s[6][3] = MP_DIGIT(a, 21);
-                s[6][4] = MP_DIGIT(a, 22);
-                s[6][5] = MP_DIGIT(a, 23);
-                s[6][6] = 0;
-                s[6][7] = 0;
-                s[6][8] = 0;
-                s[6][9] = 0;
-                s[6][10] = 0;
-                s[6][11] = 0;
-                s[7][0] = MP_DIGIT(a, 23);
-                for (i = 1; i < 12; i++) {
-                        s[7][i] = MP_DIGIT(a, i+11);
-                }
-                s[8][0] = 0;
-                s[8][1] = MP_DIGIT(a, 20);
-                s[8][2] = MP_DIGIT(a, 21);
-                s[8][3] = MP_DIGIT(a, 22);
-                s[8][4] = MP_DIGIT(a, 23);
-                s[8][5] = 0;
-                s[8][6] = 0;
-                s[8][7] = 0;
-                s[8][8] = 0;
-                s[8][9] = 0;
-                s[8][10] = 0;
-                s[8][11] = 0;
-                s[9][0] = 0;
-                s[9][1] = 0;
-                s[9][2] = 0;
-                s[9][3] = MP_DIGIT(a, 23);
-                s[9][4] = MP_DIGIT(a, 23);
-                s[9][5] = 0;
-                s[9][6] = 0;
-                s[9][7] = 0;
-                s[9][8] = 0;
-                s[9][9] = 0;
-                s[9][10] = 0;
-                s[9][11] = 0;
-
-                MP_CHECKOK(mp_add(&m[0], &m[1], r));
-                MP_CHECKOK(mp_add(r, &m[1], r));
-                MP_CHECKOK(mp_add(r, &m[2], r));
-                MP_CHECKOK(mp_add(r, &m[3], r));
-                MP_CHECKOK(mp_add(r, &m[4], r));
-                MP_CHECKOK(mp_add(r, &m[5], r));
-                MP_CHECKOK(mp_add(r, &m[6], r));
-                MP_CHECKOK(mp_sub(r, &m[7], r));
-                MP_CHECKOK(mp_sub(r, &m[8], r));
-                MP_CHECKOK(mp_submod(r, &m[9], &meth->irr, r));
-                s_mp_clamp(r);
-        }
-#else
-        /* for polynomials larger than twice the field size or polynomials
-         * not using all words, use regular reduction */
-        if ((a_bits > 768) || (a_bits <= 736)) {
-                MP_CHECKOK(mp_mod(a, &meth->irr, r));
-        } else {
-                for (i = 0; i < 6; i++) {
-                        s[0][i] = MP_DIGIT(a, i);
-                }
-                s[1][0] = 0;
-                s[1][1] = 0;
-                s[1][2] = (MP_DIGIT(a, 10) >> 32) | (MP_DIGIT(a, 11) << 32);
-                s[1][3] = MP_DIGIT(a, 11) >> 32;
-                s[1][4] = 0;
-                s[1][5] = 0;
-                for (i = 0; i < 6; i++) {
-                        s[2][i] = MP_DIGIT(a, i+6);
-                }
-                s[3][0] = (MP_DIGIT(a, 10) >> 32) | (MP_DIGIT(a, 11) << 32);
-                s[3][1] = (MP_DIGIT(a, 11) >> 32) | (MP_DIGIT(a, 6) << 32);
-                for (i = 2; i < 6; i++) {
-                        s[3][i] = (MP_DIGIT(a, i+4) >> 32) | (MP_DIGIT(a, i+5) << 32);
-                }
-                s[4][0] = (MP_DIGIT(a, 11) >> 32) << 32;
-                s[4][1] = MP_DIGIT(a, 10) << 32;
-                for (i = 2; i < 6; i++) {
-                        s[4][i] = MP_DIGIT(a, i+4);
-                }
-                s[5][0] = 0;
-                s[5][1] = 0;
-                s[5][2] = MP_DIGIT(a, 10);
-                s[5][3] = MP_DIGIT(a, 11);
-                s[5][4] = 0;
-                s[5][5] = 0;
-                s[6][0] = (MP_DIGIT(a, 10) << 32) >> 32;
-                s[6][1] = (MP_DIGIT(a, 10) >> 32) << 32;
-                s[6][2] = MP_DIGIT(a, 11);
-                s[6][3] = 0;
-                s[6][4] = 0;
-                s[6][5] = 0;
-                s[7][0] = (MP_DIGIT(a, 11) >> 32) | (MP_DIGIT(a, 6) << 32);
-                for (i = 1; i < 6; i++) {
-                        s[7][i] = (MP_DIGIT(a, i+5) >> 32) | (MP_DIGIT(a, i+6) << 32);
-                }
-                s[8][0] = MP_DIGIT(a, 10) << 32;
-                s[8][1] = (MP_DIGIT(a, 10) >> 32) | (MP_DIGIT(a, 11) << 32);
-                s[8][2] = MP_DIGIT(a, 11) >> 32;
-                s[8][3] = 0;
-                s[8][4] = 0;
-                s[8][5] = 0;
-                s[9][0] = 0;
-                s[9][1] = (MP_DIGIT(a, 11) >> 32) << 32;
-                s[9][2] = MP_DIGIT(a, 11) >> 32;
-                s[9][3] = 0;
-                s[9][4] = 0;
-                s[9][5] = 0;
-
-                MP_CHECKOK(mp_add(&m[0], &m[1], r));
-                MP_CHECKOK(mp_add(r, &m[1], r));
-                MP_CHECKOK(mp_add(r, &m[2], r));
-                MP_CHECKOK(mp_add(r, &m[3], r));
-                MP_CHECKOK(mp_add(r, &m[4], r));
-                MP_CHECKOK(mp_add(r, &m[5], r));
-                MP_CHECKOK(mp_add(r, &m[6], r));
-                MP_CHECKOK(mp_sub(r, &m[7], r));
-                MP_CHECKOK(mp_sub(r, &m[8], r));
-                MP_CHECKOK(mp_submod(r, &m[9], &meth->irr, r));
-                s_mp_clamp(r);
-        }
-#endif
-
-  CLEANUP:
-        return res;
-}
-
-/* Compute the square of polynomial a, reduce modulo p384. Store the
- * result in r.  r could be a.  Uses optimized modular reduction for p384.
- */
-mp_err
-ec_GFp_nistp384_sqr(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-
-        MP_CHECKOK(mp_sqr(a, r));
-        MP_CHECKOK(ec_GFp_nistp384_mod(r, r, meth));
-  CLEANUP:
-        return res;
-}
-
-/* Compute the product of two polynomials a and b, reduce modulo p384.
- * Store the result in r.  r could be a or b; a could be b.  Uses
- * optimized modular reduction for p384. */
-mp_err
-ec_GFp_nistp384_mul(const mp_int *a, const mp_int *b, mp_int *r,
-                                        const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-
-        MP_CHECKOK(mp_mul(a, b, r));
-        MP_CHECKOK(ec_GFp_nistp384_mod(r, r, meth));
-  CLEANUP:
-        return res;
-}
-
-/* Wire in fast field arithmetic and precomputation of base point for
- * named curves. */
-mp_err
-ec_group_set_gfp384(ECGroup *group, ECCurveName name)
-{
-        if (name == ECCurve_NIST_P384) {
-                group->meth->field_mod = &ec_GFp_nistp384_mod;
-                group->meth->field_mul = &ec_GFp_nistp384_mul;
-                group->meth->field_sqr = &ec_GFp_nistp384_sqr;
-        }
-        return MP_OKAY;
-}
--- a/jdk/src/share/native/sun/security/ec/ecp_521.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,192 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library for prime field curves.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Douglas Stebila <douglas@stebila.ca>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "ecp.h"
-#include "mpi.h"
-#include "mplogic.h"
-#include "mpi-priv.h"
-#ifndef _KERNEL
-#include <stdlib.h>
-#endif
-
-#define ECP521_DIGITS ECL_CURVE_DIGITS(521)
-
-/* Fast modular reduction for p521 = 2^521 - 1.  a can be r. Uses
- * algorithm 2.31 from Hankerson, Menezes, Vanstone. Guide to
- * Elliptic Curve Cryptography. */
-mp_err
-ec_GFp_nistp521_mod(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        int a_bits = mpl_significant_bits(a);
-        int i;
-
-        /* m1, m2 are statically-allocated mp_int of exactly the size we need */
-        mp_int m1;
-
-        mp_digit s1[ECP521_DIGITS] = { 0 };
-
-        MP_SIGN(&m1) = MP_ZPOS;
-        MP_ALLOC(&m1) = ECP521_DIGITS;
-        MP_USED(&m1) = ECP521_DIGITS;
-        MP_DIGITS(&m1) = s1;
-
-        if (a_bits < 521) {
-                if (a==r) return MP_OKAY;
-                return mp_copy(a, r);
-        }
-        /* for polynomials larger than twice the field size or polynomials
-         * not using all words, use regular reduction */
-        if (a_bits > (521*2)) {
-                MP_CHECKOK(mp_mod(a, &meth->irr, r));
-        } else {
-#define FIRST_DIGIT (ECP521_DIGITS-1)
-                for (i = FIRST_DIGIT; i < MP_USED(a)-1; i++) {
-                        s1[i-FIRST_DIGIT] = (MP_DIGIT(a, i) >> 9)
-                                | (MP_DIGIT(a, 1+i) << (MP_DIGIT_BIT-9));
-                }
-                s1[i-FIRST_DIGIT] = MP_DIGIT(a, i) >> 9;
-
-                if ( a != r ) {
-                        MP_CHECKOK(s_mp_pad(r,ECP521_DIGITS));
-                        for (i = 0; i < ECP521_DIGITS; i++) {
-                                MP_DIGIT(r,i) = MP_DIGIT(a, i);
-                        }
-                }
-                MP_USED(r) = ECP521_DIGITS;
-                MP_DIGIT(r,FIRST_DIGIT) &=  0x1FF;
-
-                MP_CHECKOK(s_mp_add(r, &m1));
-                if (MP_DIGIT(r, FIRST_DIGIT) & 0x200) {
-                        MP_CHECKOK(s_mp_add_d(r,1));
-                        MP_DIGIT(r,FIRST_DIGIT) &=  0x1FF;
-                }
-                s_mp_clamp(r);
-        }
-
-  CLEANUP:
-        return res;
-}
-
-/* Compute the square of polynomial a, reduce modulo p521. Store the
- * result in r.  r could be a.  Uses optimized modular reduction for p521.
- */
-mp_err
-ec_GFp_nistp521_sqr(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-
-        MP_CHECKOK(mp_sqr(a, r));
-        MP_CHECKOK(ec_GFp_nistp521_mod(r, r, meth));
-  CLEANUP:
-        return res;
-}
-
-/* Compute the product of two polynomials a and b, reduce modulo p521.
- * Store the result in r.  r could be a or b; a could be b.  Uses
- * optimized modular reduction for p521. */
-mp_err
-ec_GFp_nistp521_mul(const mp_int *a, const mp_int *b, mp_int *r,
-                                        const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-
-        MP_CHECKOK(mp_mul(a, b, r));
-        MP_CHECKOK(ec_GFp_nistp521_mod(r, r, meth));
-  CLEANUP:
-        return res;
-}
-
-/* Divides two field elements. If a is NULL, then returns the inverse of
- * b. */
-mp_err
-ec_GFp_nistp521_div(const mp_int *a, const mp_int *b, mp_int *r,
-                   const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-        mp_int t;
-
-        /* If a is NULL, then return the inverse of b, otherwise return a/b. */
-        if (a == NULL) {
-                return mp_invmod(b, &meth->irr, r);
-        } else {
-                /* MPI doesn't support divmod, so we implement it using invmod and
-                 * mulmod. */
-                MP_CHECKOK(mp_init(&t, FLAG(b)));
-                MP_CHECKOK(mp_invmod(b, &meth->irr, &t));
-                MP_CHECKOK(mp_mul(a, &t, r));
-                MP_CHECKOK(ec_GFp_nistp521_mod(r, r, meth));
-          CLEANUP:
-                mp_clear(&t);
-                return res;
-        }
-}
-
-/* Wire in fast field arithmetic and precomputation of base point for
- * named curves. */
-mp_err
-ec_group_set_gfp521(ECGroup *group, ECCurveName name)
-{
-        if (name == ECCurve_NIST_P521) {
-                group->meth->field_mod = &ec_GFp_nistp521_mod;
-                group->meth->field_mul = &ec_GFp_nistp521_mul;
-                group->meth->field_sqr = &ec_GFp_nistp521_sqr;
-                group->meth->field_div = &ec_GFp_nistp521_div;
-        }
-        return MP_OKAY;
-}
--- a/jdk/src/share/native/sun/security/ec/ecp_aff.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,379 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library for prime field curves.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Sheueling Chang-Shantz <sheueling.chang@sun.com>,
- *   Stephen Fung <fungstep@hotmail.com>, and
- *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories.
- *   Bodo Moeller <moeller@cdc.informatik.tu-darmstadt.de>,
- *   Nils Larsch <nla@trustcenter.de>, and
- *   Lenka Fibikova <fibikova@exp-math.uni-essen.de>, the OpenSSL Project
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "ecp.h"
-#include "mplogic.h"
-#ifndef _KERNEL
-#include <stdlib.h>
-#endif
-
-/* Checks if point P(px, py) is at infinity.  Uses affine coordinates. */
-mp_err
-ec_GFp_pt_is_inf_aff(const mp_int *px, const mp_int *py)
-{
-
-        if ((mp_cmp_z(px) == 0) && (mp_cmp_z(py) == 0)) {
-                return MP_YES;
-        } else {
-                return MP_NO;
-        }
-
-}
-
-/* Sets P(px, py) to be the point at infinity.  Uses affine coordinates. */
-mp_err
-ec_GFp_pt_set_inf_aff(mp_int *px, mp_int *py)
-{
-        mp_zero(px);
-        mp_zero(py);
-        return MP_OKAY;
-}
-
-/* Computes R = P + Q based on IEEE P1363 A.10.1. Elliptic curve points P,
- * Q, and R can all be identical. Uses affine coordinates. Assumes input
- * is already field-encoded using field_enc, and returns output that is
- * still field-encoded. */
-mp_err
-ec_GFp_pt_add_aff(const mp_int *px, const mp_int *py, const mp_int *qx,
-                                  const mp_int *qy, mp_int *rx, mp_int *ry,
-                                  const ECGroup *group)
-{
-        mp_err res = MP_OKAY;
-        mp_int lambda, temp, tempx, tempy;
-
-        MP_DIGITS(&lambda) = 0;
-        MP_DIGITS(&temp) = 0;
-        MP_DIGITS(&tempx) = 0;
-        MP_DIGITS(&tempy) = 0;
-        MP_CHECKOK(mp_init(&lambda, FLAG(px)));
-        MP_CHECKOK(mp_init(&temp, FLAG(px)));
-        MP_CHECKOK(mp_init(&tempx, FLAG(px)));
-        MP_CHECKOK(mp_init(&tempy, FLAG(px)));
-        /* if P = inf, then R = Q */
-        if (ec_GFp_pt_is_inf_aff(px, py) == 0) {
-                MP_CHECKOK(mp_copy(qx, rx));
-                MP_CHECKOK(mp_copy(qy, ry));
-                res = MP_OKAY;
-                goto CLEANUP;
-        }
-        /* if Q = inf, then R = P */
-        if (ec_GFp_pt_is_inf_aff(qx, qy) == 0) {
-                MP_CHECKOK(mp_copy(px, rx));
-                MP_CHECKOK(mp_copy(py, ry));
-                res = MP_OKAY;
-                goto CLEANUP;
-        }
-        /* if px != qx, then lambda = (py-qy) / (px-qx) */
-        if (mp_cmp(px, qx) != 0) {
-                MP_CHECKOK(group->meth->field_sub(py, qy, &tempy, group->meth));
-                MP_CHECKOK(group->meth->field_sub(px, qx, &tempx, group->meth));
-                MP_CHECKOK(group->meth->
-                                   field_div(&tempy, &tempx, &lambda, group->meth));
-        } else {
-                /* if py != qy or qy = 0, then R = inf */
-                if (((mp_cmp(py, qy) != 0)) || (mp_cmp_z(qy) == 0)) {
-                        mp_zero(rx);
-                        mp_zero(ry);
-                        res = MP_OKAY;
-                        goto CLEANUP;
-                }
-                /* lambda = (3qx^2+a) / (2qy) */
-                MP_CHECKOK(group->meth->field_sqr(qx, &tempx, group->meth));
-                MP_CHECKOK(mp_set_int(&temp, 3));
-                if (group->meth->field_enc) {
-                        MP_CHECKOK(group->meth->field_enc(&temp, &temp, group->meth));
-                }
-                MP_CHECKOK(group->meth->
-                                   field_mul(&tempx, &temp, &tempx, group->meth));
-                MP_CHECKOK(group->meth->
-                                   field_add(&tempx, &group->curvea, &tempx, group->meth));
-                MP_CHECKOK(mp_set_int(&temp, 2));
-                if (group->meth->field_enc) {
-                        MP_CHECKOK(group->meth->field_enc(&temp, &temp, group->meth));
-                }
-                MP_CHECKOK(group->meth->field_mul(qy, &temp, &tempy, group->meth));
-                MP_CHECKOK(group->meth->
-                                   field_div(&tempx, &tempy, &lambda, group->meth));
-        }
-        /* rx = lambda^2 - px - qx */
-        MP_CHECKOK(group->meth->field_sqr(&lambda, &tempx, group->meth));
-        MP_CHECKOK(group->meth->field_sub(&tempx, px, &tempx, group->meth));
-        MP_CHECKOK(group->meth->field_sub(&tempx, qx, &tempx, group->meth));
-        /* ry = (x1-x2) * lambda - y1 */
-        MP_CHECKOK(group->meth->field_sub(qx, &tempx, &tempy, group->meth));
-        MP_CHECKOK(group->meth->
-                           field_mul(&tempy, &lambda, &tempy, group->meth));
-        MP_CHECKOK(group->meth->field_sub(&tempy, qy, &tempy, group->meth));
-        MP_CHECKOK(mp_copy(&tempx, rx));
-        MP_CHECKOK(mp_copy(&tempy, ry));
-
-  CLEANUP:
-        mp_clear(&lambda);
-        mp_clear(&temp);
-        mp_clear(&tempx);
-        mp_clear(&tempy);
-        return res;
-}
-
-/* Computes R = P - Q. Elliptic curve points P, Q, and R can all be
- * identical. Uses affine coordinates. Assumes input is already
- * field-encoded using field_enc, and returns output that is still
- * field-encoded. */
-mp_err
-ec_GFp_pt_sub_aff(const mp_int *px, const mp_int *py, const mp_int *qx,
-                                  const mp_int *qy, mp_int *rx, mp_int *ry,
-                                  const ECGroup *group)
-{
-        mp_err res = MP_OKAY;
-        mp_int nqy;
-
-        MP_DIGITS(&nqy) = 0;
-        MP_CHECKOK(mp_init(&nqy, FLAG(px)));
-        /* nqy = -qy */
-        MP_CHECKOK(group->meth->field_neg(qy, &nqy, group->meth));
-        res = group->point_add(px, py, qx, &nqy, rx, ry, group);
-  CLEANUP:
-        mp_clear(&nqy);
-        return res;
-}
-
-/* Computes R = 2P. Elliptic curve points P and R can be identical. Uses
- * affine coordinates. Assumes input is already field-encoded using
- * field_enc, and returns output that is still field-encoded. */
-mp_err
-ec_GFp_pt_dbl_aff(const mp_int *px, const mp_int *py, mp_int *rx,
-                                  mp_int *ry, const ECGroup *group)
-{
-        return ec_GFp_pt_add_aff(px, py, px, py, rx, ry, group);
-}
-
-/* by default, this routine is unused and thus doesn't need to be compiled */
-#ifdef ECL_ENABLE_GFP_PT_MUL_AFF
-/* Computes R = nP based on IEEE P1363 A.10.3. Elliptic curve points P and
- * R can be identical. Uses affine coordinates. Assumes input is already
- * field-encoded using field_enc, and returns output that is still
- * field-encoded. */
-mp_err
-ec_GFp_pt_mul_aff(const mp_int *n, const mp_int *px, const mp_int *py,
-                                  mp_int *rx, mp_int *ry, const ECGroup *group)
-{
-        mp_err res = MP_OKAY;
-        mp_int k, k3, qx, qy, sx, sy;
-        int b1, b3, i, l;
-
-        MP_DIGITS(&k) = 0;
-        MP_DIGITS(&k3) = 0;
-        MP_DIGITS(&qx) = 0;
-        MP_DIGITS(&qy) = 0;
-        MP_DIGITS(&sx) = 0;
-        MP_DIGITS(&sy) = 0;
-        MP_CHECKOK(mp_init(&k));
-        MP_CHECKOK(mp_init(&k3));
-        MP_CHECKOK(mp_init(&qx));
-        MP_CHECKOK(mp_init(&qy));
-        MP_CHECKOK(mp_init(&sx));
-        MP_CHECKOK(mp_init(&sy));
-
-        /* if n = 0 then r = inf */
-        if (mp_cmp_z(n) == 0) {
-                mp_zero(rx);
-                mp_zero(ry);
-                res = MP_OKAY;
-                goto CLEANUP;
-        }
-        /* Q = P, k = n */
-        MP_CHECKOK(mp_copy(px, &qx));
-        MP_CHECKOK(mp_copy(py, &qy));
-        MP_CHECKOK(mp_copy(n, &k));
-        /* if n < 0 then Q = -Q, k = -k */
-        if (mp_cmp_z(n) < 0) {
-                MP_CHECKOK(group->meth->field_neg(&qy, &qy, group->meth));
-                MP_CHECKOK(mp_neg(&k, &k));
-        }
-#ifdef ECL_DEBUG                                /* basic double and add method */
-        l = mpl_significant_bits(&k) - 1;
-        MP_CHECKOK(mp_copy(&qx, &sx));
-        MP_CHECKOK(mp_copy(&qy, &sy));
-        for (i = l - 1; i >= 0; i--) {
-                /* S = 2S */
-                MP_CHECKOK(group->point_dbl(&sx, &sy, &sx, &sy, group));
-                /* if k_i = 1, then S = S + Q */
-                if (mpl_get_bit(&k, i) != 0) {
-                        MP_CHECKOK(group->
-                                           point_add(&sx, &sy, &qx, &qy, &sx, &sy, group));
-                }
-        }
-#else                                                   /* double and add/subtract method from
-                                                                 * standard */
-        /* k3 = 3 * k */
-        MP_CHECKOK(mp_set_int(&k3, 3));
-        MP_CHECKOK(mp_mul(&k, &k3, &k3));
-        /* S = Q */
-        MP_CHECKOK(mp_copy(&qx, &sx));
-        MP_CHECKOK(mp_copy(&qy, &sy));
-        /* l = index of high order bit in binary representation of 3*k */
-        l = mpl_significant_bits(&k3) - 1;
-        /* for i = l-1 downto 1 */
-        for (i = l - 1; i >= 1; i--) {
-                /* S = 2S */
-                MP_CHECKOK(group->point_dbl(&sx, &sy, &sx, &sy, group));
-                b3 = MP_GET_BIT(&k3, i);
-                b1 = MP_GET_BIT(&k, i);
-                /* if k3_i = 1 and k_i = 0, then S = S + Q */
-                if ((b3 == 1) && (b1 == 0)) {
-                        MP_CHECKOK(group->
-                                           point_add(&sx, &sy, &qx, &qy, &sx, &sy, group));
-                        /* if k3_i = 0 and k_i = 1, then S = S - Q */
-                } else if ((b3 == 0) && (b1 == 1)) {
-                        MP_CHECKOK(group->
-                                           point_sub(&sx, &sy, &qx, &qy, &sx, &sy, group));
-                }
-        }
-#endif
-        /* output S */
-        MP_CHECKOK(mp_copy(&sx, rx));
-        MP_CHECKOK(mp_copy(&sy, ry));
-
-  CLEANUP:
-        mp_clear(&k);
-        mp_clear(&k3);
-        mp_clear(&qx);
-        mp_clear(&qy);
-        mp_clear(&sx);
-        mp_clear(&sy);
-        return res;
-}
-#endif
-
-/* Validates a point on a GFp curve. */
-mp_err
-ec_GFp_validate_point(const mp_int *px, const mp_int *py, const ECGroup *group)
-{
-        mp_err res = MP_NO;
-        mp_int accl, accr, tmp, pxt, pyt;
-
-        MP_DIGITS(&accl) = 0;
-        MP_DIGITS(&accr) = 0;
-        MP_DIGITS(&tmp) = 0;
-        MP_DIGITS(&pxt) = 0;
-        MP_DIGITS(&pyt) = 0;
-        MP_CHECKOK(mp_init(&accl, FLAG(px)));
-        MP_CHECKOK(mp_init(&accr, FLAG(px)));
-        MP_CHECKOK(mp_init(&tmp, FLAG(px)));
-        MP_CHECKOK(mp_init(&pxt, FLAG(px)));
-        MP_CHECKOK(mp_init(&pyt, FLAG(px)));
-
-    /* 1: Verify that publicValue is not the point at infinity */
-        if (ec_GFp_pt_is_inf_aff(px, py) == MP_YES) {
-                res = MP_NO;
-                goto CLEANUP;
-        }
-    /* 2: Verify that the coordinates of publicValue are elements
-     *    of the field.
-     */
-        if ((MP_SIGN(px) == MP_NEG) || (mp_cmp(px, &group->meth->irr) >= 0) ||
-                (MP_SIGN(py) == MP_NEG) || (mp_cmp(py, &group->meth->irr) >= 0)) {
-                res = MP_NO;
-                goto CLEANUP;
-        }
-    /* 3: Verify that publicValue is on the curve. */
-        if (group->meth->field_enc) {
-                group->meth->field_enc(px, &pxt, group->meth);
-                group->meth->field_enc(py, &pyt, group->meth);
-        } else {
-                mp_copy(px, &pxt);
-                mp_copy(py, &pyt);
-        }
-        /* left-hand side: y^2  */
-        MP_CHECKOK( group->meth->field_sqr(&pyt, &accl, group->meth) );
-        /* right-hand side: x^3 + a*x + b */
-        MP_CHECKOK( group->meth->field_sqr(&pxt, &tmp, group->meth) );
-        MP_CHECKOK( group->meth->field_mul(&pxt, &tmp, &accr, group->meth) );
-        MP_CHECKOK( group->meth->field_mul(&group->curvea, &pxt, &tmp, group->meth) );
-        MP_CHECKOK( group->meth->field_add(&tmp, &accr, &accr, group->meth) );
-        MP_CHECKOK( group->meth->field_add(&accr, &group->curveb, &accr, group->meth) );
-        /* check LHS - RHS == 0 */
-        MP_CHECKOK( group->meth->field_sub(&accl, &accr, &accr, group->meth) );
-        if (mp_cmp_z(&accr) != 0) {
-                res = MP_NO;
-                goto CLEANUP;
-        }
-    /* 4: Verify that the order of the curve times the publicValue
-     *    is the point at infinity.
-     */
-        MP_CHECKOK( ECPoint_mul(group, &group->order, px, py, &pxt, &pyt) );
-        if (ec_GFp_pt_is_inf_aff(&pxt, &pyt) != MP_YES) {
-                res = MP_NO;
-                goto CLEANUP;
-        }
-
-        res = MP_YES;
-
-CLEANUP:
-        mp_clear(&accl);
-        mp_clear(&accr);
-        mp_clear(&tmp);
-        mp_clear(&pxt);
-        mp_clear(&pyt);
-        return res;
-}
--- a/jdk/src/share/native/sun/security/ec/ecp_jac.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,575 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library for prime field curves.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Sheueling Chang-Shantz <sheueling.chang@sun.com>,
- *   Stephen Fung <fungstep@hotmail.com>, and
- *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories.
- *   Bodo Moeller <moeller@cdc.informatik.tu-darmstadt.de>,
- *   Nils Larsch <nla@trustcenter.de>, and
- *   Lenka Fibikova <fibikova@exp-math.uni-essen.de>, the OpenSSL Project
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "ecp.h"
-#include "mplogic.h"
-#ifndef _KERNEL
-#include <stdlib.h>
-#endif
-#ifdef ECL_DEBUG
-#include <assert.h>
-#endif
-
-/* Converts a point P(px, py) from affine coordinates to Jacobian
- * projective coordinates R(rx, ry, rz). Assumes input is already
- * field-encoded using field_enc, and returns output that is still
- * field-encoded. */
-mp_err
-ec_GFp_pt_aff2jac(const mp_int *px, const mp_int *py, mp_int *rx,
-                                  mp_int *ry, mp_int *rz, const ECGroup *group)
-{
-        mp_err res = MP_OKAY;
-
-        if (ec_GFp_pt_is_inf_aff(px, py) == MP_YES) {
-                MP_CHECKOK(ec_GFp_pt_set_inf_jac(rx, ry, rz));
-        } else {
-                MP_CHECKOK(mp_copy(px, rx));
-                MP_CHECKOK(mp_copy(py, ry));
-                MP_CHECKOK(mp_set_int(rz, 1));
-                if (group->meth->field_enc) {
-                        MP_CHECKOK(group->meth->field_enc(rz, rz, group->meth));
-                }
-        }
-  CLEANUP:
-        return res;
-}
-
-/* Converts a point P(px, py, pz) from Jacobian projective coordinates to
- * affine coordinates R(rx, ry).  P and R can share x and y coordinates.
- * Assumes input is already field-encoded using field_enc, and returns
- * output that is still field-encoded. */
-mp_err
-ec_GFp_pt_jac2aff(const mp_int *px, const mp_int *py, const mp_int *pz,
-                                  mp_int *rx, mp_int *ry, const ECGroup *group)
-{
-        mp_err res = MP_OKAY;
-        mp_int z1, z2, z3;
-
-        MP_DIGITS(&z1) = 0;
-        MP_DIGITS(&z2) = 0;
-        MP_DIGITS(&z3) = 0;
-        MP_CHECKOK(mp_init(&z1, FLAG(px)));
-        MP_CHECKOK(mp_init(&z2, FLAG(px)));
-        MP_CHECKOK(mp_init(&z3, FLAG(px)));
-
-        /* if point at infinity, then set point at infinity and exit */
-        if (ec_GFp_pt_is_inf_jac(px, py, pz) == MP_YES) {
-                MP_CHECKOK(ec_GFp_pt_set_inf_aff(rx, ry));
-                goto CLEANUP;
-        }
-
-        /* transform (px, py, pz) into (px / pz^2, py / pz^3) */
-        if (mp_cmp_d(pz, 1) == 0) {
-                MP_CHECKOK(mp_copy(px, rx));
-                MP_CHECKOK(mp_copy(py, ry));
-        } else {
-                MP_CHECKOK(group->meth->field_div(NULL, pz, &z1, group->meth));
-                MP_CHECKOK(group->meth->field_sqr(&z1, &z2, group->meth));
-                MP_CHECKOK(group->meth->field_mul(&z1, &z2, &z3, group->meth));
-                MP_CHECKOK(group->meth->field_mul(px, &z2, rx, group->meth));
-                MP_CHECKOK(group->meth->field_mul(py, &z3, ry, group->meth));
-        }
-
-  CLEANUP:
-        mp_clear(&z1);
-        mp_clear(&z2);
-        mp_clear(&z3);
-        return res;
-}
-
-/* Checks if point P(px, py, pz) is at infinity. Uses Jacobian
- * coordinates. */
-mp_err
-ec_GFp_pt_is_inf_jac(const mp_int *px, const mp_int *py, const mp_int *pz)
-{
-        return mp_cmp_z(pz);
-}
-
-/* Sets P(px, py, pz) to be the point at infinity.  Uses Jacobian
- * coordinates. */
-mp_err
-ec_GFp_pt_set_inf_jac(mp_int *px, mp_int *py, mp_int *pz)
-{
-        mp_zero(pz);
-        return MP_OKAY;
-}
-
-/* Computes R = P + Q where R is (rx, ry, rz), P is (px, py, pz) and Q is
- * (qx, qy, 1).  Elliptic curve points P, Q, and R can all be identical.
- * Uses mixed Jacobian-affine coordinates. Assumes input is already
- * field-encoded using field_enc, and returns output that is still
- * field-encoded. Uses equation (2) from Brown, Hankerson, Lopez, and
- * Menezes. Software Implementation of the NIST Elliptic Curves Over Prime
- * Fields. */
-mp_err
-ec_GFp_pt_add_jac_aff(const mp_int *px, const mp_int *py, const mp_int *pz,
-                                          const mp_int *qx, const mp_int *qy, mp_int *rx,
-                                          mp_int *ry, mp_int *rz, const ECGroup *group)
-{
-        mp_err res = MP_OKAY;
-        mp_int A, B, C, D, C2, C3;
-
-        MP_DIGITS(&A) = 0;
-        MP_DIGITS(&B) = 0;
-        MP_DIGITS(&C) = 0;
-        MP_DIGITS(&D) = 0;
-        MP_DIGITS(&C2) = 0;
-        MP_DIGITS(&C3) = 0;
-        MP_CHECKOK(mp_init(&A, FLAG(px)));
-        MP_CHECKOK(mp_init(&B, FLAG(px)));
-        MP_CHECKOK(mp_init(&C, FLAG(px)));
-        MP_CHECKOK(mp_init(&D, FLAG(px)));
-        MP_CHECKOK(mp_init(&C2, FLAG(px)));
-        MP_CHECKOK(mp_init(&C3, FLAG(px)));
-
-        /* If either P or Q is the point at infinity, then return the other
-         * point */
-        if (ec_GFp_pt_is_inf_jac(px, py, pz) == MP_YES) {
-                MP_CHECKOK(ec_GFp_pt_aff2jac(qx, qy, rx, ry, rz, group));
-                goto CLEANUP;
-        }
-        if (ec_GFp_pt_is_inf_aff(qx, qy) == MP_YES) {
-                MP_CHECKOK(mp_copy(px, rx));
-                MP_CHECKOK(mp_copy(py, ry));
-                MP_CHECKOK(mp_copy(pz, rz));
-                goto CLEANUP;
-        }
-
-        /* A = qx * pz^2, B = qy * pz^3 */
-        MP_CHECKOK(group->meth->field_sqr(pz, &A, group->meth));
-        MP_CHECKOK(group->meth->field_mul(&A, pz, &B, group->meth));
-        MP_CHECKOK(group->meth->field_mul(&A, qx, &A, group->meth));
-        MP_CHECKOK(group->meth->field_mul(&B, qy, &B, group->meth));
-
-        /* C = A - px, D = B - py */
-        MP_CHECKOK(group->meth->field_sub(&A, px, &C, group->meth));
-        MP_CHECKOK(group->meth->field_sub(&B, py, &D, group->meth));
-
-        /* C2 = C^2, C3 = C^3 */
-        MP_CHECKOK(group->meth->field_sqr(&C, &C2, group->meth));
-        MP_CHECKOK(group->meth->field_mul(&C, &C2, &C3, group->meth));
-
-        /* rz = pz * C */
-        MP_CHECKOK(group->meth->field_mul(pz, &C, rz, group->meth));
-
-        /* C = px * C^2 */
-        MP_CHECKOK(group->meth->field_mul(px, &C2, &C, group->meth));
-        /* A = D^2 */
-        MP_CHECKOK(group->meth->field_sqr(&D, &A, group->meth));
-
-        /* rx = D^2 - (C^3 + 2 * (px * C^2)) */
-        MP_CHECKOK(group->meth->field_add(&C, &C, rx, group->meth));
-        MP_CHECKOK(group->meth->field_add(&C3, rx, rx, group->meth));
-        MP_CHECKOK(group->meth->field_sub(&A, rx, rx, group->meth));
-
-        /* C3 = py * C^3 */
-        MP_CHECKOK(group->meth->field_mul(py, &C3, &C3, group->meth));
-
-        /* ry = D * (px * C^2 - rx) - py * C^3 */
-        MP_CHECKOK(group->meth->field_sub(&C, rx, ry, group->meth));
-        MP_CHECKOK(group->meth->field_mul(&D, ry, ry, group->meth));
-        MP_CHECKOK(group->meth->field_sub(ry, &C3, ry, group->meth));
-
-  CLEANUP:
-        mp_clear(&A);
-        mp_clear(&B);
-        mp_clear(&C);
-        mp_clear(&D);
-        mp_clear(&C2);
-        mp_clear(&C3);
-        return res;
-}
-
-/* Computes R = 2P.  Elliptic curve points P and R can be identical.  Uses
- * Jacobian coordinates.
- *
- * Assumes input is already field-encoded using field_enc, and returns
- * output that is still field-encoded.
- *
- * This routine implements Point Doubling in the Jacobian Projective
- * space as described in the paper "Efficient elliptic curve exponentiation
- * using mixed coordinates", by H. Cohen, A Miyaji, T. Ono.
- */
-mp_err
-ec_GFp_pt_dbl_jac(const mp_int *px, const mp_int *py, const mp_int *pz,
-                                  mp_int *rx, mp_int *ry, mp_int *rz, const ECGroup *group)
-{
-        mp_err res = MP_OKAY;
-        mp_int t0, t1, M, S;
-
-        MP_DIGITS(&t0) = 0;
-        MP_DIGITS(&t1) = 0;
-        MP_DIGITS(&M) = 0;
-        MP_DIGITS(&S) = 0;
-        MP_CHECKOK(mp_init(&t0, FLAG(px)));
-        MP_CHECKOK(mp_init(&t1, FLAG(px)));
-        MP_CHECKOK(mp_init(&M, FLAG(px)));
-        MP_CHECKOK(mp_init(&S, FLAG(px)));
-
-        if (ec_GFp_pt_is_inf_jac(px, py, pz) == MP_YES) {
-                MP_CHECKOK(ec_GFp_pt_set_inf_jac(rx, ry, rz));
-                goto CLEANUP;
-        }
-
-        if (mp_cmp_d(pz, 1) == 0) {
-                /* M = 3 * px^2 + a */
-                MP_CHECKOK(group->meth->field_sqr(px, &t0, group->meth));
-                MP_CHECKOK(group->meth->field_add(&t0, &t0, &M, group->meth));
-                MP_CHECKOK(group->meth->field_add(&t0, &M, &t0, group->meth));
-                MP_CHECKOK(group->meth->
-                                   field_add(&t0, &group->curvea, &M, group->meth));
-        } else if (mp_cmp_int(&group->curvea, -3, FLAG(px)) == 0) {
-                /* M = 3 * (px + pz^2) * (px - pz^2) */
-                MP_CHECKOK(group->meth->field_sqr(pz, &M, group->meth));
-                MP_CHECKOK(group->meth->field_add(px, &M, &t0, group->meth));
-                MP_CHECKOK(group->meth->field_sub(px, &M, &t1, group->meth));
-                MP_CHECKOK(group->meth->field_mul(&t0, &t1, &M, group->meth));
-                MP_CHECKOK(group->meth->field_add(&M, &M, &t0, group->meth));
-                MP_CHECKOK(group->meth->field_add(&t0, &M, &M, group->meth));
-        } else {
-                /* M = 3 * (px^2) + a * (pz^4) */
-                MP_CHECKOK(group->meth->field_sqr(px, &t0, group->meth));
-                MP_CHECKOK(group->meth->field_add(&t0, &t0, &M, group->meth));
-                MP_CHECKOK(group->meth->field_add(&t0, &M, &t0, group->meth));
-                MP_CHECKOK(group->meth->field_sqr(pz, &M, group->meth));
-                MP_CHECKOK(group->meth->field_sqr(&M, &M, group->meth));
-                MP_CHECKOK(group->meth->
-                                   field_mul(&M, &group->curvea, &M, group->meth));
-                MP_CHECKOK(group->meth->field_add(&M, &t0, &M, group->meth));
-        }
-
-        /* rz = 2 * py * pz */
-        /* t0 = 4 * py^2 */
-        if (mp_cmp_d(pz, 1) == 0) {
-                MP_CHECKOK(group->meth->field_add(py, py, rz, group->meth));
-                MP_CHECKOK(group->meth->field_sqr(rz, &t0, group->meth));
-        } else {
-                MP_CHECKOK(group->meth->field_add(py, py, &t0, group->meth));
-                MP_CHECKOK(group->meth->field_mul(&t0, pz, rz, group->meth));
-                MP_CHECKOK(group->meth->field_sqr(&t0, &t0, group->meth));
-        }
-
-        /* S = 4 * px * py^2 = px * (2 * py)^2 */
-        MP_CHECKOK(group->meth->field_mul(px, &t0, &S, group->meth));
-
-        /* rx = M^2 - 2 * S */
-        MP_CHECKOK(group->meth->field_add(&S, &S, &t1, group->meth));
-        MP_CHECKOK(group->meth->field_sqr(&M, rx, group->meth));
-        MP_CHECKOK(group->meth->field_sub(rx, &t1, rx, group->meth));
-
-        /* ry = M * (S - rx) - 8 * py^4 */
-        MP_CHECKOK(group->meth->field_sqr(&t0, &t1, group->meth));
-        if (mp_isodd(&t1)) {
-                MP_CHECKOK(mp_add(&t1, &group->meth->irr, &t1));
-        }
-        MP_CHECKOK(mp_div_2(&t1, &t1));
-        MP_CHECKOK(group->meth->field_sub(&S, rx, &S, group->meth));
-        MP_CHECKOK(group->meth->field_mul(&M, &S, &M, group->meth));
-        MP_CHECKOK(group->meth->field_sub(&M, &t1, ry, group->meth));
-
-  CLEANUP:
-        mp_clear(&t0);
-        mp_clear(&t1);
-        mp_clear(&M);
-        mp_clear(&S);
-        return res;
-}
-
-/* by default, this routine is unused and thus doesn't need to be compiled */
-#ifdef ECL_ENABLE_GFP_PT_MUL_JAC
-/* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters
- * a, b and p are the elliptic curve coefficients and the prime that
- * determines the field GFp.  Elliptic curve points P and R can be
- * identical.  Uses mixed Jacobian-affine coordinates. Assumes input is
- * already field-encoded using field_enc, and returns output that is still
- * field-encoded. Uses 4-bit window method. */
-mp_err
-ec_GFp_pt_mul_jac(const mp_int *n, const mp_int *px, const mp_int *py,
-                                  mp_int *rx, mp_int *ry, const ECGroup *group)
-{
-        mp_err res = MP_OKAY;
-        mp_int precomp[16][2], rz;
-        int i, ni, d;
-
-        MP_DIGITS(&rz) = 0;
-        for (i = 0; i < 16; i++) {
-                MP_DIGITS(&precomp[i][0]) = 0;
-                MP_DIGITS(&precomp[i][1]) = 0;
-        }
-
-        ARGCHK(group != NULL, MP_BADARG);
-        ARGCHK((n != NULL) && (px != NULL) && (py != NULL), MP_BADARG);
-
-        /* initialize precomputation table */
-        for (i = 0; i < 16; i++) {
-                MP_CHECKOK(mp_init(&precomp[i][0]));
-                MP_CHECKOK(mp_init(&precomp[i][1]));
-        }
-
-        /* fill precomputation table */
-        mp_zero(&precomp[0][0]);
-        mp_zero(&precomp[0][1]);
-        MP_CHECKOK(mp_copy(px, &precomp[1][0]));
-        MP_CHECKOK(mp_copy(py, &precomp[1][1]));
-        for (i = 2; i < 16; i++) {
-                MP_CHECKOK(group->
-                                   point_add(&precomp[1][0], &precomp[1][1],
-                                                         &precomp[i - 1][0], &precomp[i - 1][1],
-                                                         &precomp[i][0], &precomp[i][1], group));
-        }
-
-        d = (mpl_significant_bits(n) + 3) / 4;
-
-        /* R = inf */
-        MP_CHECKOK(mp_init(&rz));
-        MP_CHECKOK(ec_GFp_pt_set_inf_jac(rx, ry, &rz));
-
-        for (i = d - 1; i >= 0; i--) {
-                /* compute window ni */
-                ni = MP_GET_BIT(n, 4 * i + 3);
-                ni <<= 1;
-                ni |= MP_GET_BIT(n, 4 * i + 2);
-                ni <<= 1;
-                ni |= MP_GET_BIT(n, 4 * i + 1);
-                ni <<= 1;
-                ni |= MP_GET_BIT(n, 4 * i);
-                /* R = 2^4 * R */
-                MP_CHECKOK(ec_GFp_pt_dbl_jac(rx, ry, &rz, rx, ry, &rz, group));
-                MP_CHECKOK(ec_GFp_pt_dbl_jac(rx, ry, &rz, rx, ry, &rz, group));
-                MP_CHECKOK(ec_GFp_pt_dbl_jac(rx, ry, &rz, rx, ry, &rz, group));
-                MP_CHECKOK(ec_GFp_pt_dbl_jac(rx, ry, &rz, rx, ry, &rz, group));
-                /* R = R + (ni * P) */
-                MP_CHECKOK(ec_GFp_pt_add_jac_aff
-                                   (rx, ry, &rz, &precomp[ni][0], &precomp[ni][1], rx, ry,
-                                        &rz, group));
-        }
-
-        /* convert result S to affine coordinates */
-        MP_CHECKOK(ec_GFp_pt_jac2aff(rx, ry, &rz, rx, ry, group));
-
-  CLEANUP:
-        mp_clear(&rz);
-        for (i = 0; i < 16; i++) {
-                mp_clear(&precomp[i][0]);
-                mp_clear(&precomp[i][1]);
-        }
-        return res;
-}
-#endif
-
-/* Elliptic curve scalar-point multiplication. Computes R(x, y) = k1 * G +
- * k2 * P(x, y), where G is the generator (base point) of the group of
- * points on the elliptic curve. Allows k1 = NULL or { k2, P } = NULL.
- * Uses mixed Jacobian-affine coordinates. Input and output values are
- * assumed to be NOT field-encoded. Uses algorithm 15 (simultaneous
- * multiple point multiplication) from Brown, Hankerson, Lopez, Menezes.
- * Software Implementation of the NIST Elliptic Curves over Prime Fields. */
-mp_err
-ec_GFp_pts_mul_jac(const mp_int *k1, const mp_int *k2, const mp_int *px,
-                                   const mp_int *py, mp_int *rx, mp_int *ry,
-                                   const ECGroup *group)
-{
-        mp_err res = MP_OKAY;
-        mp_int precomp[4][4][2];
-        mp_int rz;
-        const mp_int *a, *b;
-        int i, j;
-        int ai, bi, d;
-
-        for (i = 0; i < 4; i++) {
-                for (j = 0; j < 4; j++) {
-                        MP_DIGITS(&precomp[i][j][0]) = 0;
-                        MP_DIGITS(&precomp[i][j][1]) = 0;
-                }
-        }
-        MP_DIGITS(&rz) = 0;
-
-        ARGCHK(group != NULL, MP_BADARG);
-        ARGCHK(!((k1 == NULL)
-                         && ((k2 == NULL) || (px == NULL)
-                                 || (py == NULL))), MP_BADARG);
-
-        /* if some arguments are not defined used ECPoint_mul */
-        if (k1 == NULL) {
-                return ECPoint_mul(group, k2, px, py, rx, ry);
-        } else if ((k2 == NULL) || (px == NULL) || (py == NULL)) {
-                return ECPoint_mul(group, k1, NULL, NULL, rx, ry);
-        }
-
-        /* initialize precomputation table */
-        for (i = 0; i < 4; i++) {
-                for (j = 0; j < 4; j++) {
-                        MP_CHECKOK(mp_init(&precomp[i][j][0], FLAG(k1)));
-                        MP_CHECKOK(mp_init(&precomp[i][j][1], FLAG(k1)));
-                }
-        }
-
-        /* fill precomputation table */
-        /* assign {k1, k2} = {a, b} such that len(a) >= len(b) */
-        if (mpl_significant_bits(k1) < mpl_significant_bits(k2)) {
-                a = k2;
-                b = k1;
-                if (group->meth->field_enc) {
-                        MP_CHECKOK(group->meth->
-                                           field_enc(px, &precomp[1][0][0], group->meth));
-                        MP_CHECKOK(group->meth->
-                                           field_enc(py, &precomp[1][0][1], group->meth));
-                } else {
-                        MP_CHECKOK(mp_copy(px, &precomp[1][0][0]));
-                        MP_CHECKOK(mp_copy(py, &precomp[1][0][1]));
-                }
-                MP_CHECKOK(mp_copy(&group->genx, &precomp[0][1][0]));
-                MP_CHECKOK(mp_copy(&group->geny, &precomp[0][1][1]));
-        } else {
-                a = k1;
-                b = k2;
-                MP_CHECKOK(mp_copy(&group->genx, &precomp[1][0][0]));
-                MP_CHECKOK(mp_copy(&group->geny, &precomp[1][0][1]));
-                if (group->meth->field_enc) {
-                        MP_CHECKOK(group->meth->
-                                           field_enc(px, &precomp[0][1][0], group->meth));
-                        MP_CHECKOK(group->meth->
-                                           field_enc(py, &precomp[0][1][1], group->meth));
-                } else {
-                        MP_CHECKOK(mp_copy(px, &precomp[0][1][0]));
-                        MP_CHECKOK(mp_copy(py, &precomp[0][1][1]));
-                }
-        }
-        /* precompute [*][0][*] */
-        mp_zero(&precomp[0][0][0]);
-        mp_zero(&precomp[0][0][1]);
-        MP_CHECKOK(group->
-                           point_dbl(&precomp[1][0][0], &precomp[1][0][1],
-                                                 &precomp[2][0][0], &precomp[2][0][1], group));
-        MP_CHECKOK(group->
-                           point_add(&precomp[1][0][0], &precomp[1][0][1],
-                                                 &precomp[2][0][0], &precomp[2][0][1],
-                                                 &precomp[3][0][0], &precomp[3][0][1], group));
-        /* precompute [*][1][*] */
-        for (i = 1; i < 4; i++) {
-                MP_CHECKOK(group->
-                                   point_add(&precomp[0][1][0], &precomp[0][1][1],
-                                                         &precomp[i][0][0], &precomp[i][0][1],
-                                                         &precomp[i][1][0], &precomp[i][1][1], group));
-        }
-        /* precompute [*][2][*] */
-        MP_CHECKOK(group->
-                           point_dbl(&precomp[0][1][0], &precomp[0][1][1],
-                                                 &precomp[0][2][0], &precomp[0][2][1], group));
-        for (i = 1; i < 4; i++) {
-                MP_CHECKOK(group->
-                                   point_add(&precomp[0][2][0], &precomp[0][2][1],
-                                                         &precomp[i][0][0], &precomp[i][0][1],
-                                                         &precomp[i][2][0], &precomp[i][2][1], group));
-        }
-        /* precompute [*][3][*] */
-        MP_CHECKOK(group->
-                           point_add(&precomp[0][1][0], &precomp[0][1][1],
-                                                 &precomp[0][2][0], &precomp[0][2][1],
-                                                 &precomp[0][3][0], &precomp[0][3][1], group));
-        for (i = 1; i < 4; i++) {
-                MP_CHECKOK(group->
-                                   point_add(&precomp[0][3][0], &precomp[0][3][1],
-                                                         &precomp[i][0][0], &precomp[i][0][1],
-                                                         &precomp[i][3][0], &precomp[i][3][1], group));
-        }
-
-        d = (mpl_significant_bits(a) + 1) / 2;
-
-        /* R = inf */
-        MP_CHECKOK(mp_init(&rz, FLAG(k1)));
-        MP_CHECKOK(ec_GFp_pt_set_inf_jac(rx, ry, &rz));
-
-        for (i = d - 1; i >= 0; i--) {
-                ai = MP_GET_BIT(a, 2 * i + 1);
-                ai <<= 1;
-                ai |= MP_GET_BIT(a, 2 * i);
-                bi = MP_GET_BIT(b, 2 * i + 1);
-                bi <<= 1;
-                bi |= MP_GET_BIT(b, 2 * i);
-                /* R = 2^2 * R */
-                MP_CHECKOK(ec_GFp_pt_dbl_jac(rx, ry, &rz, rx, ry, &rz, group));
-                MP_CHECKOK(ec_GFp_pt_dbl_jac(rx, ry, &rz, rx, ry, &rz, group));
-                /* R = R + (ai * A + bi * B) */
-                MP_CHECKOK(ec_GFp_pt_add_jac_aff
-                                   (rx, ry, &rz, &precomp[ai][bi][0], &precomp[ai][bi][1],
-                                        rx, ry, &rz, group));
-        }
-
-        MP_CHECKOK(ec_GFp_pt_jac2aff(rx, ry, &rz, rx, ry, group));
-
-        if (group->meth->field_dec) {
-                MP_CHECKOK(group->meth->field_dec(rx, rx, group->meth));
-                MP_CHECKOK(group->meth->field_dec(ry, ry, group->meth));
-        }
-
-  CLEANUP:
-        mp_clear(&rz);
-        for (i = 0; i < 4; i++) {
-                for (j = 0; j < 4; j++) {
-                        mp_clear(&precomp[i][j][0]);
-                        mp_clear(&precomp[i][j][1]);
-                }
-        }
-        return res;
-}
--- a/jdk/src/share/native/sun/security/ec/ecp_jm.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,353 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library for prime field curves.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Stephen Fung <fungstep@hotmail.com>, Sun Microsystems Laboratories
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "ecp.h"
-#include "ecl-priv.h"
-#include "mplogic.h"
-#ifndef _KERNEL
-#include <stdlib.h>
-#endif
-
-#define MAX_SCRATCH 6
-
-/* Computes R = 2P.  Elliptic curve points P and R can be identical.  Uses
- * Modified Jacobian coordinates.
- *
- * Assumes input is already field-encoded using field_enc, and returns
- * output that is still field-encoded.
- *
- */
-mp_err
-ec_GFp_pt_dbl_jm(const mp_int *px, const mp_int *py, const mp_int *pz,
-                                 const mp_int *paz4, mp_int *rx, mp_int *ry, mp_int *rz,
-                                 mp_int *raz4, mp_int scratch[], const ECGroup *group)
-{
-        mp_err res = MP_OKAY;
-        mp_int *t0, *t1, *M, *S;
-
-        t0 = &scratch[0];
-        t1 = &scratch[1];
-        M = &scratch[2];
-        S = &scratch[3];
-
-#if MAX_SCRATCH < 4
-#error "Scratch array defined too small "
-#endif
-
-        /* Check for point at infinity */
-        if (ec_GFp_pt_is_inf_jac(px, py, pz) == MP_YES) {
-                /* Set r = pt at infinity by setting rz = 0 */
-
-                MP_CHECKOK(ec_GFp_pt_set_inf_jac(rx, ry, rz));
-                goto CLEANUP;
-        }
-
-        /* M = 3 (px^2) + a*(pz^4) */
-        MP_CHECKOK(group->meth->field_sqr(px, t0, group->meth));
-        MP_CHECKOK(group->meth->field_add(t0, t0, M, group->meth));
-        MP_CHECKOK(group->meth->field_add(t0, M, t0, group->meth));
-        MP_CHECKOK(group->meth->field_add(t0, paz4, M, group->meth));
-
-        /* rz = 2 * py * pz */
-        MP_CHECKOK(group->meth->field_mul(py, pz, S, group->meth));
-        MP_CHECKOK(group->meth->field_add(S, S, rz, group->meth));
-
-        /* t0 = 2y^2 , t1 = 8y^4 */
-        MP_CHECKOK(group->meth->field_sqr(py, t0, group->meth));
-        MP_CHECKOK(group->meth->field_add(t0, t0, t0, group->meth));
-        MP_CHECKOK(group->meth->field_sqr(t0, t1, group->meth));
-        MP_CHECKOK(group->meth->field_add(t1, t1, t1, group->meth));
-
-        /* S = 4 * px * py^2 = 2 * px * t0 */
-        MP_CHECKOK(group->meth->field_mul(px, t0, S, group->meth));
-        MP_CHECKOK(group->meth->field_add(S, S, S, group->meth));
-
-
-        /* rx = M^2 - 2S */
-        MP_CHECKOK(group->meth->field_sqr(M, rx, group->meth));
-        MP_CHECKOK(group->meth->field_sub(rx, S, rx, group->meth));
-        MP_CHECKOK(group->meth->field_sub(rx, S, rx, group->meth));
-
-        /* ry = M * (S - rx) - t1 */
-        MP_CHECKOK(group->meth->field_sub(S, rx, S, group->meth));
-        MP_CHECKOK(group->meth->field_mul(S, M, ry, group->meth));
-        MP_CHECKOK(group->meth->field_sub(ry, t1, ry, group->meth));
-
-        /* ra*z^4 = 2*t1*(apz4) */
-        MP_CHECKOK(group->meth->field_mul(paz4, t1, raz4, group->meth));
-        MP_CHECKOK(group->meth->field_add(raz4, raz4, raz4, group->meth));
-
-
-  CLEANUP:
-        return res;
-}
-
-/* Computes R = P + Q where R is (rx, ry, rz), P is (px, py, pz) and Q is
- * (qx, qy, 1).  Elliptic curve points P, Q, and R can all be identical.
- * Uses mixed Modified_Jacobian-affine coordinates. Assumes input is
- * already field-encoded using field_enc, and returns output that is still
- * field-encoded. */
-mp_err
-ec_GFp_pt_add_jm_aff(const mp_int *px, const mp_int *py, const mp_int *pz,
-                                         const mp_int *paz4, const mp_int *qx,
-                                         const mp_int *qy, mp_int *rx, mp_int *ry, mp_int *rz,
-                                         mp_int *raz4, mp_int scratch[], const ECGroup *group)
-{
-        mp_err res = MP_OKAY;
-        mp_int *A, *B, *C, *D, *C2, *C3;
-
-        A = &scratch[0];
-        B = &scratch[1];
-        C = &scratch[2];
-        D = &scratch[3];
-        C2 = &scratch[4];
-        C3 = &scratch[5];
-
-#if MAX_SCRATCH < 6
-#error "Scratch array defined too small "
-#endif
-
-        /* If either P or Q is the point at infinity, then return the other
-         * point */
-        if (ec_GFp_pt_is_inf_jac(px, py, pz) == MP_YES) {
-                MP_CHECKOK(ec_GFp_pt_aff2jac(qx, qy, rx, ry, rz, group));
-                MP_CHECKOK(group->meth->field_sqr(rz, raz4, group->meth));
-                MP_CHECKOK(group->meth->field_sqr(raz4, raz4, group->meth));
-                MP_CHECKOK(group->meth->
-                                   field_mul(raz4, &group->curvea, raz4, group->meth));
-                goto CLEANUP;
-        }
-        if (ec_GFp_pt_is_inf_aff(qx, qy) == MP_YES) {
-                MP_CHECKOK(mp_copy(px, rx));
-                MP_CHECKOK(mp_copy(py, ry));
-                MP_CHECKOK(mp_copy(pz, rz));
-                MP_CHECKOK(mp_copy(paz4, raz4));
-                goto CLEANUP;
-        }
-
-        /* A = qx * pz^2, B = qy * pz^3 */
-        MP_CHECKOK(group->meth->field_sqr(pz, A, group->meth));
-        MP_CHECKOK(group->meth->field_mul(A, pz, B, group->meth));
-        MP_CHECKOK(group->meth->field_mul(A, qx, A, group->meth));
-        MP_CHECKOK(group->meth->field_mul(B, qy, B, group->meth));
-
-        /* C = A - px, D = B - py */
-        MP_CHECKOK(group->meth->field_sub(A, px, C, group->meth));
-        MP_CHECKOK(group->meth->field_sub(B, py, D, group->meth));
-
-        /* C2 = C^2, C3 = C^3 */
-        MP_CHECKOK(group->meth->field_sqr(C, C2, group->meth));
-        MP_CHECKOK(group->meth->field_mul(C, C2, C3, group->meth));
-
-        /* rz = pz * C */
-        MP_CHECKOK(group->meth->field_mul(pz, C, rz, group->meth));
-
-        /* C = px * C^2 */
-        MP_CHECKOK(group->meth->field_mul(px, C2, C, group->meth));
-        /* A = D^2 */
-        MP_CHECKOK(group->meth->field_sqr(D, A, group->meth));
-
-        /* rx = D^2 - (C^3 + 2 * (px * C^2)) */
-        MP_CHECKOK(group->meth->field_add(C, C, rx, group->meth));
-        MP_CHECKOK(group->meth->field_add(C3, rx, rx, group->meth));
-        MP_CHECKOK(group->meth->field_sub(A, rx, rx, group->meth));
-
-        /* C3 = py * C^3 */
-        MP_CHECKOK(group->meth->field_mul(py, C3, C3, group->meth));
-
-        /* ry = D * (px * C^2 - rx) - py * C^3 */
-        MP_CHECKOK(group->meth->field_sub(C, rx, ry, group->meth));
-        MP_CHECKOK(group->meth->field_mul(D, ry, ry, group->meth));
-        MP_CHECKOK(group->meth->field_sub(ry, C3, ry, group->meth));
-
-        /* raz4 = a * rz^4 */
-        MP_CHECKOK(group->meth->field_sqr(rz, raz4, group->meth));
-        MP_CHECKOK(group->meth->field_sqr(raz4, raz4, group->meth));
-        MP_CHECKOK(group->meth->
-                           field_mul(raz4, &group->curvea, raz4, group->meth));
-CLEANUP:
-        return res;
-}
-
-/* Computes R = nP where R is (rx, ry) and P is the base point. Elliptic
- * curve points P and R can be identical. Uses mixed Modified-Jacobian
- * co-ordinates for doubling and Chudnovsky Jacobian coordinates for
- * additions. Assumes input is already field-encoded using field_enc, and
- * returns output that is still field-encoded. Uses 5-bit window NAF
- * method (algorithm 11) for scalar-point multiplication from Brown,
- * Hankerson, Lopez, Menezes. Software Implementation of the NIST Elliptic
- * Curves Over Prime Fields. */
-mp_err
-ec_GFp_pt_mul_jm_wNAF(const mp_int *n, const mp_int *px, const mp_int *py,
-                                          mp_int *rx, mp_int *ry, const ECGroup *group)
-{
-        mp_err res = MP_OKAY;
-        mp_int precomp[16][2], rz, tpx, tpy;
-        mp_int raz4;
-        mp_int scratch[MAX_SCRATCH];
-        signed char *naf = NULL;
-        int i, orderBitSize;
-
-        MP_DIGITS(&rz) = 0;
-        MP_DIGITS(&raz4) = 0;
-        MP_DIGITS(&tpx) = 0;
-        MP_DIGITS(&tpy) = 0;
-        for (i = 0; i < 16; i++) {
-                MP_DIGITS(&precomp[i][0]) = 0;
-                MP_DIGITS(&precomp[i][1]) = 0;
-        }
-        for (i = 0; i < MAX_SCRATCH; i++) {
-                MP_DIGITS(&scratch[i]) = 0;
-        }
-
-        ARGCHK(group != NULL, MP_BADARG);
-        ARGCHK((n != NULL) && (px != NULL) && (py != NULL), MP_BADARG);
-
-        /* initialize precomputation table */
-        MP_CHECKOK(mp_init(&tpx, FLAG(n)));
-        MP_CHECKOK(mp_init(&tpy, FLAG(n)));;
-        MP_CHECKOK(mp_init(&rz, FLAG(n)));
-        MP_CHECKOK(mp_init(&raz4, FLAG(n)));
-
-        for (i = 0; i < 16; i++) {
-                MP_CHECKOK(mp_init(&precomp[i][0], FLAG(n)));
-                MP_CHECKOK(mp_init(&precomp[i][1], FLAG(n)));
-        }
-        for (i = 0; i < MAX_SCRATCH; i++) {
-                MP_CHECKOK(mp_init(&scratch[i], FLAG(n)));
-        }
-
-        /* Set out[8] = P */
-        MP_CHECKOK(mp_copy(px, &precomp[8][0]));
-        MP_CHECKOK(mp_copy(py, &precomp[8][1]));
-
-        /* Set (tpx, tpy) = 2P */
-        MP_CHECKOK(group->
-                           point_dbl(&precomp[8][0], &precomp[8][1], &tpx, &tpy,
-                                                 group));
-
-        /* Set 3P, 5P, ..., 15P */
-        for (i = 8; i < 15; i++) {
-                MP_CHECKOK(group->
-                                   point_add(&precomp[i][0], &precomp[i][1], &tpx, &tpy,
-                                                         &precomp[i + 1][0], &precomp[i + 1][1],
-                                                         group));
-        }
-
-        /* Set -15P, -13P, ..., -P */
-        for (i = 0; i < 8; i++) {
-                MP_CHECKOK(mp_copy(&precomp[15 - i][0], &precomp[i][0]));
-                MP_CHECKOK(group->meth->
-                                   field_neg(&precomp[15 - i][1], &precomp[i][1],
-                                                         group->meth));
-        }
-
-        /* R = inf */
-        MP_CHECKOK(ec_GFp_pt_set_inf_jac(rx, ry, &rz));
-
-        orderBitSize = mpl_significant_bits(&group->order);
-
-        /* Allocate memory for NAF */
-#ifdef _KERNEL
-        naf = (signed char *) kmem_alloc((orderBitSize + 1), FLAG(n));
-#else
-        naf = (signed char *) malloc(sizeof(signed char) * (orderBitSize + 1));
-        if (naf == NULL) {
-                res = MP_MEM;
-                goto CLEANUP;
-        }
-#endif
-
-        /* Compute 5NAF */
-        ec_compute_wNAF(naf, orderBitSize, n, 5);
-
-        /* wNAF method */
-        for (i = orderBitSize; i >= 0; i--) {
-                /* R = 2R */
-                ec_GFp_pt_dbl_jm(rx, ry, &rz, &raz4, rx, ry, &rz,
-                                             &raz4, scratch, group);
-                if (naf[i] != 0) {
-                        ec_GFp_pt_add_jm_aff(rx, ry, &rz, &raz4,
-                                                                 &precomp[(naf[i] + 15) / 2][0],
-                                                                 &precomp[(naf[i] + 15) / 2][1], rx, ry,
-                                                                 &rz, &raz4, scratch, group);
-                }
-        }
-
-        /* convert result S to affine coordinates */
-        MP_CHECKOK(ec_GFp_pt_jac2aff(rx, ry, &rz, rx, ry, group));
-
-  CLEANUP:
-        for (i = 0; i < MAX_SCRATCH; i++) {
-                mp_clear(&scratch[i]);
-        }
-        for (i = 0; i < 16; i++) {
-                mp_clear(&precomp[i][0]);
-                mp_clear(&precomp[i][1]);
-        }
-        mp_clear(&tpx);
-        mp_clear(&tpy);
-        mp_clear(&rz);
-        mp_clear(&raz4);
-#ifdef _KERNEL
-        kmem_free(naf, (orderBitSize + 1));
-#else
-        free(naf);
-#endif
-        return res;
-}
--- a/jdk/src/share/native/sun/security/ec/ecp_mont.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,223 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the elliptic curve math library.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-/* Uses Montgomery reduction for field arithmetic.  See mpi/mpmontg.c for
- * code implementation. */
-
-#include "mpi.h"
-#include "mplogic.h"
-#include "mpi-priv.h"
-#include "ecl-priv.h"
-#include "ecp.h"
-#ifndef _KERNEL
-#include <stdlib.h>
-#include <stdio.h>
-#endif
-
-/* Construct a generic GFMethod for arithmetic over prime fields with
- * irreducible irr. */
-GFMethod *
-GFMethod_consGFp_mont(const mp_int *irr)
-{
-        mp_err res = MP_OKAY;
-        int i;
-        GFMethod *meth = NULL;
-        mp_mont_modulus *mmm;
-
-        meth = GFMethod_consGFp(irr);
-        if (meth == NULL)
-                return NULL;
-
-#ifdef _KERNEL
-        mmm = (mp_mont_modulus *) kmem_alloc(sizeof(mp_mont_modulus),
-            FLAG(irr));
-#else
-        mmm = (mp_mont_modulus *) malloc(sizeof(mp_mont_modulus));
-#endif
-        if (mmm == NULL) {
-                res = MP_MEM;
-                goto CLEANUP;
-        }
-
-        meth->field_mul = &ec_GFp_mul_mont;
-        meth->field_sqr = &ec_GFp_sqr_mont;
-        meth->field_div = &ec_GFp_div_mont;
-        meth->field_enc = &ec_GFp_enc_mont;
-        meth->field_dec = &ec_GFp_dec_mont;
-        meth->extra1 = mmm;
-        meth->extra2 = NULL;
-        meth->extra_free = &ec_GFp_extra_free_mont;
-
-        mmm->N = meth->irr;
-        i = mpl_significant_bits(&meth->irr);
-        i += MP_DIGIT_BIT - 1;
-        mmm->b = i - i % MP_DIGIT_BIT;
-        mmm->n0prime = 0 - s_mp_invmod_radix(MP_DIGIT(&meth->irr, 0));
-
-  CLEANUP:
-        if (res != MP_OKAY) {
-                GFMethod_free(meth);
-                return NULL;
-        }
-        return meth;
-}
-
-/* Wrapper functions for generic prime field arithmetic. */
-
-/* Field multiplication using Montgomery reduction. */
-mp_err
-ec_GFp_mul_mont(const mp_int *a, const mp_int *b, mp_int *r,
-                                const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-
-#ifdef MP_MONT_USE_MP_MUL
-        /* if MP_MONT_USE_MP_MUL is defined, then the function s_mp_mul_mont
-         * is not implemented and we have to use mp_mul and s_mp_redc directly
-         */
-        MP_CHECKOK(mp_mul(a, b, r));
-        MP_CHECKOK(s_mp_redc(r, (mp_mont_modulus *) meth->extra1));
-#else
-        mp_int s;
-
-        MP_DIGITS(&s) = 0;
-        /* s_mp_mul_mont doesn't allow source and destination to be the same */
-        if ((a == r) || (b == r)) {
-                MP_CHECKOK(mp_init(&s, FLAG(a)));
-                MP_CHECKOK(s_mp_mul_mont
-                                   (a, b, &s, (mp_mont_modulus *) meth->extra1));
-                MP_CHECKOK(mp_copy(&s, r));
-                mp_clear(&s);
-        } else {
-                return s_mp_mul_mont(a, b, r, (mp_mont_modulus *) meth->extra1);
-        }
-#endif
-  CLEANUP:
-        return res;
-}
-
-/* Field squaring using Montgomery reduction. */
-mp_err
-ec_GFp_sqr_mont(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        return ec_GFp_mul_mont(a, a, r, meth);
-}
-
-/* Field division using Montgomery reduction. */
-mp_err
-ec_GFp_div_mont(const mp_int *a, const mp_int *b, mp_int *r,
-                                const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-
-        /* if A=aZ represents a encoded in montgomery coordinates with Z and #
-         * and \ respectively represent multiplication and division in
-         * montgomery coordinates, then A\B = (a/b)Z = (A/B)Z and Binv =
-         * (1/b)Z = (1/B)(Z^2) where B # Binv = Z */
-        MP_CHECKOK(ec_GFp_div(a, b, r, meth));
-        MP_CHECKOK(ec_GFp_enc_mont(r, r, meth));
-        if (a == NULL) {
-                MP_CHECKOK(ec_GFp_enc_mont(r, r, meth));
-        }
-  CLEANUP:
-        return res;
-}
-
-/* Encode a field element in Montgomery form. See s_mp_to_mont in
- * mpi/mpmontg.c */
-mp_err
-ec_GFp_enc_mont(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        mp_mont_modulus *mmm;
-        mp_err res = MP_OKAY;
-
-        mmm = (mp_mont_modulus *) meth->extra1;
-        MP_CHECKOK(mpl_lsh(a, r, mmm->b));
-        MP_CHECKOK(mp_mod(r, &mmm->N, r));
-  CLEANUP:
-        return res;
-}
-
-/* Decode a field element from Montgomery form. */
-mp_err
-ec_GFp_dec_mont(const mp_int *a, mp_int *r, const GFMethod *meth)
-{
-        mp_err res = MP_OKAY;
-
-        if (a != r) {
-                MP_CHECKOK(mp_copy(a, r));
-        }
-        MP_CHECKOK(s_mp_redc(r, (mp_mont_modulus *) meth->extra1));
-  CLEANUP:
-        return res;
-}
-
-/* Free the memory allocated to the extra fields of Montgomery GFMethod
- * object. */
-void
-ec_GFp_extra_free_mont(GFMethod *meth)
-{
-        if (meth->extra1 != NULL) {
-#ifdef _KERNEL
-                kmem_free(meth->extra1, sizeof(mp_mont_modulus));
-#else
-                free(meth->extra1);
-#endif
-                meth->extra1 = NULL;
-        }
-}
--- a/jdk/src/share/native/sun/security/ec/logtab.h	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,82 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Netscape security libraries.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1994-2000
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _LOGTAB_H
-#define _LOGTAB_H
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-const float s_logv_2[] = {
-   0.000000000f, 0.000000000f, 1.000000000f, 0.630929754f,  /*  0  1  2  3 */
-   0.500000000f, 0.430676558f, 0.386852807f, 0.356207187f,  /*  4  5  6  7 */
-   0.333333333f, 0.315464877f, 0.301029996f, 0.289064826f,  /*  8  9 10 11 */
-   0.278942946f, 0.270238154f, 0.262649535f, 0.255958025f,  /* 12 13 14 15 */
-   0.250000000f, 0.244650542f, 0.239812467f, 0.235408913f,  /* 16 17 18 19 */
-   0.231378213f, 0.227670249f, 0.224243824f, 0.221064729f,  /* 20 21 22 23 */
-   0.218104292f, 0.215338279f, 0.212746054f, 0.210309918f,  /* 24 25 26 27 */
-   0.208014598f, 0.205846832f, 0.203795047f, 0.201849087f,  /* 28 29 30 31 */
-   0.200000000f, 0.198239863f, 0.196561632f, 0.194959022f,  /* 32 33 34 35 */
-   0.193426404f, 0.191958720f, 0.190551412f, 0.189200360f,  /* 36 37 38 39 */
-   0.187901825f, 0.186652411f, 0.185449023f, 0.184288833f,  /* 40 41 42 43 */
-   0.183169251f, 0.182087900f, 0.181042597f, 0.180031327f,  /* 44 45 46 47 */
-   0.179052232f, 0.178103594f, 0.177183820f, 0.176291434f,  /* 48 49 50 51 */
-   0.175425064f, 0.174583430f, 0.173765343f, 0.172969690f,  /* 52 53 54 55 */
-   0.172195434f, 0.171441601f, 0.170707280f, 0.169991616f,  /* 56 57 58 59 */
-   0.169293808f, 0.168613099f, 0.167948779f, 0.167300179f,  /* 60 61 62 63 */
-   0.166666667f
-};
-
-#endif /* _LOGTAB_H */
--- a/jdk/src/share/native/sun/security/ec/mp_gf2m-priv.h	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,122 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Multi-precision Binary Polynomial Arithmetic Library.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Sheueling Chang Shantz <sheueling.chang@sun.com> and
- *   Douglas Stebila <douglas@stebila.ca> of Sun Laboratories.
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _MP_GF2M_PRIV_H_
-#define _MP_GF2M_PRIV_H_
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "mpi-priv.h"
-
-extern const mp_digit mp_gf2m_sqr_tb[16];
-
-#if defined(MP_USE_UINT_DIGIT)
-#define MP_DIGIT_BITS 32
-#else
-#define MP_DIGIT_BITS 64
-#endif
-
-/* Platform-specific macros for fast binary polynomial squaring. */
-#if MP_DIGIT_BITS == 32
-#define gf2m_SQR1(w) \
-    mp_gf2m_sqr_tb[(w) >> 28 & 0xF] << 24 | mp_gf2m_sqr_tb[(w) >> 24 & 0xF] << 16 | \
-    mp_gf2m_sqr_tb[(w) >> 20 & 0xF] <<  8 | mp_gf2m_sqr_tb[(w) >> 16 & 0xF]
-#define gf2m_SQR0(w) \
-    mp_gf2m_sqr_tb[(w) >> 12 & 0xF] << 24 | mp_gf2m_sqr_tb[(w) >>  8 & 0xF] << 16 | \
-    mp_gf2m_sqr_tb[(w) >>  4 & 0xF] <<  8 | mp_gf2m_sqr_tb[(w)       & 0xF]
-#else
-#define gf2m_SQR1(w) \
-    mp_gf2m_sqr_tb[(w) >> 60 & 0xF] << 56 | mp_gf2m_sqr_tb[(w) >> 56 & 0xF] << 48 | \
-    mp_gf2m_sqr_tb[(w) >> 52 & 0xF] << 40 | mp_gf2m_sqr_tb[(w) >> 48 & 0xF] << 32 | \
-    mp_gf2m_sqr_tb[(w) >> 44 & 0xF] << 24 | mp_gf2m_sqr_tb[(w) >> 40 & 0xF] << 16 | \
-    mp_gf2m_sqr_tb[(w) >> 36 & 0xF] <<  8 | mp_gf2m_sqr_tb[(w) >> 32 & 0xF]
-#define gf2m_SQR0(w) \
-    mp_gf2m_sqr_tb[(w) >> 28 & 0xF] << 56 | mp_gf2m_sqr_tb[(w) >> 24 & 0xF] << 48 | \
-    mp_gf2m_sqr_tb[(w) >> 20 & 0xF] << 40 | mp_gf2m_sqr_tb[(w) >> 16 & 0xF] << 32 | \
-    mp_gf2m_sqr_tb[(w) >> 12 & 0xF] << 24 | mp_gf2m_sqr_tb[(w) >>  8 & 0xF] << 16 | \
-    mp_gf2m_sqr_tb[(w) >>  4 & 0xF] <<  8 | mp_gf2m_sqr_tb[(w)       & 0xF]
-#endif
-
-/* Multiply two binary polynomials mp_digits a, b.
- * Result is a polynomial with degree < 2 * MP_DIGIT_BITS - 1.
- * Output in two mp_digits rh, rl.
- */
-void s_bmul_1x1(mp_digit *rh, mp_digit *rl, const mp_digit a, const mp_digit b);
-
-/* Compute xor-multiply of two binary polynomials  (a1, a0) x (b1, b0)
- * result is a binary polynomial in 4 mp_digits r[4].
- * The caller MUST ensure that r has the right amount of space allocated.
- */
-void s_bmul_2x2(mp_digit *r, const mp_digit a1, const mp_digit a0, const mp_digit b1,
-        const mp_digit b0);
-
-/* Compute xor-multiply of two binary polynomials  (a2, a1, a0) x (b2, b1, b0)
- * result is a binary polynomial in 6 mp_digits r[6].
- * The caller MUST ensure that r has the right amount of space allocated.
- */
-void s_bmul_3x3(mp_digit *r, const mp_digit a2, const mp_digit a1, const mp_digit a0,
-        const mp_digit b2, const mp_digit b1, const mp_digit b0);
-
-/* Compute xor-multiply of two binary polynomials  (a3, a2, a1, a0) x (b3, b2, b1, b0)
- * result is a binary polynomial in 8 mp_digits r[8].
- * The caller MUST ensure that r has the right amount of space allocated.
- */
-void s_bmul_4x4(mp_digit *r, const mp_digit a3, const mp_digit a2, const mp_digit a1,
-        const mp_digit a0, const mp_digit b3, const mp_digit b2, const mp_digit b1,
-        const mp_digit b0);
-
-#endif /* _MP_GF2M_PRIV_H_ */
--- a/jdk/src/share/native/sun/security/ec/mp_gf2m.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,624 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Multi-precision Binary Polynomial Arithmetic Library.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Sheueling Chang Shantz <sheueling.chang@sun.com> and
- *   Douglas Stebila <douglas@stebila.ca> of Sun Laboratories.
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "mp_gf2m.h"
-#include "mp_gf2m-priv.h"
-#include "mplogic.h"
-#include "mpi-priv.h"
-
-const mp_digit mp_gf2m_sqr_tb[16] =
-{
-      0,     1,     4,     5,    16,    17,    20,    21,
-     64,    65,    68,    69,    80,    81,    84,    85
-};
-
-/* Multiply two binary polynomials mp_digits a, b.
- * Result is a polynomial with degree < 2 * MP_DIGIT_BITS - 1.
- * Output in two mp_digits rh, rl.
- */
-#if MP_DIGIT_BITS == 32
-void
-s_bmul_1x1(mp_digit *rh, mp_digit *rl, const mp_digit a, const mp_digit b)
-{
-    register mp_digit h, l, s;
-    mp_digit tab[8], top2b = a >> 30;
-    register mp_digit a1, a2, a4;
-
-    a1 = a & (0x3FFFFFFF); a2 = a1 << 1; a4 = a2 << 1;
-
-    tab[0] =  0; tab[1] = a1;    tab[2] = a2;    tab[3] = a1^a2;
-    tab[4] = a4; tab[5] = a1^a4; tab[6] = a2^a4; tab[7] = a1^a2^a4;
-
-    s = tab[b       & 0x7]; l  = s;
-    s = tab[b >>  3 & 0x7]; l ^= s <<  3; h  = s >> 29;
-    s = tab[b >>  6 & 0x7]; l ^= s <<  6; h ^= s >> 26;
-    s = tab[b >>  9 & 0x7]; l ^= s <<  9; h ^= s >> 23;
-    s = tab[b >> 12 & 0x7]; l ^= s << 12; h ^= s >> 20;
-    s = tab[b >> 15 & 0x7]; l ^= s << 15; h ^= s >> 17;
-    s = tab[b >> 18 & 0x7]; l ^= s << 18; h ^= s >> 14;
-    s = tab[b >> 21 & 0x7]; l ^= s << 21; h ^= s >> 11;
-    s = tab[b >> 24 & 0x7]; l ^= s << 24; h ^= s >>  8;
-    s = tab[b >> 27 & 0x7]; l ^= s << 27; h ^= s >>  5;
-    s = tab[b >> 30      ]; l ^= s << 30; h ^= s >>  2;
-
-    /* compensate for the top two bits of a */
-
-    if (top2b & 01) { l ^= b << 30; h ^= b >> 2; }
-    if (top2b & 02) { l ^= b << 31; h ^= b >> 1; }
-
-    *rh = h; *rl = l;
-}
-#else
-void
-s_bmul_1x1(mp_digit *rh, mp_digit *rl, const mp_digit a, const mp_digit b)
-{
-    register mp_digit h, l, s;
-    mp_digit tab[16], top3b = a >> 61;
-    register mp_digit a1, a2, a4, a8;
-
-    a1 = a & (0x1FFFFFFFFFFFFFFFULL); a2 = a1 << 1;
-    a4 = a2 << 1; a8 = a4 << 1;
-    tab[ 0] = 0;     tab[ 1] = a1;       tab[ 2] = a2;       tab[ 3] = a1^a2;
-    tab[ 4] = a4;    tab[ 5] = a1^a4;    tab[ 6] = a2^a4;    tab[ 7] = a1^a2^a4;
-    tab[ 8] = a8;    tab[ 9] = a1^a8;    tab[10] = a2^a8;    tab[11] = a1^a2^a8;
-    tab[12] = a4^a8; tab[13] = a1^a4^a8; tab[14] = a2^a4^a8; tab[15] = a1^a2^a4^a8;
-
-    s = tab[b       & 0xF]; l  = s;
-    s = tab[b >>  4 & 0xF]; l ^= s <<  4; h  = s >> 60;
-    s = tab[b >>  8 & 0xF]; l ^= s <<  8; h ^= s >> 56;
-    s = tab[b >> 12 & 0xF]; l ^= s << 12; h ^= s >> 52;
-    s = tab[b >> 16 & 0xF]; l ^= s << 16; h ^= s >> 48;
-    s = tab[b >> 20 & 0xF]; l ^= s << 20; h ^= s >> 44;
-    s = tab[b >> 24 & 0xF]; l ^= s << 24; h ^= s >> 40;
-    s = tab[b >> 28 & 0xF]; l ^= s << 28; h ^= s >> 36;
-    s = tab[b >> 32 & 0xF]; l ^= s << 32; h ^= s >> 32;
-    s = tab[b >> 36 & 0xF]; l ^= s << 36; h ^= s >> 28;
-    s = tab[b >> 40 & 0xF]; l ^= s << 40; h ^= s >> 24;
-    s = tab[b >> 44 & 0xF]; l ^= s << 44; h ^= s >> 20;
-    s = tab[b >> 48 & 0xF]; l ^= s << 48; h ^= s >> 16;
-    s = tab[b >> 52 & 0xF]; l ^= s << 52; h ^= s >> 12;
-    s = tab[b >> 56 & 0xF]; l ^= s << 56; h ^= s >>  8;
-    s = tab[b >> 60      ]; l ^= s << 60; h ^= s >>  4;
-
-    /* compensate for the top three bits of a */
-
-    if (top3b & 01) { l ^= b << 61; h ^= b >> 3; }
-    if (top3b & 02) { l ^= b << 62; h ^= b >> 2; }
-    if (top3b & 04) { l ^= b << 63; h ^= b >> 1; }
-
-    *rh = h; *rl = l;
-}
-#endif
-
-/* Compute xor-multiply of two binary polynomials  (a1, a0) x (b1, b0)
- * result is a binary polynomial in 4 mp_digits r[4].
- * The caller MUST ensure that r has the right amount of space allocated.
- */
-void
-s_bmul_2x2(mp_digit *r, const mp_digit a1, const mp_digit a0, const mp_digit b1,
-           const mp_digit b0)
-{
-    mp_digit m1, m0;
-    /* r[3] = h1, r[2] = h0; r[1] = l1; r[0] = l0 */
-    s_bmul_1x1(r+3, r+2, a1, b1);
-    s_bmul_1x1(r+1, r, a0, b0);
-    s_bmul_1x1(&m1, &m0, a0 ^ a1, b0 ^ b1);
-    /* Correction on m1 ^= l1 ^ h1; m0 ^= l0 ^ h0; */
-    r[2] ^= m1 ^ r[1] ^ r[3];  /* h0 ^= m1 ^ l1 ^ h1; */
-    r[1]  = r[3] ^ r[2] ^ r[0] ^ m1 ^ m0;  /* l1 ^= l0 ^ h0 ^ m0; */
-}
-
-/* Compute xor-multiply of two binary polynomials  (a2, a1, a0) x (b2, b1, b0)
- * result is a binary polynomial in 6 mp_digits r[6].
- * The caller MUST ensure that r has the right amount of space allocated.
- */
-void
-s_bmul_3x3(mp_digit *r, const mp_digit a2, const mp_digit a1, const mp_digit a0,
-        const mp_digit b2, const mp_digit b1, const mp_digit b0)
-{
-        mp_digit zm[4];
-
-        s_bmul_1x1(r+5, r+4, a2, b2);         /* fill top 2 words */
-        s_bmul_2x2(zm, a1, a2^a0, b1, b2^b0); /* fill middle 4 words */
-        s_bmul_2x2(r, a1, a0, b1, b0);        /* fill bottom 4 words */
-
-        zm[3] ^= r[3];
-        zm[2] ^= r[2];
-        zm[1] ^= r[1] ^ r[5];
-        zm[0] ^= r[0] ^ r[4];
-
-        r[5]  ^= zm[3];
-        r[4]  ^= zm[2];
-        r[3]  ^= zm[1];
-        r[2]  ^= zm[0];
-}
-
-/* Compute xor-multiply of two binary polynomials  (a3, a2, a1, a0) x (b3, b2, b1, b0)
- * result is a binary polynomial in 8 mp_digits r[8].
- * The caller MUST ensure that r has the right amount of space allocated.
- */
-void s_bmul_4x4(mp_digit *r, const mp_digit a3, const mp_digit a2, const mp_digit a1,
-        const mp_digit a0, const mp_digit b3, const mp_digit b2, const mp_digit b1,
-        const mp_digit b0)
-{
-        mp_digit zm[4];
-
-        s_bmul_2x2(r+4, a3, a2, b3, b2);            /* fill top 4 words */
-        s_bmul_2x2(zm, a3^a1, a2^a0, b3^b1, b2^b0); /* fill middle 4 words */
-        s_bmul_2x2(r, a1, a0, b1, b0);              /* fill bottom 4 words */
-
-        zm[3] ^= r[3] ^ r[7];
-        zm[2] ^= r[2] ^ r[6];
-        zm[1] ^= r[1] ^ r[5];
-        zm[0] ^= r[0] ^ r[4];
-
-        r[5]  ^= zm[3];
-        r[4]  ^= zm[2];
-        r[3]  ^= zm[1];
-        r[2]  ^= zm[0];
-}
-
-/* Compute addition of two binary polynomials a and b,
- * store result in c; c could be a or b, a and b could be equal;
- * c is the bitwise XOR of a and b.
- */
-mp_err
-mp_badd(const mp_int *a, const mp_int *b, mp_int *c)
-{
-    mp_digit *pa, *pb, *pc;
-    mp_size ix;
-    mp_size used_pa, used_pb;
-    mp_err res = MP_OKAY;
-
-    /* Add all digits up to the precision of b.  If b had more
-     * precision than a initially, swap a, b first
-     */
-    if (MP_USED(a) >= MP_USED(b)) {
-        pa = MP_DIGITS(a);
-        pb = MP_DIGITS(b);
-        used_pa = MP_USED(a);
-        used_pb = MP_USED(b);
-    } else {
-        pa = MP_DIGITS(b);
-        pb = MP_DIGITS(a);
-        used_pa = MP_USED(b);
-        used_pb = MP_USED(a);
-    }
-
-    /* Make sure c has enough precision for the output value */
-    MP_CHECKOK( s_mp_pad(c, used_pa) );
-
-    /* Do word-by-word xor */
-    pc = MP_DIGITS(c);
-    for (ix = 0; ix < used_pb; ix++) {
-        (*pc++) = (*pa++) ^ (*pb++);
-    }
-
-    /* Finish the rest of digits until we're actually done */
-    for (; ix < used_pa; ++ix) {
-        *pc++ = *pa++;
-    }
-
-    MP_USED(c) = used_pa;
-    MP_SIGN(c) = ZPOS;
-    s_mp_clamp(c);
-
-CLEANUP:
-    return res;
-}
-
-#define s_mp_div2(a) MP_CHECKOK( mpl_rsh((a), (a), 1) );
-
-/* Compute binary polynomial multiply d = a * b */
-static void
-s_bmul_d(const mp_digit *a, mp_size a_len, mp_digit b, mp_digit *d)
-{
-    mp_digit a_i, a0b0, a1b1, carry = 0;
-    while (a_len--) {
-        a_i = *a++;
-        s_bmul_1x1(&a1b1, &a0b0, a_i, b);
-        *d++ = a0b0 ^ carry;
-        carry = a1b1;
-    }
-    *d = carry;
-}
-
-/* Compute binary polynomial xor multiply accumulate d ^= a * b */
-static void
-s_bmul_d_add(const mp_digit *a, mp_size a_len, mp_digit b, mp_digit *d)
-{
-    mp_digit a_i, a0b0, a1b1, carry = 0;
-    while (a_len--) {
-        a_i = *a++;
-        s_bmul_1x1(&a1b1, &a0b0, a_i, b);
-        *d++ ^= a0b0 ^ carry;
-        carry = a1b1;
-    }
-    *d ^= carry;
-}
-
-/* Compute binary polynomial xor multiply c = a * b.
- * All parameters may be identical.
- */
-mp_err
-mp_bmul(const mp_int *a, const mp_int *b, mp_int *c)
-{
-    mp_digit *pb, b_i;
-    mp_int tmp;
-    mp_size ib, a_used, b_used;
-    mp_err res = MP_OKAY;
-
-    MP_DIGITS(&tmp) = 0;
-
-    ARGCHK(a != NULL && b != NULL && c != NULL, MP_BADARG);
-
-    if (a == c) {
-        MP_CHECKOK( mp_init_copy(&tmp, a) );
-        if (a == b)
-            b = &tmp;
-        a = &tmp;
-    } else if (b == c) {
-        MP_CHECKOK( mp_init_copy(&tmp, b) );
-        b = &tmp;
-    }
-
-    if (MP_USED(a) < MP_USED(b)) {
-        const mp_int *xch = b;      /* switch a and b if b longer */
-        b = a;
-        a = xch;
-    }
-
-    MP_USED(c) = 1; MP_DIGIT(c, 0) = 0;
-    MP_CHECKOK( s_mp_pad(c, USED(a) + USED(b)) );
-
-    pb = MP_DIGITS(b);
-    s_bmul_d(MP_DIGITS(a), MP_USED(a), *pb++, MP_DIGITS(c));
-
-    /* Outer loop:  Digits of b */
-    a_used = MP_USED(a);
-    b_used = MP_USED(b);
-        MP_USED(c) = a_used + b_used;
-    for (ib = 1; ib < b_used; ib++) {
-        b_i = *pb++;
-
-        /* Inner product:  Digits of a */
-        if (b_i)
-            s_bmul_d_add(MP_DIGITS(a), a_used, b_i, MP_DIGITS(c) + ib);
-        else
-            MP_DIGIT(c, ib + a_used) = b_i;
-    }
-
-    s_mp_clamp(c);
-
-    SIGN(c) = ZPOS;
-
-CLEANUP:
-    mp_clear(&tmp);
-    return res;
-}
-
-
-/* Compute modular reduction of a and store result in r.
- * r could be a.
- * For modular arithmetic, the irreducible polynomial f(t) is represented
- * as an array of int[], where f(t) is of the form:
- *     f(t) = t^p[0] + t^p[1] + ... + t^p[k]
- * where m = p[0] > p[1] > ... > p[k] = 0.
- */
-mp_err
-mp_bmod(const mp_int *a, const unsigned int p[], mp_int *r)
-{
-    int j, k;
-    int n, dN, d0, d1;
-    mp_digit zz, *z, tmp;
-    mp_size used;
-    mp_err res = MP_OKAY;
-
-    /* The algorithm does the reduction in place in r,
-     * if a != r, copy a into r first so reduction can be done in r
-     */
-    if (a != r) {
-        MP_CHECKOK( mp_copy(a, r) );
-    }
-    z = MP_DIGITS(r);
-
-    /* start reduction */
-    dN = p[0] / MP_DIGIT_BITS;
-    used = MP_USED(r);
-
-    for (j = used - 1; j > dN;) {
-
-        zz = z[j];
-        if (zz == 0) {
-            j--; continue;
-        }
-        z[j] = 0;
-
-        for (k = 1; p[k] > 0; k++) {
-            /* reducing component t^p[k] */
-            n = p[0] - p[k];
-            d0 = n % MP_DIGIT_BITS;
-            d1 = MP_DIGIT_BITS - d0;
-            n /= MP_DIGIT_BITS;
-            z[j-n] ^= (zz>>d0);
-            if (d0)
-                z[j-n-1] ^= (zz<<d1);
-        }
-
-        /* reducing component t^0 */
-        n = dN;
-        d0 = p[0] % MP_DIGIT_BITS;
-        d1 = MP_DIGIT_BITS - d0;
-        z[j-n] ^= (zz >> d0);
-        if (d0)
-            z[j-n-1] ^= (zz << d1);
-
-    }
-
-    /* final round of reduction */
-    while (j == dN) {
-
-        d0 = p[0] % MP_DIGIT_BITS;
-        zz = z[dN] >> d0;
-        if (zz == 0) break;
-        d1 = MP_DIGIT_BITS - d0;
-
-        /* clear up the top d1 bits */
-        if (d0) z[dN] = (z[dN] << d1) >> d1;
-        *z ^= zz; /* reduction t^0 component */
-
-        for (k = 1; p[k] > 0; k++) {
-            /* reducing component t^p[k]*/
-            n = p[k] / MP_DIGIT_BITS;
-            d0 = p[k] % MP_DIGIT_BITS;
-            d1 = MP_DIGIT_BITS - d0;
-            z[n] ^= (zz << d0);
-            tmp = zz >> d1;
-            if (d0 && tmp)
-                z[n+1] ^= tmp;
-        }
-    }
-
-    s_mp_clamp(r);
-CLEANUP:
-    return res;
-}
-
-/* Compute the product of two polynomials a and b, reduce modulo p,
- * Store the result in r.  r could be a or b; a could be b.
- */
-mp_err
-mp_bmulmod(const mp_int *a, const mp_int *b, const unsigned int p[], mp_int *r)
-{
-    mp_err res;
-
-    if (a == b) return mp_bsqrmod(a, p, r);
-    if ((res = mp_bmul(a, b, r) ) != MP_OKAY)
-        return res;
-    return mp_bmod(r, p, r);
-}
-
-/* Compute binary polynomial squaring c = a*a mod p .
- * Parameter r and a can be identical.
- */
-
-mp_err
-mp_bsqrmod(const mp_int *a, const unsigned int p[], mp_int *r)
-{
-    mp_digit *pa, *pr, a_i;
-    mp_int tmp;
-    mp_size ia, a_used;
-    mp_err res;
-
-    ARGCHK(a != NULL && r != NULL, MP_BADARG);
-    MP_DIGITS(&tmp) = 0;
-
-    if (a == r) {
-        MP_CHECKOK( mp_init_copy(&tmp, a) );
-        a = &tmp;
-    }
-
-    MP_USED(r) = 1; MP_DIGIT(r, 0) = 0;
-    MP_CHECKOK( s_mp_pad(r, 2*USED(a)) );
-
-    pa = MP_DIGITS(a);
-    pr = MP_DIGITS(r);
-    a_used = MP_USED(a);
-        MP_USED(r) = 2 * a_used;
-
-    for (ia = 0; ia < a_used; ia++) {
-        a_i = *pa++;
-        *pr++ = gf2m_SQR0(a_i);
-        *pr++ = gf2m_SQR1(a_i);
-    }
-
-    MP_CHECKOK( mp_bmod(r, p, r) );
-    s_mp_clamp(r);
-    SIGN(r) = ZPOS;
-
-CLEANUP:
-    mp_clear(&tmp);
-    return res;
-}
-
-/* Compute binary polynomial y/x mod p, y divided by x, reduce modulo p.
- * Store the result in r. r could be x or y, and x could equal y.
- * Uses algorithm Modular_Division_GF(2^m) from
- *     Chang-Shantz, S.  "From Euclid's GCD to Montgomery Multiplication to
- *     the Great Divide".
- */
-int
-mp_bdivmod(const mp_int *y, const mp_int *x, const mp_int *pp,
-    const unsigned int p[], mp_int *r)
-{
-    mp_int aa, bb, uu;
-    mp_int *a, *b, *u, *v;
-    mp_err res = MP_OKAY;
-
-    MP_DIGITS(&aa) = 0;
-    MP_DIGITS(&bb) = 0;
-    MP_DIGITS(&uu) = 0;
-
-    MP_CHECKOK( mp_init_copy(&aa, x) );
-    MP_CHECKOK( mp_init_copy(&uu, y) );
-    MP_CHECKOK( mp_init_copy(&bb, pp) );
-    MP_CHECKOK( s_mp_pad(r, USED(pp)) );
-    MP_USED(r) = 1; MP_DIGIT(r, 0) = 0;
-
-    a = &aa; b= &bb; u=&uu; v=r;
-    /* reduce x and y mod p */
-    MP_CHECKOK( mp_bmod(a, p, a) );
-    MP_CHECKOK( mp_bmod(u, p, u) );
-
-    while (!mp_isodd(a)) {
-        s_mp_div2(a);
-        if (mp_isodd(u)) {
-            MP_CHECKOK( mp_badd(u, pp, u) );
-        }
-        s_mp_div2(u);
-    }
-
-    do {
-        if (mp_cmp_mag(b, a) > 0) {
-            MP_CHECKOK( mp_badd(b, a, b) );
-            MP_CHECKOK( mp_badd(v, u, v) );
-            do {
-                s_mp_div2(b);
-                if (mp_isodd(v)) {
-                    MP_CHECKOK( mp_badd(v, pp, v) );
-                }
-                s_mp_div2(v);
-            } while (!mp_isodd(b));
-        }
-        else if ((MP_DIGIT(a,0) == 1) && (MP_USED(a) == 1))
-            break;
-        else {
-            MP_CHECKOK( mp_badd(a, b, a) );
-            MP_CHECKOK( mp_badd(u, v, u) );
-            do {
-                s_mp_div2(a);
-                if (mp_isodd(u)) {
-                    MP_CHECKOK( mp_badd(u, pp, u) );
-                }
-                s_mp_div2(u);
-            } while (!mp_isodd(a));
-        }
-    } while (1);
-
-    MP_CHECKOK( mp_copy(u, r) );
-
-CLEANUP:
-    /* XXX this appears to be a memory leak in the NSS code */
-    mp_clear(&aa);
-    mp_clear(&bb);
-    mp_clear(&uu);
-    return res;
-
-}
-
-/* Convert the bit-string representation of a polynomial a into an array
- * of integers corresponding to the bits with non-zero coefficient.
- * Up to max elements of the array will be filled.  Return value is total
- * number of coefficients that would be extracted if array was large enough.
- */
-int
-mp_bpoly2arr(const mp_int *a, unsigned int p[], int max)
-{
-    int i, j, k;
-    mp_digit top_bit, mask;
-
-    top_bit = 1;
-    top_bit <<= MP_DIGIT_BIT - 1;
-
-    for (k = 0; k < max; k++) p[k] = 0;
-    k = 0;
-
-    for (i = MP_USED(a) - 1; i >= 0; i--) {
-        mask = top_bit;
-        for (j = MP_DIGIT_BIT - 1; j >= 0; j--) {
-            if (MP_DIGITS(a)[i] & mask) {
-                if (k < max) p[k] = MP_DIGIT_BIT * i + j;
-                k++;
-            }
-            mask >>= 1;
-        }
-    }
-
-    return k;
-}
-
-/* Convert the coefficient array representation of a polynomial to a
- * bit-string.  The array must be terminated by 0.
- */
-mp_err
-mp_barr2poly(const unsigned int p[], mp_int *a)
-{
-
-    mp_err res = MP_OKAY;
-    int i;
-
-    mp_zero(a);
-    for (i = 0; p[i] > 0; i++) {
-        MP_CHECKOK( mpl_set_bit(a, p[i], 1) );
-    }
-    MP_CHECKOK( mpl_set_bit(a, 0, 1) );
-
-CLEANUP:
-    return res;
-}
--- a/jdk/src/share/native/sun/security/ec/mp_gf2m.h	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,83 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Multi-precision Binary Polynomial Arithmetic Library.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Sheueling Chang Shantz <sheueling.chang@sun.com> and
- *   Douglas Stebila <douglas@stebila.ca> of Sun Laboratories.
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _MP_GF2M_H_
-#define _MP_GF2M_H_
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "mpi.h"
-
-mp_err mp_badd(const mp_int *a, const mp_int *b, mp_int *c);
-mp_err mp_bmul(const mp_int *a, const mp_int *b, mp_int *c);
-
-/* For modular arithmetic, the irreducible polynomial f(t) is represented
- * as an array of int[], where f(t) is of the form:
- *     f(t) = t^p[0] + t^p[1] + ... + t^p[k]
- * where m = p[0] > p[1] > ... > p[k] = 0.
- */
-mp_err mp_bmod(const mp_int *a, const unsigned int p[], mp_int *r);
-mp_err mp_bmulmod(const mp_int *a, const mp_int *b, const unsigned int p[],
-    mp_int *r);
-mp_err mp_bsqrmod(const mp_int *a, const unsigned int p[], mp_int *r);
-mp_err mp_bdivmod(const mp_int *y, const mp_int *x, const mp_int *pp,
-    const unsigned int p[], mp_int *r);
-
-int mp_bpoly2arr(const mp_int *a, unsigned int p[], int max);
-mp_err mp_barr2poly(const unsigned int p[], mp_int *a);
-
-#endif /* _MP_GF2M_H_ */
--- a/jdk/src/share/native/sun/security/ec/mpi-config.h	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,130 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the MPI Arbitrary Precision Integer Arithmetic library.
- *
- * The Initial Developer of the Original Code is
- * Michael J. Fromberger.
- * Portions created by the Initial Developer are Copyright (C) 1997
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Netscape Communications Corporation
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _MPI_CONFIG_H
-#define _MPI_CONFIG_H
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-/* $Id: mpi-config.h,v 1.5 2004/04/25 15:03:10 gerv%gerv.net Exp $ */
-
-/*
-  For boolean options,
-  0 = no
-  1 = yes
-
-  Other options are documented individually.
-
- */
-
-#ifndef MP_IOFUNC
-#define MP_IOFUNC     0  /* include mp_print() ?                */
-#endif
-
-#ifndef MP_MODARITH
-#define MP_MODARITH   1  /* include modular arithmetic ?        */
-#endif
-
-#ifndef MP_NUMTH
-#define MP_NUMTH      1  /* include number theoretic functions? */
-#endif
-
-#ifndef MP_LOGTAB
-#define MP_LOGTAB     1  /* use table of logs instead of log()? */
-#endif
-
-#ifndef MP_MEMSET
-#define MP_MEMSET     1  /* use memset() to zero buffers?       */
-#endif
-
-#ifndef MP_MEMCPY
-#define MP_MEMCPY     1  /* use memcpy() to copy buffers?       */
-#endif
-
-#ifndef MP_CRYPTO
-#define MP_CRYPTO     1  /* erase memory on free?               */
-#endif
-
-#ifndef MP_ARGCHK
-/*
-  0 = no parameter checks
-  1 = runtime checks, continue execution and return an error to caller
-  2 = assertions; dump core on parameter errors
- */
-#ifdef DEBUG
-#define MP_ARGCHK     2  /* how to check input arguments        */
-#else
-#define MP_ARGCHK     1  /* how to check input arguments        */
-#endif
-#endif
-
-#ifndef MP_DEBUG
-#define MP_DEBUG      0  /* print diagnostic output?            */
-#endif
-
-#ifndef MP_DEFPREC
-#define MP_DEFPREC    64 /* default precision, in digits        */
-#endif
-
-#ifndef MP_MACRO
-#define MP_MACRO      0  /* use macros for frequent calls?      */
-#endif
-
-#ifndef MP_SQUARE
-#define MP_SQUARE     1  /* use separate squaring code?         */
-#endif
-
-#endif /* _MPI_CONFIG_H */
--- a/jdk/src/share/native/sun/security/ec/mpi-priv.h	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,340 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- *  Arbitrary precision integer arithmetic library
- *
- *  NOTE WELL: the content of this header file is NOT part of the "public"
- *  API for the MPI library, and may change at any time.
- *  Application programs that use libmpi should NOT include this header file.
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the MPI Arbitrary Precision Integer Arithmetic library.
- *
- * The Initial Developer of the Original Code is
- * Michael J. Fromberger.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Netscape Communications Corporation
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _MPI_PRIV_H
-#define _MPI_PRIV_H
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-/* $Id: mpi-priv.h,v 1.20 2005/11/22 07:16:43 relyea%netscape.com Exp $ */
-
-#include "mpi.h"
-#ifndef _KERNEL
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#endif /* _KERNEL */
-
-#if MP_DEBUG
-#include <stdio.h>
-
-#define DIAG(T,V) {fprintf(stderr,T);mp_print(V,stderr);fputc('\n',stderr);}
-#else
-#define DIAG(T,V)
-#endif
-
-/* If we aren't using a wired-in logarithm table, we need to include
-   the math library to get the log() function
- */
-
-/* {{{ s_logv_2[] - log table for 2 in various bases */
-
-#if MP_LOGTAB
-/*
-  A table of the logs of 2 for various bases (the 0 and 1 entries of
-  this table are meaningless and should not be referenced).
-
-  This table is used to compute output lengths for the mp_toradix()
-  function.  Since a number n in radix r takes up about log_r(n)
-  digits, we estimate the output size by taking the least integer
-  greater than log_r(n), where:
-
-  log_r(n) = log_2(n) * log_r(2)
-
-  This table, therefore, is a table of log_r(2) for 2 <= r <= 36,
-  which are the output bases supported.
- */
-
-extern const float s_logv_2[];
-#define LOG_V_2(R)  s_logv_2[(R)]
-
-#else
-
-/*
-   If MP_LOGTAB is not defined, use the math library to compute the
-   logarithms on the fly.  Otherwise, use the table.
-   Pick which works best for your system.
- */
-
-#include <math.h>
-#define LOG_V_2(R)  (log(2.0)/log(R))
-
-#endif /* if MP_LOGTAB */
-
-/* }}} */
-
-/* {{{ Digit arithmetic macros */
-
-/*
-  When adding and multiplying digits, the results can be larger than
-  can be contained in an mp_digit.  Thus, an mp_word is used.  These
-  macros mask off the upper and lower digits of the mp_word (the
-  mp_word may be more than 2 mp_digits wide, but we only concern
-  ourselves with the low-order 2 mp_digits)
- */
-
-#define  CARRYOUT(W)  (mp_digit)((W)>>DIGIT_BIT)
-#define  ACCUM(W)     (mp_digit)(W)
-
-#define MP_MIN(a,b)   (((a) < (b)) ? (a) : (b))
-#define MP_MAX(a,b)   (((a) > (b)) ? (a) : (b))
-#define MP_HOWMANY(a,b) (((a) + (b) - 1)/(b))
-#define MP_ROUNDUP(a,b) (MP_HOWMANY(a,b) * (b))
-
-/* }}} */
-
-/* {{{ Comparison constants */
-
-#define  MP_LT       -1
-#define  MP_EQ        0
-#define  MP_GT        1
-
-/* }}} */
-
-/* {{{ private function declarations */
-
-/*
-   If MP_MACRO is false, these will be defined as actual functions;
-   otherwise, suitable macro definitions will be used.  This works
-   around the fact that ANSI C89 doesn't support an 'inline' keyword
-   (although I hear C9x will ... about bloody time).  At present, the
-   macro definitions are identical to the function bodies, but they'll
-   expand in place, instead of generating a function call.
-
-   I chose these particular functions to be made into macros because
-   some profiling showed they are called a lot on a typical workload,
-   and yet they are primarily housekeeping.
- */
-#if MP_MACRO == 0
- void     s_mp_setz(mp_digit *dp, mp_size count); /* zero digits           */
- void     s_mp_copy(const mp_digit *sp, mp_digit *dp, mp_size count); /* copy */
- void    *s_mp_alloc(size_t nb, size_t ni, int flag); /* general allocator    */
- void     s_mp_free(void *ptr, mp_size);          /* general free function */
-extern unsigned long mp_allocs;
-extern unsigned long mp_frees;
-extern unsigned long mp_copies;
-#else
-
- /* Even if these are defined as macros, we need to respect the settings
-    of the MP_MEMSET and MP_MEMCPY configuration options...
-  */
- #if MP_MEMSET == 0
-  #define  s_mp_setz(dp, count) \
-       {int ix;for(ix=0;ix<(count);ix++)(dp)[ix]=0;}
- #else
-  #define  s_mp_setz(dp, count) memset(dp, 0, (count) * sizeof(mp_digit))
- #endif /* MP_MEMSET */
-
- #if MP_MEMCPY == 0
-  #define  s_mp_copy(sp, dp, count) \
-       {int ix;for(ix=0;ix<(count);ix++)(dp)[ix]=(sp)[ix];}
- #else
-  #define  s_mp_copy(sp, dp, count) memcpy(dp, sp, (count) * sizeof(mp_digit))
- #endif /* MP_MEMCPY */
-
- #define  s_mp_alloc(nb, ni)  calloc(nb, ni)
- #define  s_mp_free(ptr) {if(ptr) free(ptr);}
-#endif /* MP_MACRO */
-
-mp_err   s_mp_grow(mp_int *mp, mp_size min);   /* increase allocated size */
-mp_err   s_mp_pad(mp_int *mp, mp_size min);    /* left pad with zeroes    */
-
-#if MP_MACRO == 0
- void     s_mp_clamp(mp_int *mp);               /* clip leading zeroes     */
-#else
- #define  s_mp_clamp(mp)\
-  { mp_size used = MP_USED(mp); \
-    while (used > 1 && DIGIT(mp, used - 1) == 0) --used; \
-    MP_USED(mp) = used; \
-  }
-#endif /* MP_MACRO */
-
-void     s_mp_exch(mp_int *a, mp_int *b);      /* swap a and b in place   */
-
-mp_err   s_mp_lshd(mp_int *mp, mp_size p);     /* left-shift by p digits  */
-void     s_mp_rshd(mp_int *mp, mp_size p);     /* right-shift by p digits */
-mp_err   s_mp_mul_2d(mp_int *mp, mp_digit d);  /* multiply by 2^d in place */
-void     s_mp_div_2d(mp_int *mp, mp_digit d);  /* divide by 2^d in place  */
-void     s_mp_mod_2d(mp_int *mp, mp_digit d);  /* modulo 2^d in place     */
-void     s_mp_div_2(mp_int *mp);               /* divide by 2 in place    */
-mp_err   s_mp_mul_2(mp_int *mp);               /* multiply by 2 in place  */
-mp_err   s_mp_norm(mp_int *a, mp_int *b, mp_digit *pd);
-                                               /* normalize for division  */
-mp_err   s_mp_add_d(mp_int *mp, mp_digit d);   /* unsigned digit addition */
-mp_err   s_mp_sub_d(mp_int *mp, mp_digit d);   /* unsigned digit subtract */
-mp_err   s_mp_mul_d(mp_int *mp, mp_digit d);   /* unsigned digit multiply */
-mp_err   s_mp_div_d(mp_int *mp, mp_digit d, mp_digit *r);
-                                               /* unsigned digit divide   */
-mp_err   s_mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu);
-                                               /* Barrett reduction       */
-mp_err   s_mp_add(mp_int *a, const mp_int *b); /* magnitude addition      */
-mp_err   s_mp_add_3arg(const mp_int *a, const mp_int *b, mp_int *c);
-mp_err   s_mp_sub(mp_int *a, const mp_int *b); /* magnitude subtract      */
-mp_err   s_mp_sub_3arg(const mp_int *a, const mp_int *b, mp_int *c);
-mp_err   s_mp_add_offset(mp_int *a, mp_int *b, mp_size offset);
-                                               /* a += b * RADIX^offset   */
-mp_err   s_mp_mul(mp_int *a, const mp_int *b); /* magnitude multiply      */
-#if MP_SQUARE
-mp_err   s_mp_sqr(mp_int *a);                  /* magnitude square        */
-#else
-#define  s_mp_sqr(a) s_mp_mul(a, a)
-#endif
-mp_err   s_mp_div(mp_int *rem, mp_int *div, mp_int *quot); /* magnitude div */
-mp_err   s_mp_exptmod(const mp_int *a, const mp_int *b, const mp_int *m, mp_int *c);
-mp_err   s_mp_2expt(mp_int *a, mp_digit k);    /* a = 2^k                 */
-int      s_mp_cmp(const mp_int *a, const mp_int *b); /* magnitude comparison */
-int      s_mp_cmp_d(const mp_int *a, mp_digit d); /* magnitude digit compare */
-int      s_mp_ispow2(const mp_int *v);         /* is v a power of 2?      */
-int      s_mp_ispow2d(mp_digit d);             /* is d a power of 2?      */
-
-int      s_mp_tovalue(char ch, int r);          /* convert ch to value    */
-char     s_mp_todigit(mp_digit val, int r, int low); /* convert val to digit */
-int      s_mp_outlen(int bits, int r);          /* output length in bytes */
-mp_digit s_mp_invmod_radix(mp_digit P);   /* returns (P ** -1) mod RADIX */
-mp_err   s_mp_invmod_odd_m( const mp_int *a, const mp_int *m, mp_int *c);
-mp_err   s_mp_invmod_2d(    const mp_int *a, mp_size k,       mp_int *c);
-mp_err   s_mp_invmod_even_m(const mp_int *a, const mp_int *m, mp_int *c);
-
-#ifdef NSS_USE_COMBA
-
-#define IS_POWER_OF_2(a) ((a) && !((a) & ((a)-1)))
-
-void s_mp_mul_comba_4(const mp_int *A, const mp_int *B, mp_int *C);
-void s_mp_mul_comba_8(const mp_int *A, const mp_int *B, mp_int *C);
-void s_mp_mul_comba_16(const mp_int *A, const mp_int *B, mp_int *C);
-void s_mp_mul_comba_32(const mp_int *A, const mp_int *B, mp_int *C);
-
-void s_mp_sqr_comba_4(const mp_int *A, mp_int *B);
-void s_mp_sqr_comba_8(const mp_int *A, mp_int *B);
-void s_mp_sqr_comba_16(const mp_int *A, mp_int *B);
-void s_mp_sqr_comba_32(const mp_int *A, mp_int *B);
-
-#endif /* end NSS_USE_COMBA */
-
-/* ------ mpv functions, operate on arrays of digits, not on mp_int's ------ */
-#if defined (__OS2__) && defined (__IBMC__)
-#define MPI_ASM_DECL __cdecl
-#else
-#define MPI_ASM_DECL
-#endif
-
-#ifdef MPI_AMD64
-
-mp_digit MPI_ASM_DECL s_mpv_mul_set_vec64(mp_digit*, mp_digit *, mp_size, mp_digit);
-mp_digit MPI_ASM_DECL s_mpv_mul_add_vec64(mp_digit*, const mp_digit*, mp_size, mp_digit);
-
-/* c = a * b */
-#define s_mpv_mul_d(a, a_len, b, c) \
-        ((unsigned long*)c)[a_len] = s_mpv_mul_set_vec64(c, a, a_len, b)
-
-/* c += a * b */
-#define s_mpv_mul_d_add(a, a_len, b, c) \
-        ((unsigned long*)c)[a_len] = s_mpv_mul_add_vec64(c, a, a_len, b)
-
-#else
-
-void     MPI_ASM_DECL s_mpv_mul_d(const mp_digit *a, mp_size a_len,
-                                        mp_digit b, mp_digit *c);
-void     MPI_ASM_DECL s_mpv_mul_d_add(const mp_digit *a, mp_size a_len,
-                                            mp_digit b, mp_digit *c);
-
-#endif
-
-void     MPI_ASM_DECL s_mpv_mul_d_add_prop(const mp_digit *a,
-                                                mp_size a_len, mp_digit b,
-                                                mp_digit *c);
-void     MPI_ASM_DECL s_mpv_sqr_add_prop(const mp_digit *a,
-                                                mp_size a_len,
-                                                mp_digit *sqrs);
-
-mp_err   MPI_ASM_DECL s_mpv_div_2dx1d(mp_digit Nhi, mp_digit Nlo,
-                            mp_digit divisor, mp_digit *quot, mp_digit *rem);
-
-/* c += a * b * (MP_RADIX ** offset);  */
-#define s_mp_mul_d_add_offset(a, b, c, off) \
-(s_mpv_mul_d_add_prop(MP_DIGITS(a), MP_USED(a), b, MP_DIGITS(c) + off), MP_OKAY)
-
-typedef struct {
-  mp_int       N;       /* modulus N */
-  mp_digit     n0prime; /* n0' = - (n0 ** -1) mod MP_RADIX */
-  mp_size      b;       /* R == 2 ** b,  also b = # significant bits in N */
-} mp_mont_modulus;
-
-mp_err s_mp_mul_mont(const mp_int *a, const mp_int *b, mp_int *c,
-                       mp_mont_modulus *mmm);
-mp_err s_mp_redc(mp_int *T, mp_mont_modulus *mmm);
-
-/*
- * s_mpi_getProcessorLineSize() returns the size in bytes of the cache line
- * if a cache exists, or zero if there is no cache. If more than one
- * cache line exists, it should return the smallest line size (which is
- * usually the L1 cache).
- *
- * mp_modexp uses this information to make sure that private key information
- * isn't being leaked through the cache.
- *
- * see mpcpucache.c for the implementation.
- */
-unsigned long s_mpi_getProcessorLineSize();
-
-/* }}} */
-#endif /* _MPI_PRIV_H */
--- a/jdk/src/share/native/sun/security/ec/mpi.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,4886 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- *
- *  Arbitrary precision integer arithmetic library
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the MPI Arbitrary Precision Integer Arithmetic library.
- *
- * The Initial Developer of the Original Code is
- * Michael J. Fromberger.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Netscape Communications Corporation
- *   Douglas Stebila <douglas@stebila.ca> of Sun Laboratories.
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-/* $Id: mpi.c,v 1.45 2006/09/29 20:12:21 alexei.volkov.bugs%sun.com Exp $ */
-
-#include "mpi-priv.h"
-#if defined(OSF1)
-#include <c_asm.h>
-#endif
-
-#if MP_LOGTAB
-/*
-  A table of the logs of 2 for various bases (the 0 and 1 entries of
-  this table are meaningless and should not be referenced).
-
-  This table is used to compute output lengths for the mp_toradix()
-  function.  Since a number n in radix r takes up about log_r(n)
-  digits, we estimate the output size by taking the least integer
-  greater than log_r(n), where:
-
-  log_r(n) = log_2(n) * log_r(2)
-
-  This table, therefore, is a table of log_r(2) for 2 <= r <= 36,
-  which are the output bases supported.
- */
-#include "logtab.h"
-#endif
-
-/* {{{ Constant strings */
-
-/* Constant strings returned by mp_strerror() */
-static const char *mp_err_string[] = {
-  "unknown result code",     /* say what?            */
-  "boolean true",            /* MP_OKAY, MP_YES      */
-  "boolean false",           /* MP_NO                */
-  "out of memory",           /* MP_MEM               */
-  "argument out of range",   /* MP_RANGE             */
-  "invalid input parameter", /* MP_BADARG            */
-  "result is undefined"      /* MP_UNDEF             */
-};
-
-/* Value to digit maps for radix conversion   */
-
-/* s_dmap_1 - standard digits and letters */
-static const char *s_dmap_1 =
-  "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";
-
-/* }}} */
-
-unsigned long mp_allocs;
-unsigned long mp_frees;
-unsigned long mp_copies;
-
-/* {{{ Default precision manipulation */
-
-/* Default precision for newly created mp_int's      */
-static mp_size s_mp_defprec = MP_DEFPREC;
-
-mp_size mp_get_prec(void)
-{
-  return s_mp_defprec;
-
-} /* end mp_get_prec() */
-
-void         mp_set_prec(mp_size prec)
-{
-  if(prec == 0)
-    s_mp_defprec = MP_DEFPREC;
-  else
-    s_mp_defprec = prec;
-
-} /* end mp_set_prec() */
-
-/* }}} */
-
-/*------------------------------------------------------------------------*/
-/* {{{ mp_init(mp, kmflag) */
-
-/*
-  mp_init(mp, kmflag)
-
-  Initialize a new zero-valued mp_int.  Returns MP_OKAY if successful,
-  MP_MEM if memory could not be allocated for the structure.
- */
-
-mp_err mp_init(mp_int *mp, int kmflag)
-{
-  return mp_init_size(mp, s_mp_defprec, kmflag);
-
-} /* end mp_init() */
-
-/* }}} */
-
-/* {{{ mp_init_size(mp, prec, kmflag) */
-
-/*
-  mp_init_size(mp, prec, kmflag)
-
-  Initialize a new zero-valued mp_int with at least the given
-  precision; returns MP_OKAY if successful, or MP_MEM if memory could
-  not be allocated for the structure.
- */
-
-mp_err mp_init_size(mp_int *mp, mp_size prec, int kmflag)
-{
-  ARGCHK(mp != NULL && prec > 0, MP_BADARG);
-
-  prec = MP_ROUNDUP(prec, s_mp_defprec);
-  if((DIGITS(mp) = s_mp_alloc(prec, sizeof(mp_digit), kmflag)) == NULL)
-    return MP_MEM;
-
-  SIGN(mp) = ZPOS;
-  USED(mp) = 1;
-  ALLOC(mp) = prec;
-
-  return MP_OKAY;
-
-} /* end mp_init_size() */
-
-/* }}} */
-
-/* {{{ mp_init_copy(mp, from) */
-
-/*
-  mp_init_copy(mp, from)
-
-  Initialize mp as an exact copy of from.  Returns MP_OKAY if
-  successful, MP_MEM if memory could not be allocated for the new
-  structure.
- */
-
-mp_err mp_init_copy(mp_int *mp, const mp_int *from)
-{
-  ARGCHK(mp != NULL && from != NULL, MP_BADARG);
-
-  if(mp == from)
-    return MP_OKAY;
-
-  if((DIGITS(mp) = s_mp_alloc(ALLOC(from), sizeof(mp_digit), FLAG(from))) == NULL)
-    return MP_MEM;
-
-  s_mp_copy(DIGITS(from), DIGITS(mp), USED(from));
-  USED(mp) = USED(from);
-  ALLOC(mp) = ALLOC(from);
-  SIGN(mp) = SIGN(from);
-
-#ifndef _WIN32
-  FLAG(mp) = FLAG(from);
-#endif /* _WIN32 */
-
-  return MP_OKAY;
-
-} /* end mp_init_copy() */
-
-/* }}} */
-
-/* {{{ mp_copy(from, to) */
-
-/*
-  mp_copy(from, to)
-
-  Copies the mp_int 'from' to the mp_int 'to'.  It is presumed that
-  'to' has already been initialized (if not, use mp_init_copy()
-  instead). If 'from' and 'to' are identical, nothing happens.
- */
-
-mp_err mp_copy(const mp_int *from, mp_int *to)
-{
-  ARGCHK(from != NULL && to != NULL, MP_BADARG);
-
-  if(from == to)
-    return MP_OKAY;
-
-  ++mp_copies;
-  { /* copy */
-    mp_digit   *tmp;
-
-    /*
-      If the allocated buffer in 'to' already has enough space to hold
-      all the used digits of 'from', we'll re-use it to avoid hitting
-      the memory allocater more than necessary; otherwise, we'd have
-      to grow anyway, so we just allocate a hunk and make the copy as
-      usual
-     */
-    if(ALLOC(to) >= USED(from)) {
-      s_mp_setz(DIGITS(to) + USED(from), ALLOC(to) - USED(from));
-      s_mp_copy(DIGITS(from), DIGITS(to), USED(from));
-
-    } else {
-      if((tmp = s_mp_alloc(ALLOC(from), sizeof(mp_digit), FLAG(from))) == NULL)
-        return MP_MEM;
-
-      s_mp_copy(DIGITS(from), tmp, USED(from));
-
-      if(DIGITS(to) != NULL) {
-#if MP_CRYPTO
-        s_mp_setz(DIGITS(to), ALLOC(to));
-#endif
-        s_mp_free(DIGITS(to), ALLOC(to));
-      }
-
-      DIGITS(to) = tmp;
-      ALLOC(to) = ALLOC(from);
-    }
-
-    /* Copy the precision and sign from the original */
-    USED(to) = USED(from);
-    SIGN(to) = SIGN(from);
-  } /* end copy */
-
-  return MP_OKAY;
-
-} /* end mp_copy() */
-
-/* }}} */
-
-/* {{{ mp_exch(mp1, mp2) */
-
-/*
-  mp_exch(mp1, mp2)
-
-  Exchange mp1 and mp2 without allocating any intermediate memory
-  (well, unless you count the stack space needed for this call and the
-  locals it creates...).  This cannot fail.
- */
-
-void mp_exch(mp_int *mp1, mp_int *mp2)
-{
-#if MP_ARGCHK == 2
-  assert(mp1 != NULL && mp2 != NULL);
-#else
-  if(mp1 == NULL || mp2 == NULL)
-    return;
-#endif
-
-  s_mp_exch(mp1, mp2);
-
-} /* end mp_exch() */
-
-/* }}} */
-
-/* {{{ mp_clear(mp) */
-
-/*
-  mp_clear(mp)
-
-  Release the storage used by an mp_int, and void its fields so that
-  if someone calls mp_clear() again for the same int later, we won't
-  get tollchocked.
- */
-
-void   mp_clear(mp_int *mp)
-{
-  if(mp == NULL)
-    return;
-
-  if(DIGITS(mp) != NULL) {
-#if MP_CRYPTO
-    s_mp_setz(DIGITS(mp), ALLOC(mp));
-#endif
-    s_mp_free(DIGITS(mp), ALLOC(mp));
-    DIGITS(mp) = NULL;
-  }
-
-  USED(mp) = 0;
-  ALLOC(mp) = 0;
-
-} /* end mp_clear() */
-
-/* }}} */
-
-/* {{{ mp_zero(mp) */
-
-/*
-  mp_zero(mp)
-
-  Set mp to zero.  Does not change the allocated size of the structure,
-  and therefore cannot fail (except on a bad argument, which we ignore)
- */
-void   mp_zero(mp_int *mp)
-{
-  if(mp == NULL)
-    return;
-
-  s_mp_setz(DIGITS(mp), ALLOC(mp));
-  USED(mp) = 1;
-  SIGN(mp) = ZPOS;
-
-} /* end mp_zero() */
-
-/* }}} */
-
-/* {{{ mp_set(mp, d) */
-
-void   mp_set(mp_int *mp, mp_digit d)
-{
-  if(mp == NULL)
-    return;
-
-  mp_zero(mp);
-  DIGIT(mp, 0) = d;
-
-} /* end mp_set() */
-
-/* }}} */
-
-/* {{{ mp_set_int(mp, z) */
-
-mp_err mp_set_int(mp_int *mp, long z)
-{
-  int            ix;
-  unsigned long  v = labs(z);
-  mp_err         res;
-
-  ARGCHK(mp != NULL, MP_BADARG);
-
-  mp_zero(mp);
-  if(z == 0)
-    return MP_OKAY;  /* shortcut for zero */
-
-  if (sizeof v <= sizeof(mp_digit)) {
-    DIGIT(mp,0) = v;
-  } else {
-    for (ix = sizeof(long) - 1; ix >= 0; ix--) {
-      if ((res = s_mp_mul_d(mp, (UCHAR_MAX + 1))) != MP_OKAY)
-        return res;
-
-      res = s_mp_add_d(mp, (mp_digit)((v >> (ix * CHAR_BIT)) & UCHAR_MAX));
-      if (res != MP_OKAY)
-        return res;
-    }
-  }
-  if(z < 0)
-    SIGN(mp) = NEG;
-
-  return MP_OKAY;
-
-} /* end mp_set_int() */
-
-/* }}} */
-
-/* {{{ mp_set_ulong(mp, z) */
-
-mp_err mp_set_ulong(mp_int *mp, unsigned long z)
-{
-  int            ix;
-  mp_err         res;
-
-  ARGCHK(mp != NULL, MP_BADARG);
-
-  mp_zero(mp);
-  if(z == 0)
-    return MP_OKAY;  /* shortcut for zero */
-
-  if (sizeof z <= sizeof(mp_digit)) {
-    DIGIT(mp,0) = z;
-  } else {
-    for (ix = sizeof(long) - 1; ix >= 0; ix--) {
-      if ((res = s_mp_mul_d(mp, (UCHAR_MAX + 1))) != MP_OKAY)
-        return res;
-
-      res = s_mp_add_d(mp, (mp_digit)((z >> (ix * CHAR_BIT)) & UCHAR_MAX));
-      if (res != MP_OKAY)
-        return res;
-    }
-  }
-  return MP_OKAY;
-} /* end mp_set_ulong() */
-
-/* }}} */
-
-/*------------------------------------------------------------------------*/
-/* {{{ Digit arithmetic */
-
-/* {{{ mp_add_d(a, d, b) */
-
-/*
-  mp_add_d(a, d, b)
-
-  Compute the sum b = a + d, for a single digit d.  Respects the sign of
-  its primary addend (single digits are unsigned anyway).
- */
-
-mp_err mp_add_d(const mp_int *a, mp_digit d, mp_int *b)
-{
-  mp_int   tmp;
-  mp_err   res;
-
-  ARGCHK(a != NULL && b != NULL, MP_BADARG);
-
-  if((res = mp_init_copy(&tmp, a)) != MP_OKAY)
-    return res;
-
-  if(SIGN(&tmp) == ZPOS) {
-    if((res = s_mp_add_d(&tmp, d)) != MP_OKAY)
-      goto CLEANUP;
-  } else if(s_mp_cmp_d(&tmp, d) >= 0) {
-    if((res = s_mp_sub_d(&tmp, d)) != MP_OKAY)
-      goto CLEANUP;
-  } else {
-    mp_neg(&tmp, &tmp);
-
-    DIGIT(&tmp, 0) = d - DIGIT(&tmp, 0);
-  }
-
-  if(s_mp_cmp_d(&tmp, 0) == 0)
-    SIGN(&tmp) = ZPOS;
-
-  s_mp_exch(&tmp, b);
-
-CLEANUP:
-  mp_clear(&tmp);
-  return res;
-
-} /* end mp_add_d() */
-
-/* }}} */
-
-/* {{{ mp_sub_d(a, d, b) */
-
-/*
-  mp_sub_d(a, d, b)
-
-  Compute the difference b = a - d, for a single digit d.  Respects the
-  sign of its subtrahend (single digits are unsigned anyway).
- */
-
-mp_err mp_sub_d(const mp_int *a, mp_digit d, mp_int *b)
-{
-  mp_int   tmp;
-  mp_err   res;
-
-  ARGCHK(a != NULL && b != NULL, MP_BADARG);
-
-  if((res = mp_init_copy(&tmp, a)) != MP_OKAY)
-    return res;
-
-  if(SIGN(&tmp) == NEG) {
-    if((res = s_mp_add_d(&tmp, d)) != MP_OKAY)
-      goto CLEANUP;
-  } else if(s_mp_cmp_d(&tmp, d) >= 0) {
-    if((res = s_mp_sub_d(&tmp, d)) != MP_OKAY)
-      goto CLEANUP;
-  } else {
-    mp_neg(&tmp, &tmp);
-
-    DIGIT(&tmp, 0) = d - DIGIT(&tmp, 0);
-    SIGN(&tmp) = NEG;
-  }
-
-  if(s_mp_cmp_d(&tmp, 0) == 0)
-    SIGN(&tmp) = ZPOS;
-
-  s_mp_exch(&tmp, b);
-
-CLEANUP:
-  mp_clear(&tmp);
-  return res;
-
-} /* end mp_sub_d() */
-
-/* }}} */
-
-/* {{{ mp_mul_d(a, d, b) */
-
-/*
-  mp_mul_d(a, d, b)
-
-  Compute the product b = a * d, for a single digit d.  Respects the sign
-  of its multiplicand (single digits are unsigned anyway)
- */
-
-mp_err mp_mul_d(const mp_int *a, mp_digit d, mp_int *b)
-{
-  mp_err  res;
-
-  ARGCHK(a != NULL && b != NULL, MP_BADARG);
-
-  if(d == 0) {
-    mp_zero(b);
-    return MP_OKAY;
-  }
-
-  if((res = mp_copy(a, b)) != MP_OKAY)
-    return res;
-
-  res = s_mp_mul_d(b, d);
-
-  return res;
-
-} /* end mp_mul_d() */
-
-/* }}} */
-
-/* {{{ mp_mul_2(a, c) */
-
-mp_err mp_mul_2(const mp_int *a, mp_int *c)
-{
-  mp_err  res;
-
-  ARGCHK(a != NULL && c != NULL, MP_BADARG);
-
-  if((res = mp_copy(a, c)) != MP_OKAY)
-    return res;
-
-  return s_mp_mul_2(c);
-
-} /* end mp_mul_2() */
-
-/* }}} */
-
-/* {{{ mp_div_d(a, d, q, r) */
-
-/*
-  mp_div_d(a, d, q, r)
-
-  Compute the quotient q = a / d and remainder r = a mod d, for a
-  single digit d.  Respects the sign of its divisor (single digits are
-  unsigned anyway).
- */
-
-mp_err mp_div_d(const mp_int *a, mp_digit d, mp_int *q, mp_digit *r)
-{
-  mp_err   res;
-  mp_int   qp;
-  mp_digit rem;
-  int      pow;
-
-  ARGCHK(a != NULL, MP_BADARG);
-
-  if(d == 0)
-    return MP_RANGE;
-
-  /* Shortcut for powers of two ... */
-  if((pow = s_mp_ispow2d(d)) >= 0) {
-    mp_digit  mask;
-
-    mask = ((mp_digit)1 << pow) - 1;
-    rem = DIGIT(a, 0) & mask;
-
-    if(q) {
-      mp_copy(a, q);
-      s_mp_div_2d(q, pow);
-    }
-
-    if(r)
-      *r = rem;
-
-    return MP_OKAY;
-  }
-
-  if((res = mp_init_copy(&qp, a)) != MP_OKAY)
-    return res;
-
-  res = s_mp_div_d(&qp, d, &rem);
-
-  if(s_mp_cmp_d(&qp, 0) == 0)
-    SIGN(q) = ZPOS;
-
-  if(r)
-    *r = rem;
-
-  if(q)
-    s_mp_exch(&qp, q);
-
-  mp_clear(&qp);
-  return res;
-
-} /* end mp_div_d() */
-
-/* }}} */
-
-/* {{{ mp_div_2(a, c) */
-
-/*
-  mp_div_2(a, c)
-
-  Compute c = a / 2, disregarding the remainder.
- */
-
-mp_err mp_div_2(const mp_int *a, mp_int *c)
-{
-  mp_err  res;
-
-  ARGCHK(a != NULL && c != NULL, MP_BADARG);
-
-  if((res = mp_copy(a, c)) != MP_OKAY)
-    return res;
-
-  s_mp_div_2(c);
-
-  return MP_OKAY;
-
-} /* end mp_div_2() */
-
-/* }}} */
-
-/* {{{ mp_expt_d(a, d, b) */
-
-mp_err mp_expt_d(const mp_int *a, mp_digit d, mp_int *c)
-{
-  mp_int   s, x;
-  mp_err   res;
-
-  ARGCHK(a != NULL && c != NULL, MP_BADARG);
-
-  if((res = mp_init(&s, FLAG(a))) != MP_OKAY)
-    return res;
-  if((res = mp_init_copy(&x, a)) != MP_OKAY)
-    goto X;
-
-  DIGIT(&s, 0) = 1;
-
-  while(d != 0) {
-    if(d & 1) {
-      if((res = s_mp_mul(&s, &x)) != MP_OKAY)
-        goto CLEANUP;
-    }
-
-    d /= 2;
-
-    if((res = s_mp_sqr(&x)) != MP_OKAY)
-      goto CLEANUP;
-  }
-
-  s_mp_exch(&s, c);
-
-CLEANUP:
-  mp_clear(&x);
-X:
-  mp_clear(&s);
-
-  return res;
-
-} /* end mp_expt_d() */
-
-/* }}} */
-
-/* }}} */
-
-/*------------------------------------------------------------------------*/
-/* {{{ Full arithmetic */
-
-/* {{{ mp_abs(a, b) */
-
-/*
-  mp_abs(a, b)
-
-  Compute b = |a|.  'a' and 'b' may be identical.
- */
-
-mp_err mp_abs(const mp_int *a, mp_int *b)
-{
-  mp_err   res;
-
-  ARGCHK(a != NULL && b != NULL, MP_BADARG);
-
-  if((res = mp_copy(a, b)) != MP_OKAY)
-    return res;
-
-  SIGN(b) = ZPOS;
-
-  return MP_OKAY;
-
-} /* end mp_abs() */
-
-/* }}} */
-
-/* {{{ mp_neg(a, b) */
-
-/*
-  mp_neg(a, b)
-
-  Compute b = -a.  'a' and 'b' may be identical.
- */
-
-mp_err mp_neg(const mp_int *a, mp_int *b)
-{
-  mp_err   res;
-
-  ARGCHK(a != NULL && b != NULL, MP_BADARG);
-
-  if((res = mp_copy(a, b)) != MP_OKAY)
-    return res;
-
-  if(s_mp_cmp_d(b, 0) == MP_EQ)
-    SIGN(b) = ZPOS;
-  else
-    SIGN(b) = (SIGN(b) == NEG) ? ZPOS : NEG;
-
-  return MP_OKAY;
-
-} /* end mp_neg() */
-
-/* }}} */
-
-/* {{{ mp_add(a, b, c) */
-
-/*
-  mp_add(a, b, c)
-
-  Compute c = a + b.  All parameters may be identical.
- */
-
-mp_err mp_add(const mp_int *a, const mp_int *b, mp_int *c)
-{
-  mp_err  res;
-
-  ARGCHK(a != NULL && b != NULL && c != NULL, MP_BADARG);
-
-  if(SIGN(a) == SIGN(b)) { /* same sign:  add values, keep sign */
-    MP_CHECKOK( s_mp_add_3arg(a, b, c) );
-  } else if(s_mp_cmp(a, b) >= 0) {  /* different sign: |a| >= |b|   */
-    MP_CHECKOK( s_mp_sub_3arg(a, b, c) );
-  } else {                          /* different sign: |a|  < |b|   */
-    MP_CHECKOK( s_mp_sub_3arg(b, a, c) );
-  }
-
-  if (s_mp_cmp_d(c, 0) == MP_EQ)
-    SIGN(c) = ZPOS;
-
-CLEANUP:
-  return res;
-
-} /* end mp_add() */
-
-/* }}} */
-
-/* {{{ mp_sub(a, b, c) */
-
-/*
-  mp_sub(a, b, c)
-
-  Compute c = a - b.  All parameters may be identical.
- */
-
-mp_err mp_sub(const mp_int *a, const mp_int *b, mp_int *c)
-{
-  mp_err  res;
-  int     magDiff;
-
-  ARGCHK(a != NULL && b != NULL && c != NULL, MP_BADARG);
-
-  if (a == b) {
-    mp_zero(c);
-    return MP_OKAY;
-  }
-
-  if (MP_SIGN(a) != MP_SIGN(b)) {
-    MP_CHECKOK( s_mp_add_3arg(a, b, c) );
-  } else if (!(magDiff = s_mp_cmp(a, b))) {
-    mp_zero(c);
-    res = MP_OKAY;
-  } else if (magDiff > 0) {
-    MP_CHECKOK( s_mp_sub_3arg(a, b, c) );
-  } else {
-    MP_CHECKOK( s_mp_sub_3arg(b, a, c) );
-    MP_SIGN(c) = !MP_SIGN(a);
-  }
-
-  if (s_mp_cmp_d(c, 0) == MP_EQ)
-    MP_SIGN(c) = MP_ZPOS;
-
-CLEANUP:
-  return res;
-
-} /* end mp_sub() */
-
-/* }}} */
-
-/* {{{ mp_mul(a, b, c) */
-
-/*
-  mp_mul(a, b, c)
-
-  Compute c = a * b.  All parameters may be identical.
- */
-mp_err   mp_mul(const mp_int *a, const mp_int *b, mp_int * c)
-{
-  mp_digit *pb;
-  mp_int   tmp;
-  mp_err   res;
-  mp_size  ib;
-  mp_size  useda, usedb;
-
-  ARGCHK(a != NULL && b != NULL && c != NULL, MP_BADARG);
-
-  if (a == c) {
-    if ((res = mp_init_copy(&tmp, a)) != MP_OKAY)
-      return res;
-    if (a == b)
-      b = &tmp;
-    a = &tmp;
-  } else if (b == c) {
-    if ((res = mp_init_copy(&tmp, b)) != MP_OKAY)
-      return res;
-    b = &tmp;
-  } else {
-    MP_DIGITS(&tmp) = 0;
-  }
-
-  if (MP_USED(a) < MP_USED(b)) {
-    const mp_int *xch = b;      /* switch a and b, to do fewer outer loops */
-    b = a;
-    a = xch;
-  }
-
-  MP_USED(c) = 1; MP_DIGIT(c, 0) = 0;
-  if((res = s_mp_pad(c, USED(a) + USED(b))) != MP_OKAY)
-    goto CLEANUP;
-
-#ifdef NSS_USE_COMBA
-  if ((MP_USED(a) == MP_USED(b)) && IS_POWER_OF_2(MP_USED(b))) {
-      if (MP_USED(a) == 4) {
-          s_mp_mul_comba_4(a, b, c);
-          goto CLEANUP;
-      }
-      if (MP_USED(a) == 8) {
-          s_mp_mul_comba_8(a, b, c);
-          goto CLEANUP;
-      }
-      if (MP_USED(a) == 16) {
-          s_mp_mul_comba_16(a, b, c);
-          goto CLEANUP;
-      }
-      if (MP_USED(a) == 32) {
-          s_mp_mul_comba_32(a, b, c);
-          goto CLEANUP;
-      }
-  }
-#endif
-
-  pb = MP_DIGITS(b);
-  s_mpv_mul_d(MP_DIGITS(a), MP_USED(a), *pb++, MP_DIGITS(c));
-
-  /* Outer loop:  Digits of b */
-  useda = MP_USED(a);
-  usedb = MP_USED(b);
-  for (ib = 1; ib < usedb; ib++) {
-    mp_digit b_i    = *pb++;
-
-    /* Inner product:  Digits of a */
-    if (b_i)
-      s_mpv_mul_d_add(MP_DIGITS(a), useda, b_i, MP_DIGITS(c) + ib);
-    else
-      MP_DIGIT(c, ib + useda) = b_i;
-  }
-
-  s_mp_clamp(c);
-
-  if(SIGN(a) == SIGN(b) || s_mp_cmp_d(c, 0) == MP_EQ)
-    SIGN(c) = ZPOS;
-  else
-    SIGN(c) = NEG;
-
-CLEANUP:
-  mp_clear(&tmp);
-  return res;
-} /* end mp_mul() */
-
-/* }}} */
-
-/* {{{ mp_sqr(a, sqr) */
-
-#if MP_SQUARE
-/*
-  Computes the square of a.  This can be done more
-  efficiently than a general multiplication, because many of the
-  computation steps are redundant when squaring.  The inner product
-  step is a bit more complicated, but we save a fair number of
-  iterations of the multiplication loop.
- */
-
-/* sqr = a^2;   Caller provides both a and tmp; */
-mp_err   mp_sqr(const mp_int *a, mp_int *sqr)
-{
-  mp_digit *pa;
-  mp_digit d;
-  mp_err   res;
-  mp_size  ix;
-  mp_int   tmp;
-  int      count;
-
-  ARGCHK(a != NULL && sqr != NULL, MP_BADARG);
-
-  if (a == sqr) {
-    if((res = mp_init_copy(&tmp, a)) != MP_OKAY)
-      return res;
-    a = &tmp;
-  } else {
-    DIGITS(&tmp) = 0;
-    res = MP_OKAY;
-  }
-
-  ix = 2 * MP_USED(a);
-  if (ix > MP_ALLOC(sqr)) {
-    MP_USED(sqr) = 1;
-    MP_CHECKOK( s_mp_grow(sqr, ix) );
-  }
-  MP_USED(sqr) = ix;
-  MP_DIGIT(sqr, 0) = 0;
-
-#ifdef NSS_USE_COMBA
-  if (IS_POWER_OF_2(MP_USED(a))) {
-      if (MP_USED(a) == 4) {
-          s_mp_sqr_comba_4(a, sqr);
-          goto CLEANUP;
-      }
-      if (MP_USED(a) == 8) {
-          s_mp_sqr_comba_8(a, sqr);
-          goto CLEANUP;
-      }
-      if (MP_USED(a) == 16) {
-          s_mp_sqr_comba_16(a, sqr);
-          goto CLEANUP;
-      }
-      if (MP_USED(a) == 32) {
-          s_mp_sqr_comba_32(a, sqr);
-          goto CLEANUP;
-      }
-  }
-#endif
-
-  pa = MP_DIGITS(a);
-  count = MP_USED(a) - 1;
-  if (count > 0) {
-    d = *pa++;
-    s_mpv_mul_d(pa, count, d, MP_DIGITS(sqr) + 1);
-    for (ix = 3; --count > 0; ix += 2) {
-      d = *pa++;
-      s_mpv_mul_d_add(pa, count, d, MP_DIGITS(sqr) + ix);
-    } /* for(ix ...) */
-    MP_DIGIT(sqr, MP_USED(sqr)-1) = 0; /* above loop stopped short of this. */
-
-    /* now sqr *= 2 */
-    s_mp_mul_2(sqr);
-  } else {
-    MP_DIGIT(sqr, 1) = 0;
-  }
-
-  /* now add the squares of the digits of a to sqr. */
-  s_mpv_sqr_add_prop(MP_DIGITS(a), MP_USED(a), MP_DIGITS(sqr));
-
-  SIGN(sqr) = ZPOS;
-  s_mp_clamp(sqr);
-
-CLEANUP:
-  mp_clear(&tmp);
-  return res;
-
-} /* end mp_sqr() */
-#endif
-
-/* }}} */
-
-/* {{{ mp_div(a, b, q, r) */
-
-/*
-  mp_div(a, b, q, r)
-
-  Compute q = a / b and r = a mod b.  Input parameters may be re-used
-  as output parameters.  If q or r is NULL, that portion of the
-  computation will be discarded (although it will still be computed)
- */
-mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *q, mp_int *r)
-{
-  mp_err   res;
-  mp_int   *pQ, *pR;
-  mp_int   qtmp, rtmp, btmp;
-  int      cmp;
-  mp_sign  signA;
-  mp_sign  signB;
-
-  ARGCHK(a != NULL && b != NULL, MP_BADARG);
-
-  signA = MP_SIGN(a);
-  signB = MP_SIGN(b);
-
-  if(mp_cmp_z(b) == MP_EQ)
-    return MP_RANGE;
-
-  DIGITS(&qtmp) = 0;
-  DIGITS(&rtmp) = 0;
-  DIGITS(&btmp) = 0;
-
-  /* Set up some temporaries... */
-  if (!r || r == a || r == b) {
-    MP_CHECKOK( mp_init_copy(&rtmp, a) );
-    pR = &rtmp;
-  } else {
-    MP_CHECKOK( mp_copy(a, r) );
-    pR = r;
-  }
-
-  if (!q || q == a || q == b) {
-    MP_CHECKOK( mp_init_size(&qtmp, MP_USED(a), FLAG(a)) );
-    pQ = &qtmp;
-  } else {
-    MP_CHECKOK( s_mp_pad(q, MP_USED(a)) );
-    pQ = q;
-    mp_zero(pQ);
-  }
-
-  /*
-    If |a| <= |b|, we can compute the solution without division;
-    otherwise, we actually do the work required.
-   */
-  if ((cmp = s_mp_cmp(a, b)) <= 0) {
-    if (cmp) {
-      /* r was set to a above. */
-      mp_zero(pQ);
-    } else {
-      mp_set(pQ, 1);
-      mp_zero(pR);
-    }
-  } else {
-    MP_CHECKOK( mp_init_copy(&btmp, b) );
-    MP_CHECKOK( s_mp_div(pR, &btmp, pQ) );
-  }
-
-  /* Compute the signs for the output  */
-  MP_SIGN(pR) = signA;   /* Sr = Sa              */
-  /* Sq = ZPOS if Sa == Sb */ /* Sq = NEG if Sa != Sb */
-  MP_SIGN(pQ) = (signA == signB) ? ZPOS : NEG;
-
-  if(s_mp_cmp_d(pQ, 0) == MP_EQ)
-    SIGN(pQ) = ZPOS;
-  if(s_mp_cmp_d(pR, 0) == MP_EQ)
-    SIGN(pR) = ZPOS;
-
-  /* Copy output, if it is needed      */
-  if(q && q != pQ)
-    s_mp_exch(pQ, q);
-
-  if(r && r != pR)
-    s_mp_exch(pR, r);
-
-CLEANUP:
-  mp_clear(&btmp);
-  mp_clear(&rtmp);
-  mp_clear(&qtmp);
-
-  return res;
-
-} /* end mp_div() */
-
-/* }}} */
-
-/* {{{ mp_div_2d(a, d, q, r) */
-
-mp_err mp_div_2d(const mp_int *a, mp_digit d, mp_int *q, mp_int *r)
-{
-  mp_err  res;
-
-  ARGCHK(a != NULL, MP_BADARG);
-
-  if(q) {
-    if((res = mp_copy(a, q)) != MP_OKAY)
-      return res;
-  }
-  if(r) {
-    if((res = mp_copy(a, r)) != MP_OKAY)
-      return res;
-  }
-  if(q) {
-    s_mp_div_2d(q, d);
-  }
-  if(r) {
-    s_mp_mod_2d(r, d);
-  }
-
-  return MP_OKAY;
-
-} /* end mp_div_2d() */
-
-/* }}} */
-
-/* {{{ mp_expt(a, b, c) */
-
-/*
-  mp_expt(a, b, c)
-
-  Compute c = a ** b, that is, raise a to the b power.  Uses a
-  standard iterative square-and-multiply technique.
- */
-
-mp_err mp_expt(mp_int *a, mp_int *b, mp_int *c)
-{
-  mp_int   s, x;
-  mp_err   res;
-  mp_digit d;
-  int      dig, bit;
-
-  ARGCHK(a != NULL && b != NULL && c != NULL, MP_BADARG);
-
-  if(mp_cmp_z(b) < 0)
-    return MP_RANGE;
-
-  if((res = mp_init(&s, FLAG(a))) != MP_OKAY)
-    return res;
-
-  mp_set(&s, 1);
-
-  if((res = mp_init_copy(&x, a)) != MP_OKAY)
-    goto X;
-
-  /* Loop over low-order digits in ascending order */
-  for(dig = 0; dig < (USED(b) - 1); dig++) {
-    d = DIGIT(b, dig);
-
-    /* Loop over bits of each non-maximal digit */
-    for(bit = 0; bit < DIGIT_BIT; bit++) {
-      if(d & 1) {
-        if((res = s_mp_mul(&s, &x)) != MP_OKAY)
-          goto CLEANUP;
-      }
-
-      d >>= 1;
-
-      if((res = s_mp_sqr(&x)) != MP_OKAY)
-        goto CLEANUP;
-    }
-  }
-
-  /* Consider now the last digit... */
-  d = DIGIT(b, dig);
-
-  while(d) {
-    if(d & 1) {
-      if((res = s_mp_mul(&s, &x)) != MP_OKAY)
-        goto CLEANUP;
-    }
-
-    d >>= 1;
-
-    if((res = s_mp_sqr(&x)) != MP_OKAY)
-      goto CLEANUP;
-  }
-
-  if(mp_iseven(b))
-    SIGN(&s) = SIGN(a);
-
-  res = mp_copy(&s, c);
-
-CLEANUP:
-  mp_clear(&x);
-X:
-  mp_clear(&s);
-
-  return res;
-
-} /* end mp_expt() */
-
-/* }}} */
-
-/* {{{ mp_2expt(a, k) */
-
-/* Compute a = 2^k */
-
-mp_err mp_2expt(mp_int *a, mp_digit k)
-{
-  ARGCHK(a != NULL, MP_BADARG);
-
-  return s_mp_2expt(a, k);
-
-} /* end mp_2expt() */
-
-/* }}} */
-
-/* {{{ mp_mod(a, m, c) */
-
-/*
-  mp_mod(a, m, c)
-
-  Compute c = a (mod m).  Result will always be 0 <= c < m.
- */
-
-mp_err mp_mod(const mp_int *a, const mp_int *m, mp_int *c)
-{
-  mp_err  res;
-  int     mag;
-
-  ARGCHK(a != NULL && m != NULL && c != NULL, MP_BADARG);
-
-  if(SIGN(m) == NEG)
-    return MP_RANGE;
-
-  /*
-     If |a| > m, we need to divide to get the remainder and take the
-     absolute value.
-
-     If |a| < m, we don't need to do any division, just copy and adjust
-     the sign (if a is negative).
-
-     If |a| == m, we can simply set the result to zero.
-
-     This order is intended to minimize the average path length of the
-     comparison chain on common workloads -- the most frequent cases are
-     that |a| != m, so we do those first.
-   */
-  if((mag = s_mp_cmp(a, m)) > 0) {
-    if((res = mp_div(a, m, NULL, c)) != MP_OKAY)
-      return res;
-
-    if(SIGN(c) == NEG) {
-      if((res = mp_add(c, m, c)) != MP_OKAY)
-        return res;
-    }
-
-  } else if(mag < 0) {
-    if((res = mp_copy(a, c)) != MP_OKAY)
-      return res;
-
-    if(mp_cmp_z(a) < 0) {
-      if((res = mp_add(c, m, c)) != MP_OKAY)
-        return res;
-
-    }
-
-  } else {
-    mp_zero(c);
-
-  }
-
-  return MP_OKAY;
-
-} /* end mp_mod() */
-
-/* }}} */
-
-/* {{{ mp_mod_d(a, d, c) */
-
-/*
-  mp_mod_d(a, d, c)
-
-  Compute c = a (mod d).  Result will always be 0 <= c < d
- */
-mp_err mp_mod_d(const mp_int *a, mp_digit d, mp_digit *c)
-{
-  mp_err   res;
-  mp_digit rem;
-
-  ARGCHK(a != NULL && c != NULL, MP_BADARG);
-
-  if(s_mp_cmp_d(a, d) > 0) {
-    if((res = mp_div_d(a, d, NULL, &rem)) != MP_OKAY)
-      return res;
-
-  } else {
-    if(SIGN(a) == NEG)
-      rem = d - DIGIT(a, 0);
-    else
-      rem = DIGIT(a, 0);
-  }
-
-  if(c)
-    *c = rem;
-
-  return MP_OKAY;
-
-} /* end mp_mod_d() */
-
-/* }}} */
-
-/* {{{ mp_sqrt(a, b) */
-
-/*
-  mp_sqrt(a, b)
-
-  Compute the integer square root of a, and store the result in b.
-  Uses an integer-arithmetic version of Newton's iterative linear
-  approximation technique to determine this value; the result has the
-  following two properties:
-
-     b^2 <= a
-     (b+1)^2 >= a
-
-  It is a range error to pass a negative value.
- */
-mp_err mp_sqrt(const mp_int *a, mp_int *b)
-{
-  mp_int   x, t;
-  mp_err   res;
-  mp_size  used;
-
-  ARGCHK(a != NULL && b != NULL, MP_BADARG);
-
-  /* Cannot take square root of a negative value */
-  if(SIGN(a) == NEG)
-    return MP_RANGE;
-
-  /* Special cases for zero and one, trivial     */
-  if(mp_cmp_d(a, 1) <= 0)
-    return mp_copy(a, b);
-
-  /* Initialize the temporaries we'll use below  */
-  if((res = mp_init_size(&t, USED(a), FLAG(a))) != MP_OKAY)
-    return res;
-
-  /* Compute an initial guess for the iteration as a itself */
-  if((res = mp_init_copy(&x, a)) != MP_OKAY)
-    goto X;
-
-  used = MP_USED(&x);
-  if (used > 1) {
-    s_mp_rshd(&x, used / 2);
-  }
-
-  for(;;) {
-    /* t = (x * x) - a */
-    mp_copy(&x, &t);      /* can't fail, t is big enough for original x */
-    if((res = mp_sqr(&t, &t)) != MP_OKAY ||
-       (res = mp_sub(&t, a, &t)) != MP_OKAY)
-      goto CLEANUP;
-
-    /* t = t / 2x       */
-    s_mp_mul_2(&x);
-    if((res = mp_div(&t, &x, &t, NULL)) != MP_OKAY)
-      goto CLEANUP;
-    s_mp_div_2(&x);
-
-    /* Terminate the loop, if the quotient is zero */
-    if(mp_cmp_z(&t) == MP_EQ)
-      break;
-
-    /* x = x - t       */
-    if((res = mp_sub(&x, &t, &x)) != MP_OKAY)
-      goto CLEANUP;
-
-  }
-
-  /* Copy result to output parameter */
-  mp_sub_d(&x, 1, &x);
-  s_mp_exch(&x, b);
-
- CLEANUP:
-  mp_clear(&x);
- X:
-  mp_clear(&t);
-
-  return res;
-
-} /* end mp_sqrt() */
-
-/* }}} */
-
-/* }}} */
-
-/*------------------------------------------------------------------------*/
-/* {{{ Modular arithmetic */
-
-#if MP_MODARITH
-/* {{{ mp_addmod(a, b, m, c) */
-
-/*
-  mp_addmod(a, b, m, c)
-
-  Compute c = (a + b) mod m
- */
-
-mp_err mp_addmod(const mp_int *a, const mp_int *b, const mp_int *m, mp_int *c)
-{
-  mp_err  res;
-
-  ARGCHK(a != NULL && b != NULL && m != NULL && c != NULL, MP_BADARG);
-
-  if((res = mp_add(a, b, c)) != MP_OKAY)
-    return res;
-  if((res = mp_mod(c, m, c)) != MP_OKAY)
-    return res;
-
-  return MP_OKAY;
-
-}
-
-/* }}} */
-
-/* {{{ mp_submod(a, b, m, c) */
-
-/*
-  mp_submod(a, b, m, c)
-
-  Compute c = (a - b) mod m
- */
-
-mp_err mp_submod(const mp_int *a, const mp_int *b, const mp_int *m, mp_int *c)
-{
-  mp_err  res;
-
-  ARGCHK(a != NULL && b != NULL && m != NULL && c != NULL, MP_BADARG);
-
-  if((res = mp_sub(a, b, c)) != MP_OKAY)
-    return res;
-  if((res = mp_mod(c, m, c)) != MP_OKAY)
-    return res;
-
-  return MP_OKAY;
-
-}
-
-/* }}} */
-
-/* {{{ mp_mulmod(a, b, m, c) */
-
-/*
-  mp_mulmod(a, b, m, c)
-
-  Compute c = (a * b) mod m
- */
-
-mp_err mp_mulmod(const mp_int *a, const mp_int *b, const mp_int *m, mp_int *c)
-{
-  mp_err  res;
-
-  ARGCHK(a != NULL && b != NULL && m != NULL && c != NULL, MP_BADARG);
-
-  if((res = mp_mul(a, b, c)) != MP_OKAY)
-    return res;
-  if((res = mp_mod(c, m, c)) != MP_OKAY)
-    return res;
-
-  return MP_OKAY;
-
-}
-
-/* }}} */
-
-/* {{{ mp_sqrmod(a, m, c) */
-
-#if MP_SQUARE
-mp_err mp_sqrmod(const mp_int *a, const mp_int *m, mp_int *c)
-{
-  mp_err  res;
-
-  ARGCHK(a != NULL && m != NULL && c != NULL, MP_BADARG);
-
-  if((res = mp_sqr(a, c)) != MP_OKAY)
-    return res;
-  if((res = mp_mod(c, m, c)) != MP_OKAY)
-    return res;
-
-  return MP_OKAY;
-
-} /* end mp_sqrmod() */
-#endif
-
-/* }}} */
-
-/* {{{ s_mp_exptmod(a, b, m, c) */
-
-/*
-  s_mp_exptmod(a, b, m, c)
-
-  Compute c = (a ** b) mod m.  Uses a standard square-and-multiply
-  method with modular reductions at each step. (This is basically the
-  same code as mp_expt(), except for the addition of the reductions)
-
-  The modular reductions are done using Barrett's algorithm (see
-  s_mp_reduce() below for details)
- */
-
-mp_err s_mp_exptmod(const mp_int *a, const mp_int *b, const mp_int *m, mp_int *c)
-{
-  mp_int   s, x, mu;
-  mp_err   res;
-  mp_digit d;
-  int      dig, bit;
-
-  ARGCHK(a != NULL && b != NULL && c != NULL, MP_BADARG);
-
-  if(mp_cmp_z(b) < 0 || mp_cmp_z(m) <= 0)
-    return MP_RANGE;
-
-  if((res = mp_init(&s, FLAG(a))) != MP_OKAY)
-    return res;
-  if((res = mp_init_copy(&x, a)) != MP_OKAY ||
-     (res = mp_mod(&x, m, &x)) != MP_OKAY)
-    goto X;
-  if((res = mp_init(&mu, FLAG(a))) != MP_OKAY)
-    goto MU;
-
-  mp_set(&s, 1);
-
-  /* mu = b^2k / m */
-  s_mp_add_d(&mu, 1);
-  s_mp_lshd(&mu, 2 * USED(m));
-  if((res = mp_div(&mu, m, &mu, NULL)) != MP_OKAY)
-    goto CLEANUP;
-
-  /* Loop over digits of b in ascending order, except highest order */
-  for(dig = 0; dig < (USED(b) - 1); dig++) {
-    d = DIGIT(b, dig);
-
-    /* Loop over the bits of the lower-order digits */
-    for(bit = 0; bit < DIGIT_BIT; bit++) {
-      if(d & 1) {
-        if((res = s_mp_mul(&s, &x)) != MP_OKAY)
-          goto CLEANUP;
-        if((res = s_mp_reduce(&s, m, &mu)) != MP_OKAY)
-          goto CLEANUP;
-      }
-
-      d >>= 1;
-
-      if((res = s_mp_sqr(&x)) != MP_OKAY)
-        goto CLEANUP;
-      if((res = s_mp_reduce(&x, m, &mu)) != MP_OKAY)
-        goto CLEANUP;
-    }
-  }
-
-  /* Now do the last digit... */
-  d = DIGIT(b, dig);
-
-  while(d) {
-    if(d & 1) {
-      if((res = s_mp_mul(&s, &x)) != MP_OKAY)
-        goto CLEANUP;
-      if((res = s_mp_reduce(&s, m, &mu)) != MP_OKAY)
-        goto CLEANUP;
-    }
-
-    d >>= 1;
-
-    if((res = s_mp_sqr(&x)) != MP_OKAY)
-      goto CLEANUP;
-    if((res = s_mp_reduce(&x, m, &mu)) != MP_OKAY)
-      goto CLEANUP;
-  }
-
-  s_mp_exch(&s, c);
-
- CLEANUP:
-  mp_clear(&mu);
- MU:
-  mp_clear(&x);
- X:
-  mp_clear(&s);
-
-  return res;
-
-} /* end s_mp_exptmod() */
-
-/* }}} */
-
-/* {{{ mp_exptmod_d(a, d, m, c) */
-
-mp_err mp_exptmod_d(const mp_int *a, mp_digit d, const mp_int *m, mp_int *c)
-{
-  mp_int   s, x;
-  mp_err   res;
-
-  ARGCHK(a != NULL && c != NULL, MP_BADARG);
-
-  if((res = mp_init(&s, FLAG(a))) != MP_OKAY)
-    return res;
-  if((res = mp_init_copy(&x, a)) != MP_OKAY)
-    goto X;
-
-  mp_set(&s, 1);
-
-  while(d != 0) {
-    if(d & 1) {
-      if((res = s_mp_mul(&s, &x)) != MP_OKAY ||
-         (res = mp_mod(&s, m, &s)) != MP_OKAY)
-        goto CLEANUP;
-    }
-
-    d /= 2;
-
-    if((res = s_mp_sqr(&x)) != MP_OKAY ||
-       (res = mp_mod(&x, m, &x)) != MP_OKAY)
-      goto CLEANUP;
-  }
-
-  s_mp_exch(&s, c);
-
-CLEANUP:
-  mp_clear(&x);
-X:
-  mp_clear(&s);
-
-  return res;
-
-} /* end mp_exptmod_d() */
-
-/* }}} */
-#endif /* if MP_MODARITH */
-
-/* }}} */
-
-/*------------------------------------------------------------------------*/
-/* {{{ Comparison functions */
-
-/* {{{ mp_cmp_z(a) */
-
-/*
-  mp_cmp_z(a)
-
-  Compare a <=> 0.  Returns <0 if a<0, 0 if a=0, >0 if a>0.
- */
-
-int    mp_cmp_z(const mp_int *a)
-{
-  if(SIGN(a) == NEG)
-    return MP_LT;
-  else if(USED(a) == 1 && DIGIT(a, 0) == 0)
-    return MP_EQ;
-  else
-    return MP_GT;
-
-} /* end mp_cmp_z() */
-
-/* }}} */
-
-/* {{{ mp_cmp_d(a, d) */
-
-/*
-  mp_cmp_d(a, d)
-
-  Compare a <=> d.  Returns <0 if a<d, 0 if a=d, >0 if a>d
- */
-
-int    mp_cmp_d(const mp_int *a, mp_digit d)
-{
-  ARGCHK(a != NULL, MP_EQ);
-
-  if(SIGN(a) == NEG)
-    return MP_LT;
-
-  return s_mp_cmp_d(a, d);
-
-} /* end mp_cmp_d() */
-
-/* }}} */
-
-/* {{{ mp_cmp(a, b) */
-
-int    mp_cmp(const mp_int *a, const mp_int *b)
-{
-  ARGCHK(a != NULL && b != NULL, MP_EQ);
-
-  if(SIGN(a) == SIGN(b)) {
-    int  mag;
-
-    if((mag = s_mp_cmp(a, b)) == MP_EQ)
-      return MP_EQ;
-
-    if(SIGN(a) == ZPOS)
-      return mag;
-    else
-      return -mag;
-
-  } else if(SIGN(a) == ZPOS) {
-    return MP_GT;
-  } else {
-    return MP_LT;
-  }
-
-} /* end mp_cmp() */
-
-/* }}} */
-
-/* {{{ mp_cmp_mag(a, b) */
-
-/*
-  mp_cmp_mag(a, b)
-
-  Compares |a| <=> |b|, and returns an appropriate comparison result
- */
-
-int    mp_cmp_mag(mp_int *a, mp_int *b)
-{
-  ARGCHK(a != NULL && b != NULL, MP_EQ);
-
-  return s_mp_cmp(a, b);
-
-} /* end mp_cmp_mag() */
-
-/* }}} */
-
-/* {{{ mp_cmp_int(a, z, kmflag) */
-
-/*
-  This just converts z to an mp_int, and uses the existing comparison
-  routines.  This is sort of inefficient, but it's not clear to me how
-  frequently this wil get used anyway.  For small positive constants,
-  you can always use mp_cmp_d(), and for zero, there is mp_cmp_z().
- */
-int    mp_cmp_int(const mp_int *a, long z, int kmflag)
-{
-  mp_int  tmp;
-  int     out;
-
-  ARGCHK(a != NULL, MP_EQ);
-
-  mp_init(&tmp, kmflag); mp_set_int(&tmp, z);
-  out = mp_cmp(a, &tmp);
-  mp_clear(&tmp);
-
-  return out;
-
-} /* end mp_cmp_int() */
-
-/* }}} */
-
-/* {{{ mp_isodd(a) */
-
-/*
-  mp_isodd(a)
-
-  Returns a true (non-zero) value if a is odd, false (zero) otherwise.
- */
-int    mp_isodd(const mp_int *a)
-{
-  ARGCHK(a != NULL, 0);
-
-  return (int)(DIGIT(a, 0) & 1);
-
-} /* end mp_isodd() */
-
-/* }}} */
-
-/* {{{ mp_iseven(a) */
-
-int    mp_iseven(const mp_int *a)
-{
-  return !mp_isodd(a);
-
-} /* end mp_iseven() */
-
-/* }}} */
-
-/* }}} */
-
-/*------------------------------------------------------------------------*/
-/* {{{ Number theoretic functions */
-
-#if MP_NUMTH
-/* {{{ mp_gcd(a, b, c) */
-
-/*
-  Like the old mp_gcd() function, except computes the GCD using the
-  binary algorithm due to Josef Stein in 1961 (via Knuth).
- */
-mp_err mp_gcd(mp_int *a, mp_int *b, mp_int *c)
-{
-  mp_err   res;
-  mp_int   u, v, t;
-  mp_size  k = 0;
-
-  ARGCHK(a != NULL && b != NULL && c != NULL, MP_BADARG);
-
-  if(mp_cmp_z(a) == MP_EQ && mp_cmp_z(b) == MP_EQ)
-      return MP_RANGE;
-  if(mp_cmp_z(a) == MP_EQ) {
-    return mp_copy(b, c);
-  } else if(mp_cmp_z(b) == MP_EQ) {
-    return mp_copy(a, c);
-  }
-
-  if((res = mp_init(&t, FLAG(a))) != MP_OKAY)
-    return res;
-  if((res = mp_init_copy(&u, a)) != MP_OKAY)
-    goto U;
-  if((res = mp_init_copy(&v, b)) != MP_OKAY)
-    goto V;
-
-  SIGN(&u) = ZPOS;
-  SIGN(&v) = ZPOS;
-
-  /* Divide out common factors of 2 until at least 1 of a, b is even */
-  while(mp_iseven(&u) && mp_iseven(&v)) {
-    s_mp_div_2(&u);
-    s_mp_div_2(&v);
-    ++k;
-  }
-
-  /* Initialize t */
-  if(mp_isodd(&u)) {
-    if((res = mp_copy(&v, &t)) != MP_OKAY)
-      goto CLEANUP;
-
-    /* t = -v */
-    if(SIGN(&v) == ZPOS)
-      SIGN(&t) = NEG;
-    else
-      SIGN(&t) = ZPOS;
-
-  } else {
-    if((res = mp_copy(&u, &t)) != MP_OKAY)
-      goto CLEANUP;
-
-  }
-
-  for(;;) {
-    while(mp_iseven(&t)) {
-      s_mp_div_2(&t);
-    }
-
-    if(mp_cmp_z(&t) == MP_GT) {
-      if((res = mp_copy(&t, &u)) != MP_OKAY)
-        goto CLEANUP;
-
-    } else {
-      if((res = mp_copy(&t, &v)) != MP_OKAY)
-        goto CLEANUP;
-
-      /* v = -t */
-      if(SIGN(&t) == ZPOS)
-        SIGN(&v) = NEG;
-      else
-        SIGN(&v) = ZPOS;
-    }
-
-    if((res = mp_sub(&u, &v, &t)) != MP_OKAY)
-      goto CLEANUP;
-
-    if(s_mp_cmp_d(&t, 0) == MP_EQ)
-      break;
-  }
-
-  s_mp_2expt(&v, k);       /* v = 2^k   */
-  res = mp_mul(&u, &v, c); /* c = u * v */
-
- CLEANUP:
-  mp_clear(&v);
- V:
-  mp_clear(&u);
- U:
-  mp_clear(&t);
-
-  return res;
-
-} /* end mp_gcd() */
-
-/* }}} */
-
-/* {{{ mp_lcm(a, b, c) */
-
-/* We compute the least common multiple using the rule:
-
-   ab = [a, b](a, b)
-
-   ... by computing the product, and dividing out the gcd.
- */
-
-mp_err mp_lcm(mp_int *a, mp_int *b, mp_int *c)
-{
-  mp_int  gcd, prod;
-  mp_err  res;
-
-  ARGCHK(a != NULL && b != NULL && c != NULL, MP_BADARG);
-
-  /* Set up temporaries */
-  if((res = mp_init(&gcd, FLAG(a))) != MP_OKAY)
-    return res;
-  if((res = mp_init(&prod, FLAG(a))) != MP_OKAY)
-    goto GCD;
-
-  if((res = mp_mul(a, b, &prod)) != MP_OKAY)
-    goto CLEANUP;
-  if((res = mp_gcd(a, b, &gcd)) != MP_OKAY)
-    goto CLEANUP;
-
-  res = mp_div(&prod, &gcd, c, NULL);
-
- CLEANUP:
-  mp_clear(&prod);
- GCD:
-  mp_clear(&gcd);
-
-  return res;
-
-} /* end mp_lcm() */
-
-/* }}} */
-
-/* {{{ mp_xgcd(a, b, g, x, y) */
-
-/*
-  mp_xgcd(a, b, g, x, y)
-
-  Compute g = (a, b) and values x and y satisfying Bezout's identity
-  (that is, ax + by = g).  This uses the binary extended GCD algorithm
-  based on the Stein algorithm used for mp_gcd()
-  See algorithm 14.61 in Handbook of Applied Cryptogrpahy.
- */
-
-mp_err mp_xgcd(const mp_int *a, const mp_int *b, mp_int *g, mp_int *x, mp_int *y)
-{
-  mp_int   gx, xc, yc, u, v, A, B, C, D;
-  mp_int  *clean[9];
-  mp_err   res;
-  int      last = -1;
-
-  if(mp_cmp_z(b) == 0)
-    return MP_RANGE;
-
-  /* Initialize all these variables we need */
-  MP_CHECKOK( mp_init(&u, FLAG(a)) );
-  clean[++last] = &u;
-  MP_CHECKOK( mp_init(&v, FLAG(a)) );
-  clean[++last] = &v;
-  MP_CHECKOK( mp_init(&gx, FLAG(a)) );
-  clean[++last] = &gx;
-  MP_CHECKOK( mp_init(&A, FLAG(a)) );
-  clean[++last] = &A;
-  MP_CHECKOK( mp_init(&B, FLAG(a)) );
-  clean[++last] = &B;
-  MP_CHECKOK( mp_init(&C, FLAG(a)) );
-  clean[++last] = &C;
-  MP_CHECKOK( mp_init(&D, FLAG(a)) );
-  clean[++last] = &D;
-  MP_CHECKOK( mp_init_copy(&xc, a) );
-  clean[++last] = &xc;
-  mp_abs(&xc, &xc);
-  MP_CHECKOK( mp_init_copy(&yc, b) );
-  clean[++last] = &yc;
-  mp_abs(&yc, &yc);
-
-  mp_set(&gx, 1);
-
-  /* Divide by two until at least one of them is odd */
-  while(mp_iseven(&xc) && mp_iseven(&yc)) {
-    mp_size nx = mp_trailing_zeros(&xc);
-    mp_size ny = mp_trailing_zeros(&yc);
-    mp_size n  = MP_MIN(nx, ny);
-    s_mp_div_2d(&xc,n);
-    s_mp_div_2d(&yc,n);
-    MP_CHECKOK( s_mp_mul_2d(&gx,n) );
-  }
-
-  mp_copy(&xc, &u);
-  mp_copy(&yc, &v);
-  mp_set(&A, 1); mp_set(&D, 1);
-
-  /* Loop through binary GCD algorithm */
-  do {
-    while(mp_iseven(&u)) {
-      s_mp_div_2(&u);
-
-      if(mp_iseven(&A) && mp_iseven(&B)) {
-        s_mp_div_2(&A); s_mp_div_2(&B);
-      } else {
-        MP_CHECKOK( mp_add(&A, &yc, &A) );
-        s_mp_div_2(&A);
-        MP_CHECKOK( mp_sub(&B, &xc, &B) );
-        s_mp_div_2(&B);
-      }
-    }
-
-    while(mp_iseven(&v)) {
-      s_mp_div_2(&v);
-
-      if(mp_iseven(&C) && mp_iseven(&D)) {
-        s_mp_div_2(&C); s_mp_div_2(&D);
-      } else {
-        MP_CHECKOK( mp_add(&C, &yc, &C) );
-        s_mp_div_2(&C);
-        MP_CHECKOK( mp_sub(&D, &xc, &D) );
-        s_mp_div_2(&D);
-      }
-    }
-
-    if(mp_cmp(&u, &v) >= 0) {
-      MP_CHECKOK( mp_sub(&u, &v, &u) );
-      MP_CHECKOK( mp_sub(&A, &C, &A) );
-      MP_CHECKOK( mp_sub(&B, &D, &B) );
-    } else {
-      MP_CHECKOK( mp_sub(&v, &u, &v) );
-      MP_CHECKOK( mp_sub(&C, &A, &C) );
-      MP_CHECKOK( mp_sub(&D, &B, &D) );
-    }
-  } while (mp_cmp_z(&u) != 0);
-
-  /* copy results to output */
-  if(x)
-    MP_CHECKOK( mp_copy(&C, x) );
-
-  if(y)
-    MP_CHECKOK( mp_copy(&D, y) );
-
-  if(g)
-    MP_CHECKOK( mp_mul(&gx, &v, g) );
-
- CLEANUP:
-  while(last >= 0)
-    mp_clear(clean[last--]);
-
-  return res;
-
-} /* end mp_xgcd() */
-
-/* }}} */
-
-mp_size mp_trailing_zeros(const mp_int *mp)
-{
-  mp_digit d;
-  mp_size  n = 0;
-  int      ix;
-
-  if (!mp || !MP_DIGITS(mp) || !mp_cmp_z(mp))
-    return n;
-
-  for (ix = 0; !(d = MP_DIGIT(mp,ix)) && (ix < MP_USED(mp)); ++ix)
-    n += MP_DIGIT_BIT;
-  if (!d)
-    return 0;   /* shouldn't happen, but ... */
-#if !defined(MP_USE_UINT_DIGIT)
-  if (!(d & 0xffffffffU)) {
-    d >>= 32;
-    n  += 32;
-  }
-#endif
-  if (!(d & 0xffffU)) {
-    d >>= 16;
-    n  += 16;
-  }
-  if (!(d & 0xffU)) {
-    d >>= 8;
-    n  += 8;
-  }
-  if (!(d & 0xfU)) {
-    d >>= 4;
-    n  += 4;
-  }
-  if (!(d & 0x3U)) {
-    d >>= 2;
-    n  += 2;
-  }
-  if (!(d & 0x1U)) {
-    d >>= 1;
-    n  += 1;
-  }
-#if MP_ARGCHK == 2
-  assert(0 != (d & 1));
-#endif
-  return n;
-}
-
-/* Given a and prime p, computes c and k such that a*c == 2**k (mod p).
-** Returns k (positive) or error (negative).
-** This technique from the paper "Fast Modular Reciprocals" (unpublished)
-** by Richard Schroeppel (a.k.a. Captain Nemo).
-*/
-mp_err s_mp_almost_inverse(const mp_int *a, const mp_int *p, mp_int *c)
-{
-  mp_err res;
-  mp_err k    = 0;
-  mp_int d, f, g;
-
-  ARGCHK(a && p && c, MP_BADARG);
-
-  MP_DIGITS(&d) = 0;
-  MP_DIGITS(&f) = 0;
-  MP_DIGITS(&g) = 0;
-  MP_CHECKOK( mp_init(&d, FLAG(a)) );
-  MP_CHECKOK( mp_init_copy(&f, a) );    /* f = a */
-  MP_CHECKOK( mp_init_copy(&g, p) );    /* g = p */
-
-  mp_set(c, 1);
-  mp_zero(&d);
-
-  if (mp_cmp_z(&f) == 0) {
-    res = MP_UNDEF;
-  } else
-  for (;;) {
-    int diff_sign;
-    while (mp_iseven(&f)) {
-      mp_size n = mp_trailing_zeros(&f);
-      if (!n) {
-        res = MP_UNDEF;
-        goto CLEANUP;
-      }
-      s_mp_div_2d(&f, n);
-      MP_CHECKOK( s_mp_mul_2d(&d, n) );
-      k += n;
-    }
-    if (mp_cmp_d(&f, 1) == MP_EQ) {     /* f == 1 */
-      res = k;
-      break;
-    }
-    diff_sign = mp_cmp(&f, &g);
-    if (diff_sign < 0) {                /* f < g */
-      s_mp_exch(&f, &g);
-      s_mp_exch(c, &d);
-    } else if (diff_sign == 0) {                /* f == g */
-      res = MP_UNDEF;           /* a and p are not relatively prime */
-      break;
-    }
-    if ((MP_DIGIT(&f,0) % 4) == (MP_DIGIT(&g,0) % 4)) {
-      MP_CHECKOK( mp_sub(&f, &g, &f) ); /* f = f - g */
-      MP_CHECKOK( mp_sub(c,  &d,  c) ); /* c = c - d */
-    } else {
-      MP_CHECKOK( mp_add(&f, &g, &f) ); /* f = f + g */
-      MP_CHECKOK( mp_add(c,  &d,  c) ); /* c = c + d */
-    }
-  }
-  if (res >= 0) {
-    while (MP_SIGN(c) != MP_ZPOS) {
-      MP_CHECKOK( mp_add(c, p, c) );
-    }
-    res = k;
-  }
-
-CLEANUP:
-  mp_clear(&d);
-  mp_clear(&f);
-  mp_clear(&g);
-  return res;
-}
-
-/* Compute T = (P ** -1) mod MP_RADIX.  Also works for 16-bit mp_digits.
-** This technique from the paper "Fast Modular Reciprocals" (unpublished)
-** by Richard Schroeppel (a.k.a. Captain Nemo).
-*/
-mp_digit  s_mp_invmod_radix(mp_digit P)
-{
-  mp_digit T = P;
-  T *= 2 - (P * T);
-  T *= 2 - (P * T);
-  T *= 2 - (P * T);
-  T *= 2 - (P * T);
-#if !defined(MP_USE_UINT_DIGIT)
-  T *= 2 - (P * T);
-  T *= 2 - (P * T);
-#endif
-  return T;
-}
-
-/* Given c, k, and prime p, where a*c == 2**k (mod p),
-** Compute x = (a ** -1) mod p.  This is similar to Montgomery reduction.
-** This technique from the paper "Fast Modular Reciprocals" (unpublished)
-** by Richard Schroeppel (a.k.a. Captain Nemo).
-*/
-mp_err  s_mp_fixup_reciprocal(const mp_int *c, const mp_int *p, int k, mp_int *x)
-{
-  int      k_orig = k;
-  mp_digit r;
-  mp_size  ix;
-  mp_err   res;
-
-  if (mp_cmp_z(c) < 0) {                /* c < 0 */
-    MP_CHECKOK( mp_add(c, p, x) );      /* x = c + p */
-  } else {
-    MP_CHECKOK( mp_copy(c, x) );        /* x = c */
-  }
-
-  /* make sure x is large enough */
-  ix = MP_HOWMANY(k, MP_DIGIT_BIT) + MP_USED(p) + 1;
-  ix = MP_MAX(ix, MP_USED(x));
-  MP_CHECKOK( s_mp_pad(x, ix) );
-
-  r = 0 - s_mp_invmod_radix(MP_DIGIT(p,0));
-
-  for (ix = 0; k > 0; ix++) {
-    int      j = MP_MIN(k, MP_DIGIT_BIT);
-    mp_digit v = r * MP_DIGIT(x, ix);
-    if (j < MP_DIGIT_BIT) {
-      v &= ((mp_digit)1 << j) - 1;      /* v = v mod (2 ** j) */
-    }
-    s_mp_mul_d_add_offset(p, v, x, ix); /* x += p * v * (RADIX ** ix) */
-    k -= j;
-  }
-  s_mp_clamp(x);
-  s_mp_div_2d(x, k_orig);
-  res = MP_OKAY;
-
-CLEANUP:
-  return res;
-}
-
-/* compute mod inverse using Schroeppel's method, only if m is odd */
-mp_err s_mp_invmod_odd_m(const mp_int *a, const mp_int *m, mp_int *c)
-{
-  int k;
-  mp_err  res;
-  mp_int  x;
-
-  ARGCHK(a && m && c, MP_BADARG);
-
-  if(mp_cmp_z(a) == 0 || mp_cmp_z(m) == 0)
-    return MP_RANGE;
-  if (mp_iseven(m))
-    return MP_UNDEF;
-
-  MP_DIGITS(&x) = 0;
-
-  if (a == c) {
-    if ((res = mp_init_copy(&x, a)) != MP_OKAY)
-      return res;
-    if (a == m)
-      m = &x;
-    a = &x;
-  } else if (m == c) {
-    if ((res = mp_init_copy(&x, m)) != MP_OKAY)
-      return res;
-    m = &x;
-  } else {
-    MP_DIGITS(&x) = 0;
-  }
-
-  MP_CHECKOK( s_mp_almost_inverse(a, m, c) );
-  k = res;
-  MP_CHECKOK( s_mp_fixup_reciprocal(c, m, k, c) );
-CLEANUP:
-  mp_clear(&x);
-  return res;
-}
-
-/* Known good algorithm for computing modular inverse.  But slow. */
-mp_err mp_invmod_xgcd(const mp_int *a, const mp_int *m, mp_int *c)
-{
-  mp_int  g, x;
-  mp_err  res;
-
-  ARGCHK(a && m && c, MP_BADARG);
-
-  if(mp_cmp_z(a) == 0 || mp_cmp_z(m) == 0)
-    return MP_RANGE;
-
-  MP_DIGITS(&g) = 0;
-  MP_DIGITS(&x) = 0;
-  MP_CHECKOK( mp_init(&x, FLAG(a)) );
-  MP_CHECKOK( mp_init(&g, FLAG(a)) );
-
-  MP_CHECKOK( mp_xgcd(a, m, &g, &x, NULL) );
-
-  if (mp_cmp_d(&g, 1) != MP_EQ) {
-    res = MP_UNDEF;
-    goto CLEANUP;
-  }
-
-  res = mp_mod(&x, m, c);
-  SIGN(c) = SIGN(a);
-
-CLEANUP:
-  mp_clear(&x);
-  mp_clear(&g);
-
-  return res;
-}
-
-/* modular inverse where modulus is 2**k. */
-/* c = a**-1 mod 2**k */
-mp_err s_mp_invmod_2d(const mp_int *a, mp_size k, mp_int *c)
-{
-  mp_err res;
-  mp_size ix = k + 4;
-  mp_int t0, t1, val, tmp, two2k;
-
-  static const mp_digit d2 = 2;
-  static const mp_int two = { 0, MP_ZPOS, 1, 1, (mp_digit *)&d2 };
-
-  if (mp_iseven(a))
-    return MP_UNDEF;
-  if (k <= MP_DIGIT_BIT) {
-    mp_digit i = s_mp_invmod_radix(MP_DIGIT(a,0));
-    if (k < MP_DIGIT_BIT)
-      i &= ((mp_digit)1 << k) - (mp_digit)1;
-    mp_set(c, i);
-    return MP_OKAY;
-  }
-  MP_DIGITS(&t0) = 0;
-  MP_DIGITS(&t1) = 0;
-  MP_DIGITS(&val) = 0;
-  MP_DIGITS(&tmp) = 0;
-  MP_DIGITS(&two2k) = 0;
-  MP_CHECKOK( mp_init_copy(&val, a) );
-  s_mp_mod_2d(&val, k);
-  MP_CHECKOK( mp_init_copy(&t0, &val) );
-  MP_CHECKOK( mp_init_copy(&t1, &t0)  );
-  MP_CHECKOK( mp_init(&tmp, FLAG(a)) );
-  MP_CHECKOK( mp_init(&two2k, FLAG(a)) );
-  MP_CHECKOK( s_mp_2expt(&two2k, k) );
-  do {
-    MP_CHECKOK( mp_mul(&val, &t1, &tmp)  );
-    MP_CHECKOK( mp_sub(&two, &tmp, &tmp) );
-    MP_CHECKOK( mp_mul(&t1, &tmp, &t1)   );
-    s_mp_mod_2d(&t1, k);
-    while (MP_SIGN(&t1) != MP_ZPOS) {
-      MP_CHECKOK( mp_add(&t1, &two2k, &t1) );
-    }
-    if (mp_cmp(&t1, &t0) == MP_EQ)
-      break;
-    MP_CHECKOK( mp_copy(&t1, &t0) );
-  } while (--ix > 0);
-  if (!ix) {
-    res = MP_UNDEF;
-  } else {
-    mp_exch(c, &t1);
-  }
-
-CLEANUP:
-  mp_clear(&t0);
-  mp_clear(&t1);
-  mp_clear(&val);
-  mp_clear(&tmp);
-  mp_clear(&two2k);
-  return res;
-}
-
-mp_err s_mp_invmod_even_m(const mp_int *a, const mp_int *m, mp_int *c)
-{
-  mp_err res;
-  mp_size k;
-  mp_int oddFactor, evenFactor; /* factors of the modulus */
-  mp_int oddPart, evenPart;     /* parts to combine via CRT. */
-  mp_int C2, tmp1, tmp2;
-
-  /*static const mp_digit d1 = 1; */
-  /*static const mp_int one = { MP_ZPOS, 1, 1, (mp_digit *)&d1 }; */
-
-  if ((res = s_mp_ispow2(m)) >= 0) {
-    k = res;
-    return s_mp_invmod_2d(a, k, c);
-  }
-  MP_DIGITS(&oddFactor) = 0;
-  MP_DIGITS(&evenFactor) = 0;
-  MP_DIGITS(&oddPart) = 0;
-  MP_DIGITS(&evenPart) = 0;
-  MP_DIGITS(&C2)     = 0;
-  MP_DIGITS(&tmp1)   = 0;
-  MP_DIGITS(&tmp2)   = 0;
-
-  MP_CHECKOK( mp_init_copy(&oddFactor, m) );    /* oddFactor = m */
-  MP_CHECKOK( mp_init(&evenFactor, FLAG(m)) );
-  MP_CHECKOK( mp_init(&oddPart, FLAG(m)) );
-  MP_CHECKOK( mp_init(&evenPart, FLAG(m)) );
-  MP_CHECKOK( mp_init(&C2, FLAG(m))     );
-  MP_CHECKOK( mp_init(&tmp1, FLAG(m))   );
-  MP_CHECKOK( mp_init(&tmp2, FLAG(m))   );
-
-  k = mp_trailing_zeros(m);
-  s_mp_div_2d(&oddFactor, k);
-  MP_CHECKOK( s_mp_2expt(&evenFactor, k) );
-
-  /* compute a**-1 mod oddFactor. */
-  MP_CHECKOK( s_mp_invmod_odd_m(a, &oddFactor, &oddPart) );
-  /* compute a**-1 mod evenFactor, where evenFactor == 2**k. */
-  MP_CHECKOK( s_mp_invmod_2d(   a,       k,    &evenPart) );
-
-  /* Use Chinese Remainer theorem to compute a**-1 mod m. */
-  /* let m1 = oddFactor,  v1 = oddPart,
-   * let m2 = evenFactor, v2 = evenPart.
-   */
-
-  /* Compute C2 = m1**-1 mod m2. */
-  MP_CHECKOK( s_mp_invmod_2d(&oddFactor, k,    &C2) );
-
-  /* compute u = (v2 - v1)*C2 mod m2 */
-  MP_CHECKOK( mp_sub(&evenPart, &oddPart,   &tmp1) );
-  MP_CHECKOK( mp_mul(&tmp1,     &C2,        &tmp2) );
-  s_mp_mod_2d(&tmp2, k);
-  while (MP_SIGN(&tmp2) != MP_ZPOS) {
-    MP_CHECKOK( mp_add(&tmp2, &evenFactor, &tmp2) );
-  }
-
-  /* compute answer = v1 + u*m1 */
-  MP_CHECKOK( mp_mul(&tmp2,     &oddFactor, c) );
-  MP_CHECKOK( mp_add(&oddPart,  c,          c) );
-  /* not sure this is necessary, but it's low cost if not. */
-  MP_CHECKOK( mp_mod(c,         m,          c) );
-
-CLEANUP:
-  mp_clear(&oddFactor);
-  mp_clear(&evenFactor);
-  mp_clear(&oddPart);
-  mp_clear(&evenPart);
-  mp_clear(&C2);
-  mp_clear(&tmp1);
-  mp_clear(&tmp2);
-  return res;
-}
-
-
-/* {{{ mp_invmod(a, m, c) */
-
-/*
-  mp_invmod(a, m, c)
-
-  Compute c = a^-1 (mod m), if there is an inverse for a (mod m).
-  This is equivalent to the question of whether (a, m) = 1.  If not,
-  MP_UNDEF is returned, and there is no inverse.
- */
-
-mp_err mp_invmod(const mp_int *a, const mp_int *m, mp_int *c)
-{
-
-  ARGCHK(a && m && c, MP_BADARG);
-
-  if(mp_cmp_z(a) == 0 || mp_cmp_z(m) == 0)
-    return MP_RANGE;
-
-  if (mp_isodd(m)) {
-    return s_mp_invmod_odd_m(a, m, c);
-  }
-  if (mp_iseven(a))
-    return MP_UNDEF;    /* not invertable */
-
-  return s_mp_invmod_even_m(a, m, c);
-
-} /* end mp_invmod() */
-
-/* }}} */
-#endif /* if MP_NUMTH */
-
-/* }}} */
-
-/*------------------------------------------------------------------------*/
-/* {{{ mp_print(mp, ofp) */
-
-#if MP_IOFUNC
-/*
-  mp_print(mp, ofp)
-
-  Print a textual representation of the given mp_int on the output
-  stream 'ofp'.  Output is generated using the internal radix.
- */
-
-void   mp_print(mp_int *mp, FILE *ofp)
-{
-  int   ix;
-
-  if(mp == NULL || ofp == NULL)
-    return;
-
-  fputc((SIGN(mp) == NEG) ? '-' : '+', ofp);
-
-  for(ix = USED(mp) - 1; ix >= 0; ix--) {
-    fprintf(ofp, DIGIT_FMT, DIGIT(mp, ix));
-  }
-
-} /* end mp_print() */
-
-#endif /* if MP_IOFUNC */
-
-/* }}} */
-
-/*------------------------------------------------------------------------*/
-/* {{{ More I/O Functions */
-
-/* {{{ mp_read_raw(mp, str, len) */
-
-/*
-   mp_read_raw(mp, str, len)
-
-   Read in a raw value (base 256) into the given mp_int
- */
-
-mp_err  mp_read_raw(mp_int *mp, char *str, int len)
-{
-  int            ix;
-  mp_err         res;
-  unsigned char *ustr = (unsigned char *)str;
-
-  ARGCHK(mp != NULL && str != NULL && len > 0, MP_BADARG);
-
-  mp_zero(mp);
-
-  /* Get sign from first byte */
-  if(ustr[0])
-    SIGN(mp) = NEG;
-  else
-    SIGN(mp) = ZPOS;
-
-  /* Read the rest of the digits */
-  for(ix = 1; ix < len; ix++) {
-    if((res = mp_mul_d(mp, 256, mp)) != MP_OKAY)
-      return res;
-    if((res = mp_add_d(mp, ustr[ix], mp)) != MP_OKAY)
-      return res;
-  }
-
-  return MP_OKAY;
-
-} /* end mp_read_raw() */
-
-/* }}} */
-
-/* {{{ mp_raw_size(mp) */
-
-int    mp_raw_size(mp_int *mp)
-{
-  ARGCHK(mp != NULL, 0);
-
-  return (USED(mp) * sizeof(mp_digit)) + 1;
-
-} /* end mp_raw_size() */
-
-/* }}} */
-
-/* {{{ mp_toraw(mp, str) */
-
-mp_err mp_toraw(mp_int *mp, char *str)
-{
-  int  ix, jx, pos = 1;
-
-  ARGCHK(mp != NULL && str != NULL, MP_BADARG);
-
-  str[0] = (char)SIGN(mp);
-
-  /* Iterate over each digit... */
-  for(ix = USED(mp) - 1; ix >= 0; ix--) {
-    mp_digit  d = DIGIT(mp, ix);
-
-    /* Unpack digit bytes, high order first */
-    for(jx = sizeof(mp_digit) - 1; jx >= 0; jx--) {
-      str[pos++] = (char)(d >> (jx * CHAR_BIT));
-    }
-  }
-
-  return MP_OKAY;
-
-} /* end mp_toraw() */
-
-/* }}} */
-
-/* {{{ mp_read_radix(mp, str, radix) */
-
-/*
-  mp_read_radix(mp, str, radix)
-
-  Read an integer from the given string, and set mp to the resulting
-  value.  The input is presumed to be in base 10.  Leading non-digit
-  characters are ignored, and the function reads until a non-digit
-  character or the end of the string.
- */
-
-mp_err  mp_read_radix(mp_int *mp, const char *str, int radix)
-{
-  int     ix = 0, val = 0;
-  mp_err  res;
-  mp_sign sig = ZPOS;
-
-  ARGCHK(mp != NULL && str != NULL && radix >= 2 && radix <= MAX_RADIX,
-         MP_BADARG);
-
-  mp_zero(mp);
-
-  /* Skip leading non-digit characters until a digit or '-' or '+' */
-  while(str[ix] &&
-        (s_mp_tovalue(str[ix], radix) < 0) &&
-        str[ix] != '-' &&
-        str[ix] != '+') {
-    ++ix;
-  }
-
-  if(str[ix] == '-') {
-    sig = NEG;
-    ++ix;
-  } else if(str[ix] == '+') {
-    sig = ZPOS; /* this is the default anyway... */
-    ++ix;
-  }
-
-  while((val = s_mp_tovalue(str[ix], radix)) >= 0) {
-    if((res = s_mp_mul_d(mp, radix)) != MP_OKAY)
-      return res;
-    if((res = s_mp_add_d(mp, val)) != MP_OKAY)
-      return res;
-    ++ix;
-  }
-
-  if(s_mp_cmp_d(mp, 0) == MP_EQ)
-    SIGN(mp) = ZPOS;
-  else
-    SIGN(mp) = sig;
-
-  return MP_OKAY;
-
-} /* end mp_read_radix() */
-
-mp_err mp_read_variable_radix(mp_int *a, const char * str, int default_radix)
-{
-  int     radix = default_radix;
-  int     cx;
-  mp_sign sig   = ZPOS;
-  mp_err  res;
-
-  /* Skip leading non-digit characters until a digit or '-' or '+' */
-  while ((cx = *str) != 0 &&
-        (s_mp_tovalue(cx, radix) < 0) &&
-        cx != '-' &&
-        cx != '+') {
-    ++str;
-  }
-
-  if (cx == '-') {
-    sig = NEG;
-    ++str;
-  } else if (cx == '+') {
-    sig = ZPOS; /* this is the default anyway... */
-    ++str;
-  }
-
-  if (str[0] == '0') {
-    if ((str[1] | 0x20) == 'x') {
-      radix = 16;
-      str += 2;
-    } else {
-      radix = 8;
-      str++;
-    }
-  }
-  res = mp_read_radix(a, str, radix);
-  if (res == MP_OKAY) {
-    MP_SIGN(a) = (s_mp_cmp_d(a, 0) == MP_EQ) ? ZPOS : sig;
-  }
-  return res;
-}
-
-/* }}} */
-
-/* {{{ mp_radix_size(mp, radix) */
-
-int    mp_radix_size(mp_int *mp, int radix)
-{
-  int  bits;
-
-  if(!mp || radix < 2 || radix > MAX_RADIX)
-    return 0;
-
-  bits = USED(mp) * DIGIT_BIT - 1;
-
-  return s_mp_outlen(bits, radix);
-
-} /* end mp_radix_size() */
-
-/* }}} */
-
-/* {{{ mp_toradix(mp, str, radix) */
-
-mp_err mp_toradix(mp_int *mp, char *str, int radix)
-{
-  int  ix, pos = 0;
-
-  ARGCHK(mp != NULL && str != NULL, MP_BADARG);
-  ARGCHK(radix > 1 && radix <= MAX_RADIX, MP_RANGE);
-
-  if(mp_cmp_z(mp) == MP_EQ) {
-    str[0] = '0';
-    str[1] = '\0';
-  } else {
-    mp_err   res;
-    mp_int   tmp;
-    mp_sign  sgn;
-    mp_digit rem, rdx = (mp_digit)radix;
-    char     ch;
-
-    if((res = mp_init_copy(&tmp, mp)) != MP_OKAY)
-      return res;
-
-    /* Save sign for later, and take absolute value */
-    sgn = SIGN(&tmp); SIGN(&tmp) = ZPOS;
-
-    /* Generate output digits in reverse order      */
-    while(mp_cmp_z(&tmp) != 0) {
-      if((res = mp_div_d(&tmp, rdx, &tmp, &rem)) != MP_OKAY) {
-        mp_clear(&tmp);
-        return res;
-      }
-
-      /* Generate digits, use capital letters */
-      ch = s_mp_todigit(rem, radix, 0);
-
-      str[pos++] = ch;
-    }
-
-    /* Add - sign if original value was negative */
-    if(sgn == NEG)
-      str[pos++] = '-';
-
-    /* Add trailing NUL to end the string        */
-    str[pos--] = '\0';
-
-    /* Reverse the digits and sign indicator     */
-    ix = 0;
-    while(ix < pos) {
-      char tmp = str[ix];
-
-      str[ix] = str[pos];
-      str[pos] = tmp;
-      ++ix;
-      --pos;
-    }
-
-    mp_clear(&tmp);
-  }
-
-  return MP_OKAY;
-
-} /* end mp_toradix() */
-
-/* }}} */
-
-/* {{{ mp_tovalue(ch, r) */
-
-int    mp_tovalue(char ch, int r)
-{
-  return s_mp_tovalue(ch, r);
-
-} /* end mp_tovalue() */
-
-/* }}} */
-
-/* }}} */
-
-/* {{{ mp_strerror(ec) */
-
-/*
-  mp_strerror(ec)
-
-  Return a string describing the meaning of error code 'ec'.  The
-  string returned is allocated in static memory, so the caller should
-  not attempt to modify or free the memory associated with this
-  string.
- */
-const char  *mp_strerror(mp_err ec)
-{
-  int   aec = (ec < 0) ? -ec : ec;
-
-  /* Code values are negative, so the senses of these comparisons
-     are accurate */
-  if(ec < MP_LAST_CODE || ec > MP_OKAY) {
-    return mp_err_string[0];  /* unknown error code */
-  } else {
-    return mp_err_string[aec + 1];
-  }
-
-} /* end mp_strerror() */
-
-/* }}} */
-
-/*========================================================================*/
-/*------------------------------------------------------------------------*/
-/* Static function definitions (internal use only)                        */
-
-/* {{{ Memory management */
-
-/* {{{ s_mp_grow(mp, min) */
-
-/* Make sure there are at least 'min' digits allocated to mp              */
-mp_err   s_mp_grow(mp_int *mp, mp_size min)
-{
-  if(min > ALLOC(mp)) {
-    mp_digit   *tmp;
-
-    /* Set min to next nearest default precision block size */
-    min = MP_ROUNDUP(min, s_mp_defprec);
-
-    if((tmp = s_mp_alloc(min, sizeof(mp_digit), FLAG(mp))) == NULL)
-      return MP_MEM;
-
-    s_mp_copy(DIGITS(mp), tmp, USED(mp));
-
-#if MP_CRYPTO
-    s_mp_setz(DIGITS(mp), ALLOC(mp));
-#endif
-    s_mp_free(DIGITS(mp), ALLOC(mp));
-    DIGITS(mp) = tmp;
-    ALLOC(mp) = min;
-  }
-
-  return MP_OKAY;
-
-} /* end s_mp_grow() */
-
-/* }}} */
-
-/* {{{ s_mp_pad(mp, min) */
-
-/* Make sure the used size of mp is at least 'min', growing if needed     */
-mp_err   s_mp_pad(mp_int *mp, mp_size min)
-{
-  if(min > USED(mp)) {
-    mp_err  res;
-
-    /* Make sure there is room to increase precision  */
-    if (min > ALLOC(mp)) {
-      if ((res = s_mp_grow(mp, min)) != MP_OKAY)
-        return res;
-    } else {
-      s_mp_setz(DIGITS(mp) + USED(mp), min - USED(mp));
-    }
-
-    /* Increase precision; should already be 0-filled */
-    USED(mp) = min;
-  }
-
-  return MP_OKAY;
-
-} /* end s_mp_pad() */
-
-/* }}} */
-
-/* {{{ s_mp_setz(dp, count) */
-
-#if MP_MACRO == 0
-/* Set 'count' digits pointed to by dp to be zeroes                       */
-void s_mp_setz(mp_digit *dp, mp_size count)
-{
-#if MP_MEMSET == 0
-  int  ix;
-
-  for(ix = 0; ix < count; ix++)
-    dp[ix] = 0;
-#else
-  memset(dp, 0, count * sizeof(mp_digit));
-#endif
-
-} /* end s_mp_setz() */
-#endif
-
-/* }}} */
-
-/* {{{ s_mp_copy(sp, dp, count) */
-
-#if MP_MACRO == 0
-/* Copy 'count' digits from sp to dp                                      */
-void s_mp_copy(const mp_digit *sp, mp_digit *dp, mp_size count)
-{
-#if MP_MEMCPY == 0
-  int  ix;
-
-  for(ix = 0; ix < count; ix++)
-    dp[ix] = sp[ix];
-#else
-  memcpy(dp, sp, count * sizeof(mp_digit));
-#endif
-
-} /* end s_mp_copy() */
-#endif
-
-/* }}} */
-
-/* {{{ s_mp_alloc(nb, ni, kmflag) */
-
-#if MP_MACRO == 0
-/* Allocate ni records of nb bytes each, and return a pointer to that     */
-void    *s_mp_alloc(size_t nb, size_t ni, int kmflag)
-{
-  mp_int *mp;
-  ++mp_allocs;
-#ifdef _KERNEL
-  mp = kmem_zalloc(nb * ni, kmflag);
-  if (mp != NULL)
-    FLAG(mp) = kmflag;
-  return (mp);
-#else
-  return calloc(nb, ni);
-#endif
-
-} /* end s_mp_alloc() */
-#endif
-
-/* }}} */
-
-/* {{{ s_mp_free(ptr) */
-
-#if MP_MACRO == 0
-/* Free the memory pointed to by ptr                                      */
-void     s_mp_free(void *ptr, mp_size alloc)
-{
-  if(ptr) {
-    ++mp_frees;
-#ifdef _KERNEL
-    kmem_free(ptr, alloc * sizeof (mp_digit));
-#else
-    free(ptr);
-#endif
-  }
-} /* end s_mp_free() */
-#endif
-
-/* }}} */
-
-/* {{{ s_mp_clamp(mp) */
-
-#if MP_MACRO == 0
-/* Remove leading zeroes from the given value                             */
-void     s_mp_clamp(mp_int *mp)
-{
-  mp_size used = MP_USED(mp);
-  while (used > 1 && DIGIT(mp, used - 1) == 0)
-    --used;
-  MP_USED(mp) = used;
-} /* end s_mp_clamp() */
-#endif
-
-/* }}} */
-
-/* {{{ s_mp_exch(a, b) */
-
-/* Exchange the data for a and b; (b, a) = (a, b)                         */
-void     s_mp_exch(mp_int *a, mp_int *b)
-{
-  mp_int   tmp;
-
-  tmp = *a;
-  *a = *b;
-  *b = tmp;
-
-} /* end s_mp_exch() */
-
-/* }}} */
-
-/* }}} */
-
-/* {{{ Arithmetic helpers */
-
-/* {{{ s_mp_lshd(mp, p) */
-
-/*
-   Shift mp leftward by p digits, growing if needed, and zero-filling
-   the in-shifted digits at the right end.  This is a convenient
-   alternative to multiplication by powers of the radix
-   The value of USED(mp) must already have been set to the value for
-   the shifted result.
- */
-
-mp_err   s_mp_lshd(mp_int *mp, mp_size p)
-{
-  mp_err  res;
-  mp_size pos;
-  int     ix;
-
-  if(p == 0)
-    return MP_OKAY;
-
-  if (MP_USED(mp) == 1 && MP_DIGIT(mp, 0) == 0)
-    return MP_OKAY;
-
-  if((res = s_mp_pad(mp, USED(mp) + p)) != MP_OKAY)
-    return res;
-
-  pos = USED(mp) - 1;
-
-  /* Shift all the significant figures over as needed */
-  for(ix = pos - p; ix >= 0; ix--)
-    DIGIT(mp, ix + p) = DIGIT(mp, ix);
-
-  /* Fill the bottom digits with zeroes */
-  for(ix = 0; ix < p; ix++)
-    DIGIT(mp, ix) = 0;
-
-  return MP_OKAY;
-
-} /* end s_mp_lshd() */
-
-/* }}} */
-
-/* {{{ s_mp_mul_2d(mp, d) */
-
-/*
-  Multiply the integer by 2^d, where d is a number of bits.  This
-  amounts to a bitwise shift of the value.
- */
-mp_err   s_mp_mul_2d(mp_int *mp, mp_digit d)
-{
-  mp_err   res;
-  mp_digit dshift, bshift;
-  mp_digit mask;
-
-  ARGCHK(mp != NULL,  MP_BADARG);
-
-  dshift = d / MP_DIGIT_BIT;
-  bshift = d % MP_DIGIT_BIT;
-  /* bits to be shifted out of the top word */
-  mask   = ((mp_digit)~0 << (MP_DIGIT_BIT - bshift));
-  mask  &= MP_DIGIT(mp, MP_USED(mp) - 1);
-
-  if (MP_OKAY != (res = s_mp_pad(mp, MP_USED(mp) + dshift + (mask != 0) )))
-    return res;
-
-  if (dshift && MP_OKAY != (res = s_mp_lshd(mp, dshift)))
-    return res;
-
-  if (bshift) {
-    mp_digit *pa = MP_DIGITS(mp);
-    mp_digit *alim = pa + MP_USED(mp);
-    mp_digit  prev = 0;
-
-    for (pa += dshift; pa < alim; ) {
-      mp_digit x = *pa;
-      *pa++ = (x << bshift) | prev;
-      prev = x >> (DIGIT_BIT - bshift);
-    }
-  }
-
-  s_mp_clamp(mp);
-  return MP_OKAY;
-} /* end s_mp_mul_2d() */
-
-/* {{{ s_mp_rshd(mp, p) */
-
-/*
-   Shift mp rightward by p digits.  Maintains the invariant that
-   digits above the precision are all zero.  Digits shifted off the
-   end are lost.  Cannot fail.
- */
-
-void     s_mp_rshd(mp_int *mp, mp_size p)
-{
-  mp_size  ix;
-  mp_digit *src, *dst;
-
-  if(p == 0)
-    return;
-
-  /* Shortcut when all digits are to be shifted off */
-  if(p >= USED(mp)) {
-    s_mp_setz(DIGITS(mp), ALLOC(mp));
-    USED(mp) = 1;
-    SIGN(mp) = ZPOS;
-    return;
-  }
-
-  /* Shift all the significant figures over as needed */
-  dst = MP_DIGITS(mp);
-  src = dst + p;
-  for (ix = USED(mp) - p; ix > 0; ix--)
-    *dst++ = *src++;
-
-  MP_USED(mp) -= p;
-  /* Fill the top digits with zeroes */
-  while (p-- > 0)
-    *dst++ = 0;
-
-#if 0
-  /* Strip off any leading zeroes    */
-  s_mp_clamp(mp);
-#endif
-
-} /* end s_mp_rshd() */
-
-/* }}} */
-
-/* {{{ s_mp_div_2(mp) */
-
-/* Divide by two -- take advantage of radix properties to do it fast      */
-void     s_mp_div_2(mp_int *mp)
-{
-  s_mp_div_2d(mp, 1);
-
-} /* end s_mp_div_2() */
-
-/* }}} */
-
-/* {{{ s_mp_mul_2(mp) */
-
-mp_err s_mp_mul_2(mp_int *mp)
-{
-  mp_digit *pd;
-  int      ix, used;
-  mp_digit kin = 0;
-
-  /* Shift digits leftward by 1 bit */
-  used = MP_USED(mp);
-  pd = MP_DIGITS(mp);
-  for (ix = 0; ix < used; ix++) {
-    mp_digit d = *pd;
-    *pd++ = (d << 1) | kin;
-    kin = (d >> (DIGIT_BIT - 1));
-  }
-
-  /* Deal with rollover from last digit */
-  if (kin) {
-    if (ix >= ALLOC(mp)) {
-      mp_err res;
-      if((res = s_mp_grow(mp, ALLOC(mp) + 1)) != MP_OKAY)
-        return res;
-    }
-
-    DIGIT(mp, ix) = kin;
-    USED(mp) += 1;
-  }
-
-  return MP_OKAY;
-
-} /* end s_mp_mul_2() */
-
-/* }}} */
-
-/* {{{ s_mp_mod_2d(mp, d) */
-
-/*
-  Remainder the integer by 2^d, where d is a number of bits.  This
-  amounts to a bitwise AND of the value, and does not require the full
-  division code
- */
-void     s_mp_mod_2d(mp_int *mp, mp_digit d)
-{
-  mp_size  ndig = (d / DIGIT_BIT), nbit = (d % DIGIT_BIT);
-  mp_size  ix;
-  mp_digit dmask;
-
-  if(ndig >= USED(mp))
-    return;
-
-  /* Flush all the bits above 2^d in its digit */
-  dmask = ((mp_digit)1 << nbit) - 1;
-  DIGIT(mp, ndig) &= dmask;
-
-  /* Flush all digits above the one with 2^d in it */
-  for(ix = ndig + 1; ix < USED(mp); ix++)
-    DIGIT(mp, ix) = 0;
-
-  s_mp_clamp(mp);
-
-} /* end s_mp_mod_2d() */
-
-/* }}} */
-
-/* {{{ s_mp_div_2d(mp, d) */
-
-/*
-  Divide the integer by 2^d, where d is a number of bits.  This
-  amounts to a bitwise shift of the value, and does not require the
-  full division code (used in Barrett reduction, see below)
- */
-void     s_mp_div_2d(mp_int *mp, mp_digit d)
-{
-  int       ix;
-  mp_digit  save, next, mask;
-
-  s_mp_rshd(mp, d / DIGIT_BIT);
-  d %= DIGIT_BIT;
-  if (d) {
-    mask = ((mp_digit)1 << d) - 1;
-    save = 0;
-    for(ix = USED(mp) - 1; ix >= 0; ix--) {
-      next = DIGIT(mp, ix) & mask;
-      DIGIT(mp, ix) = (DIGIT(mp, ix) >> d) | (save << (DIGIT_BIT - d));
-      save = next;
-    }
-  }
-  s_mp_clamp(mp);
-
-} /* end s_mp_div_2d() */
-
-/* }}} */
-
-/* {{{ s_mp_norm(a, b, *d) */
-
-/*
-  s_mp_norm(a, b, *d)
-
-  Normalize a and b for division, where b is the divisor.  In order
-  that we might make good guesses for quotient digits, we want the
-  leading digit of b to be at least half the radix, which we
-  accomplish by multiplying a and b by a power of 2.  The exponent
-  (shift count) is placed in *pd, so that the remainder can be shifted
-  back at the end of the division process.
- */
-
-mp_err   s_mp_norm(mp_int *a, mp_int *b, mp_digit *pd)
-{
-  mp_digit  d;
-  mp_digit  mask;
-  mp_digit  b_msd;
-  mp_err    res    = MP_OKAY;
-
-  d = 0;
-  mask  = DIGIT_MAX & ~(DIGIT_MAX >> 1);        /* mask is msb of digit */
-  b_msd = DIGIT(b, USED(b) - 1);
-  while (!(b_msd & mask)) {
-    b_msd <<= 1;
-    ++d;
-  }
-
-  if (d) {
-    MP_CHECKOK( s_mp_mul_2d(a, d) );
-    MP_CHECKOK( s_mp_mul_2d(b, d) );
-  }
-
-  *pd = d;
-CLEANUP:
-  return res;
-
-} /* end s_mp_norm() */
-
-/* }}} */
-
-/* }}} */
-
-/* {{{ Primitive digit arithmetic */
-
-/* {{{ s_mp_add_d(mp, d) */
-
-/* Add d to |mp| in place                                                 */
-mp_err   s_mp_add_d(mp_int *mp, mp_digit d)    /* unsigned digit addition */
-{
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD)
-  mp_word   w, k = 0;
-  mp_size   ix = 1;
-
-  w = (mp_word)DIGIT(mp, 0) + d;
-  DIGIT(mp, 0) = ACCUM(w);
-  k = CARRYOUT(w);
-
-  while(ix < USED(mp) && k) {
-    w = (mp_word)DIGIT(mp, ix) + k;
-    DIGIT(mp, ix) = ACCUM(w);
-    k = CARRYOUT(w);
-    ++ix;
-  }
-
-  if(k != 0) {
-    mp_err  res;
-
-    if((res = s_mp_pad(mp, USED(mp) + 1)) != MP_OKAY)
-      return res;
-
-    DIGIT(mp, ix) = (mp_digit)k;
-  }
-
-  return MP_OKAY;
-#else
-  mp_digit * pmp = MP_DIGITS(mp);
-  mp_digit sum, mp_i, carry = 0;
-  mp_err   res = MP_OKAY;
-  int used = (int)MP_USED(mp);
-
-  mp_i = *pmp;
-  *pmp++ = sum = d + mp_i;
-  carry = (sum < d);
-  while (carry && --used > 0) {
-    mp_i = *pmp;
-    *pmp++ = sum = carry + mp_i;
-    carry = !sum;
-  }
-  if (carry && !used) {
-    /* mp is growing */
-    used = MP_USED(mp);
-    MP_CHECKOK( s_mp_pad(mp, used + 1) );
-    MP_DIGIT(mp, used) = carry;
-  }
-CLEANUP:
-  return res;
-#endif
-} /* end s_mp_add_d() */
-
-/* }}} */
-
-/* {{{ s_mp_sub_d(mp, d) */
-
-/* Subtract d from |mp| in place, assumes |mp| > d                        */
-mp_err   s_mp_sub_d(mp_int *mp, mp_digit d)    /* unsigned digit subtract */
-{
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_SUB_WORD)
-  mp_word   w, b = 0;
-  mp_size   ix = 1;
-
-  /* Compute initial subtraction    */
-  w = (RADIX + (mp_word)DIGIT(mp, 0)) - d;
-  b = CARRYOUT(w) ? 0 : 1;
-  DIGIT(mp, 0) = ACCUM(w);
-
-  /* Propagate borrows leftward     */
-  while(b && ix < USED(mp)) {
-    w = (RADIX + (mp_word)DIGIT(mp, ix)) - b;
-    b = CARRYOUT(w) ? 0 : 1;
-    DIGIT(mp, ix) = ACCUM(w);
-    ++ix;
-  }
-
-  /* Remove leading zeroes          */
-  s_mp_clamp(mp);
-
-  /* If we have a borrow out, it's a violation of the input invariant */
-  if(b)
-    return MP_RANGE;
-  else
-    return MP_OKAY;
-#else
-  mp_digit *pmp = MP_DIGITS(mp);
-  mp_digit mp_i, diff, borrow;
-  mp_size  used = MP_USED(mp);
-
-  mp_i = *pmp;
-  *pmp++ = diff = mp_i - d;
-  borrow = (diff > mp_i);
-  while (borrow && --used) {
-    mp_i = *pmp;
-    *pmp++ = diff = mp_i - borrow;
-    borrow = (diff > mp_i);
-  }
-  s_mp_clamp(mp);
-  return (borrow && !used) ? MP_RANGE : MP_OKAY;
-#endif
-} /* end s_mp_sub_d() */
-
-/* }}} */
-
-/* {{{ s_mp_mul_d(a, d) */
-
-/* Compute a = a * d, single digit multiplication                         */
-mp_err   s_mp_mul_d(mp_int *a, mp_digit d)
-{
-  mp_err  res;
-  mp_size used;
-  int     pow;
-
-  if (!d) {
-    mp_zero(a);
-    return MP_OKAY;
-  }
-  if (d == 1)
-    return MP_OKAY;
-  if (0 <= (pow = s_mp_ispow2d(d))) {
-    return s_mp_mul_2d(a, (mp_digit)pow);
-  }
-
-  used = MP_USED(a);
-  MP_CHECKOK( s_mp_pad(a, used + 1) );
-
-  s_mpv_mul_d(MP_DIGITS(a), used, d, MP_DIGITS(a));
-
-  s_mp_clamp(a);
-
-CLEANUP:
-  return res;
-
-} /* end s_mp_mul_d() */
-
-/* }}} */
-
-/* {{{ s_mp_div_d(mp, d, r) */
-
-/*
-  s_mp_div_d(mp, d, r)
-
-  Compute the quotient mp = mp / d and remainder r = mp mod d, for a
-  single digit d.  If r is null, the remainder will be discarded.
- */
-
-mp_err   s_mp_div_d(mp_int *mp, mp_digit d, mp_digit *r)
-{
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_DIV_WORD)
-  mp_word   w = 0, q;
-#else
-  mp_digit  w, q;
-#endif
-  int       ix;
-  mp_err    res;
-  mp_int    quot;
-  mp_int    rem;
-
-  if(d == 0)
-    return MP_RANGE;
-  if (d == 1) {
-    if (r)
-      *r = 0;
-    return MP_OKAY;
-  }
-  /* could check for power of 2 here, but mp_div_d does that. */
-  if (MP_USED(mp) == 1) {
-    mp_digit n   = MP_DIGIT(mp,0);
-    mp_digit rem;
-
-    q   = n / d;
-    rem = n % d;
-    MP_DIGIT(mp,0) = q;
-    if (r)
-      *r = rem;
-    return MP_OKAY;
-  }
-
-  MP_DIGITS(&rem)  = 0;
-  MP_DIGITS(&quot) = 0;
-  /* Make room for the quotient */
-  MP_CHECKOK( mp_init_size(&quot, USED(mp), FLAG(mp)) );
-
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_DIV_WORD)
-  for(ix = USED(mp) - 1; ix >= 0; ix--) {
-    w = (w << DIGIT_BIT) | DIGIT(mp, ix);
-
-    if(w >= d) {
-      q = w / d;
-      w = w % d;
-    } else {
-      q = 0;
-    }
-
-    s_mp_lshd(&quot, 1);
-    DIGIT(&quot, 0) = (mp_digit)q;
-  }
-#else
-  {
-    mp_digit p;
-#if !defined(MP_ASSEMBLY_DIV_2DX1D)
-    mp_digit norm;
-#endif
-
-    MP_CHECKOK( mp_init_copy(&rem, mp) );
-
-#if !defined(MP_ASSEMBLY_DIV_2DX1D)
-    MP_DIGIT(&quot, 0) = d;
-    MP_CHECKOK( s_mp_norm(&rem, &quot, &norm) );
-    if (norm)
-      d <<= norm;
-    MP_DIGIT(&quot, 0) = 0;
-#endif
-
-    p = 0;
-    for (ix = USED(&rem) - 1; ix >= 0; ix--) {
-      w = DIGIT(&rem, ix);
-
-      if (p) {
-        MP_CHECKOK( s_mpv_div_2dx1d(p, w, d, &q, &w) );
-      } else if (w >= d) {
-        q = w / d;
-        w = w % d;
-      } else {
-        q = 0;
-      }
-
-      MP_CHECKOK( s_mp_lshd(&quot, 1) );
-      DIGIT(&quot, 0) = q;
-      p = w;
-    }
-#if !defined(MP_ASSEMBLY_DIV_2DX1D)
-    if (norm)
-      w >>= norm;
-#endif
-  }
-#endif
-
-  /* Deliver the remainder, if desired */
-  if(r)
-    *r = (mp_digit)w;
-
-  s_mp_clamp(&quot);
-  mp_exch(&quot, mp);
-CLEANUP:
-  mp_clear(&quot);
-  mp_clear(&rem);
-
-  return res;
-} /* end s_mp_div_d() */
-
-/* }}} */
-
-
-/* }}} */
-
-/* {{{ Primitive full arithmetic */
-
-/* {{{ s_mp_add(a, b) */
-
-/* Compute a = |a| + |b|                                                  */
-mp_err   s_mp_add(mp_int *a, const mp_int *b)  /* magnitude addition      */
-{
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD)
-  mp_word   w = 0;
-#else
-  mp_digit  d, sum, carry = 0;
-#endif
-  mp_digit *pa, *pb;
-  mp_size   ix;
-  mp_size   used;
-  mp_err    res;
-
-  /* Make sure a has enough precision for the output value */
-  if((USED(b) > USED(a)) && (res = s_mp_pad(a, USED(b))) != MP_OKAY)
-    return res;
-
-  /*
-    Add up all digits up to the precision of b.  If b had initially
-    the same precision as a, or greater, we took care of it by the
-    padding step above, so there is no problem.  If b had initially
-    less precision, we'll have to make sure the carry out is duly
-    propagated upward among the higher-order digits of the sum.
-   */
-  pa = MP_DIGITS(a);
-  pb = MP_DIGITS(b);
-  used = MP_USED(b);
-  for(ix = 0; ix < used; ix++) {
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD)
-    w = w + *pa + *pb++;
-    *pa++ = ACCUM(w);
-    w = CARRYOUT(w);
-#else
-    d = *pa;
-    sum = d + *pb++;
-    d = (sum < d);                      /* detect overflow */
-    *pa++ = sum += carry;
-    carry = d + (sum < carry);          /* detect overflow */
-#endif
-  }
-
-  /* If we run out of 'b' digits before we're actually done, make
-     sure the carries get propagated upward...
-   */
-  used = MP_USED(a);
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD)
-  while (w && ix < used) {
-    w = w + *pa;
-    *pa++ = ACCUM(w);
-    w = CARRYOUT(w);
-    ++ix;
-  }
-#else
-  while (carry && ix < used) {
-    sum = carry + *pa;
-    *pa++ = sum;
-    carry = !sum;
-    ++ix;
-  }
-#endif
-
-  /* If there's an overall carry out, increase precision and include
-     it.  We could have done this initially, but why touch the memory
-     allocator unless we're sure we have to?
-   */
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD)
-  if (w) {
-    if((res = s_mp_pad(a, used + 1)) != MP_OKAY)
-      return res;
-
-    DIGIT(a, ix) = (mp_digit)w;
-  }
-#else
-  if (carry) {
-    if((res = s_mp_pad(a, used + 1)) != MP_OKAY)
-      return res;
-
-    DIGIT(a, used) = carry;
-  }
-#endif
-
-  return MP_OKAY;
-} /* end s_mp_add() */
-
-/* }}} */
-
-/* Compute c = |a| + |b|         */ /* magnitude addition      */
-mp_err   s_mp_add_3arg(const mp_int *a, const mp_int *b, mp_int *c)
-{
-  mp_digit *pa, *pb, *pc;
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD)
-  mp_word   w = 0;
-#else
-  mp_digit  sum, carry = 0, d;
-#endif
-  mp_size   ix;
-  mp_size   used;
-  mp_err    res;
-
-  MP_SIGN(c) = MP_SIGN(a);
-  if (MP_USED(a) < MP_USED(b)) {
-    const mp_int *xch = a;
-    a = b;
-    b = xch;
-  }
-
-  /* Make sure a has enough precision for the output value */
-  if (MP_OKAY != (res = s_mp_pad(c, MP_USED(a))))
-    return res;
-
-  /*
-    Add up all digits up to the precision of b.  If b had initially
-    the same precision as a, or greater, we took care of it by the
-    exchange step above, so there is no problem.  If b had initially
-    less precision, we'll have to make sure the carry out is duly
-    propagated upward among the higher-order digits of the sum.
-   */
-  pa = MP_DIGITS(a);
-  pb = MP_DIGITS(b);
-  pc = MP_DIGITS(c);
-  used = MP_USED(b);
-  for (ix = 0; ix < used; ix++) {
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD)
-    w = w + *pa++ + *pb++;
-    *pc++ = ACCUM(w);
-    w = CARRYOUT(w);
-#else
-    d = *pa++;
-    sum = d + *pb++;
-    d = (sum < d);                      /* detect overflow */
-    *pc++ = sum += carry;
-    carry = d + (sum < carry);          /* detect overflow */
-#endif
-  }
-
-  /* If we run out of 'b' digits before we're actually done, make
-     sure the carries get propagated upward...
-   */
-  for (used = MP_USED(a); ix < used; ++ix) {
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD)
-    w = w + *pa++;
-    *pc++ = ACCUM(w);
-    w = CARRYOUT(w);
-#else
-    *pc++ = sum = carry + *pa++;
-    carry = (sum < carry);
-#endif
-  }
-
-  /* If there's an overall carry out, increase precision and include
-     it.  We could have done this initially, but why touch the memory
-     allocator unless we're sure we have to?
-   */
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD)
-  if (w) {
-    if((res = s_mp_pad(c, used + 1)) != MP_OKAY)
-      return res;
-
-    DIGIT(c, used) = (mp_digit)w;
-    ++used;
-  }
-#else
-  if (carry) {
-    if((res = s_mp_pad(c, used + 1)) != MP_OKAY)
-      return res;
-
-    DIGIT(c, used) = carry;
-    ++used;
-  }
-#endif
-  MP_USED(c) = used;
-  return MP_OKAY;
-}
-/* {{{ s_mp_add_offset(a, b, offset) */
-
-/* Compute a = |a| + ( |b| * (RADIX ** offset) )             */
-mp_err   s_mp_add_offset(mp_int *a, mp_int *b, mp_size offset)
-{
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD)
-  mp_word   w, k = 0;
-#else
-  mp_digit  d, sum, carry = 0;
-#endif
-  mp_size   ib;
-  mp_size   ia;
-  mp_size   lim;
-  mp_err    res;
-
-  /* Make sure a has enough precision for the output value */
-  lim = MP_USED(b) + offset;
-  if((lim > USED(a)) && (res = s_mp_pad(a, lim)) != MP_OKAY)
-    return res;
-
-  /*
-    Add up all digits up to the precision of b.  If b had initially
-    the same precision as a, or greater, we took care of it by the
-    padding step above, so there is no problem.  If b had initially
-    less precision, we'll have to make sure the carry out is duly
-    propagated upward among the higher-order digits of the sum.
-   */
-  lim = USED(b);
-  for(ib = 0, ia = offset; ib < lim; ib++, ia++) {
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD)
-    w = (mp_word)DIGIT(a, ia) + DIGIT(b, ib) + k;
-    DIGIT(a, ia) = ACCUM(w);
-    k = CARRYOUT(w);
-#else
-    d = MP_DIGIT(a, ia);
-    sum = d + MP_DIGIT(b, ib);
-    d = (sum < d);
-    MP_DIGIT(a,ia) = sum += carry;
-    carry = d + (sum < carry);
-#endif
-  }
-
-  /* If we run out of 'b' digits before we're actually done, make
-     sure the carries get propagated upward...
-   */
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD)
-  for (lim = MP_USED(a); k && (ia < lim); ++ia) {
-    w = (mp_word)DIGIT(a, ia) + k;
-    DIGIT(a, ia) = ACCUM(w);
-    k = CARRYOUT(w);
-  }
-#else
-  for (lim = MP_USED(a); carry && (ia < lim); ++ia) {
-    d = MP_DIGIT(a, ia);
-    MP_DIGIT(a,ia) = sum = d + carry;
-    carry = (sum < d);
-  }
-#endif
-
-  /* If there's an overall carry out, increase precision and include
-     it.  We could have done this initially, but why touch the memory
-     allocator unless we're sure we have to?
-   */
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD)
-  if(k) {
-    if((res = s_mp_pad(a, USED(a) + 1)) != MP_OKAY)
-      return res;
-
-    DIGIT(a, ia) = (mp_digit)k;
-  }
-#else
-  if (carry) {
-    if((res = s_mp_pad(a, lim + 1)) != MP_OKAY)
-      return res;
-
-    DIGIT(a, lim) = carry;
-  }
-#endif
-  s_mp_clamp(a);
-
-  return MP_OKAY;
-
-} /* end s_mp_add_offset() */
-
-/* }}} */
-
-/* {{{ s_mp_sub(a, b) */
-
-/* Compute a = |a| - |b|, assumes |a| >= |b|                              */
-mp_err   s_mp_sub(mp_int *a, const mp_int *b)  /* magnitude subtract      */
-{
-  mp_digit *pa, *pb, *limit;
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_SUB_WORD)
-  mp_sword  w = 0;
-#else
-  mp_digit  d, diff, borrow = 0;
-#endif
-
-  /*
-    Subtract and propagate borrow.  Up to the precision of b, this
-    accounts for the digits of b; after that, we just make sure the
-    carries get to the right place.  This saves having to pad b out to
-    the precision of a just to make the loops work right...
-   */
-  pa = MP_DIGITS(a);
-  pb = MP_DIGITS(b);
-  limit = pb + MP_USED(b);
-  while (pb < limit) {
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_SUB_WORD)
-    w = w + *pa - *pb++;
-    *pa++ = ACCUM(w);
-    w >>= MP_DIGIT_BIT;
-#else
-    d = *pa;
-    diff = d - *pb++;
-    d = (diff > d);                             /* detect borrow */
-    if (borrow && --diff == MP_DIGIT_MAX)
-      ++d;
-    *pa++ = diff;
-    borrow = d;
-#endif
-  }
-  limit = MP_DIGITS(a) + MP_USED(a);
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_SUB_WORD)
-  while (w && pa < limit) {
-    w = w + *pa;
-    *pa++ = ACCUM(w);
-    w >>= MP_DIGIT_BIT;
-  }
-#else
-  while (borrow && pa < limit) {
-    d = *pa;
-    *pa++ = diff = d - borrow;
-    borrow = (diff > d);
-  }
-#endif
-
-  /* Clobber any leading zeroes we created    */
-  s_mp_clamp(a);
-
-  /*
-     If there was a borrow out, then |b| > |a| in violation
-     of our input invariant.  We've already done the work,
-     but we'll at least complain about it...
-   */
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_SUB_WORD)
-  return w ? MP_RANGE : MP_OKAY;
-#else
-  return borrow ? MP_RANGE : MP_OKAY;
-#endif
-} /* end s_mp_sub() */
-
-/* }}} */
-
-/* Compute c = |a| - |b|, assumes |a| >= |b| */ /* magnitude subtract      */
-mp_err   s_mp_sub_3arg(const mp_int *a, const mp_int *b, mp_int *c)
-{
-  mp_digit *pa, *pb, *pc;
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_SUB_WORD)
-  mp_sword  w = 0;
-#else
-  mp_digit  d, diff, borrow = 0;
-#endif
-  int       ix, limit;
-  mp_err    res;
-
-  MP_SIGN(c) = MP_SIGN(a);
-
-  /* Make sure a has enough precision for the output value */
-  if (MP_OKAY != (res = s_mp_pad(c, MP_USED(a))))
-    return res;
-
-  /*
-    Subtract and propagate borrow.  Up to the precision of b, this
-    accounts for the digits of b; after that, we just make sure the
-    carries get to the right place.  This saves having to pad b out to
-    the precision of a just to make the loops work right...
-   */
-  pa = MP_DIGITS(a);
-  pb = MP_DIGITS(b);
-  pc = MP_DIGITS(c);
-  limit = MP_USED(b);
-  for (ix = 0; ix < limit; ++ix) {
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_SUB_WORD)
-    w = w + *pa++ - *pb++;
-    *pc++ = ACCUM(w);
-    w >>= MP_DIGIT_BIT;
-#else
-    d = *pa++;
-    diff = d - *pb++;
-    d = (diff > d);
-    if (borrow && --diff == MP_DIGIT_MAX)
-      ++d;
-    *pc++ = diff;
-    borrow = d;
-#endif
-  }
-  for (limit = MP_USED(a); ix < limit; ++ix) {
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_SUB_WORD)
-    w = w + *pa++;
-    *pc++ = ACCUM(w);
-    w >>= MP_DIGIT_BIT;
-#else
-    d = *pa++;
-    *pc++ = diff = d - borrow;
-    borrow = (diff > d);
-#endif
-  }
-
-  /* Clobber any leading zeroes we created    */
-  MP_USED(c) = ix;
-  s_mp_clamp(c);
-
-  /*
-     If there was a borrow out, then |b| > |a| in violation
-     of our input invariant.  We've already done the work,
-     but we'll at least complain about it...
-   */
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_SUB_WORD)
-  return w ? MP_RANGE : MP_OKAY;
-#else
-  return borrow ? MP_RANGE : MP_OKAY;
-#endif
-}
-/* {{{ s_mp_mul(a, b) */
-
-/* Compute a = |a| * |b|                                                  */
-mp_err   s_mp_mul(mp_int *a, const mp_int *b)
-{
-  return mp_mul(a, b, a);
-} /* end s_mp_mul() */
-
-/* }}} */
-
-#if defined(MP_USE_UINT_DIGIT) && defined(MP_USE_LONG_LONG_MULTIPLY)
-/* This trick works on Sparc V8 CPUs with the Workshop compilers. */
-#define MP_MUL_DxD(a, b, Phi, Plo) \
-  { unsigned long long product = (unsigned long long)a * b; \
-    Plo = (mp_digit)product; \
-    Phi = (mp_digit)(product >> MP_DIGIT_BIT); }
-#elif defined(OSF1)
-#define MP_MUL_DxD(a, b, Phi, Plo) \
-  { Plo = asm ("mulq %a0, %a1, %v0", a, b);\
-    Phi = asm ("umulh %a0, %a1, %v0", a, b); }
-#else
-#define MP_MUL_DxD(a, b, Phi, Plo) \
-  { mp_digit a0b1, a1b0; \
-    Plo = (a & MP_HALF_DIGIT_MAX) * (b & MP_HALF_DIGIT_MAX); \
-    Phi = (a >> MP_HALF_DIGIT_BIT) * (b >> MP_HALF_DIGIT_BIT); \
-    a0b1 = (a & MP_HALF_DIGIT_MAX) * (b >> MP_HALF_DIGIT_BIT); \
-    a1b0 = (a >> MP_HALF_DIGIT_BIT) * (b & MP_HALF_DIGIT_MAX); \
-    a1b0 += a0b1; \
-    Phi += a1b0 >> MP_HALF_DIGIT_BIT; \
-    if (a1b0 < a0b1)  \
-      Phi += MP_HALF_RADIX; \
-    a1b0 <<= MP_HALF_DIGIT_BIT; \
-    Plo += a1b0; \
-    if (Plo < a1b0) \
-      ++Phi; \
-  }
-#endif
-
-#if !defined(MP_ASSEMBLY_MULTIPLY)
-/* c = a * b */
-void s_mpv_mul_d(const mp_digit *a, mp_size a_len, mp_digit b, mp_digit *c)
-{
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_MUL_WORD)
-  mp_digit   d = 0;
-
-  /* Inner product:  Digits of a */
-  while (a_len--) {
-    mp_word w = ((mp_word)b * *a++) + d;
-    *c++ = ACCUM(w);
-    d = CARRYOUT(w);
-  }
-  *c = d;
-#else
-  mp_digit carry = 0;
-  while (a_len--) {
-    mp_digit a_i = *a++;
-    mp_digit a0b0, a1b1;
-
-    MP_MUL_DxD(a_i, b, a1b1, a0b0);
-
-    a0b0 += carry;
-    if (a0b0 < carry)
-      ++a1b1;
-    *c++ = a0b0;
-    carry = a1b1;
-  }
-  *c = carry;
-#endif
-}
-
-/* c += a * b */
-void s_mpv_mul_d_add(const mp_digit *a, mp_size a_len, mp_digit b,
-                              mp_digit *c)
-{
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_MUL_WORD)
-  mp_digit   d = 0;
-
-  /* Inner product:  Digits of a */
-  while (a_len--) {
-    mp_word w = ((mp_word)b * *a++) + *c + d;
-    *c++ = ACCUM(w);
-    d = CARRYOUT(w);
-  }
-  *c = d;
-#else
-  mp_digit carry = 0;
-  while (a_len--) {
-    mp_digit a_i = *a++;
-    mp_digit a0b0, a1b1;
-
-    MP_MUL_DxD(a_i, b, a1b1, a0b0);
-
-    a0b0 += carry;
-    if (a0b0 < carry)
-      ++a1b1;
-    a0b0 += a_i = *c;
-    if (a0b0 < a_i)
-      ++a1b1;
-    *c++ = a0b0;
-    carry = a1b1;
-  }
-  *c = carry;
-#endif
-}
-
-/* Presently, this is only used by the Montgomery arithmetic code. */
-/* c += a * b */
-void s_mpv_mul_d_add_prop(const mp_digit *a, mp_size a_len, mp_digit b, mp_digit *c)
-{
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_MUL_WORD)
-  mp_digit   d = 0;
-
-  /* Inner product:  Digits of a */
-  while (a_len--) {
-    mp_word w = ((mp_word)b * *a++) + *c + d;
-    *c++ = ACCUM(w);
-    d = CARRYOUT(w);
-  }
-
-  while (d) {
-    mp_word w = (mp_word)*c + d;
-    *c++ = ACCUM(w);
-    d = CARRYOUT(w);
-  }
-#else
-  mp_digit carry = 0;
-  while (a_len--) {
-    mp_digit a_i = *a++;
-    mp_digit a0b0, a1b1;
-
-    MP_MUL_DxD(a_i, b, a1b1, a0b0);
-
-    a0b0 += carry;
-    if (a0b0 < carry)
-      ++a1b1;
-
-    a0b0 += a_i = *c;
-    if (a0b0 < a_i)
-      ++a1b1;
-
-    *c++ = a0b0;
-    carry = a1b1;
-  }
-  while (carry) {
-    mp_digit c_i = *c;
-    carry += c_i;
-    *c++ = carry;
-    carry = carry < c_i;
-  }
-#endif
-}
-#endif
-
-#if defined(MP_USE_UINT_DIGIT) && defined(MP_USE_LONG_LONG_MULTIPLY)
-/* This trick works on Sparc V8 CPUs with the Workshop compilers. */
-#define MP_SQR_D(a, Phi, Plo) \
-  { unsigned long long square = (unsigned long long)a * a; \
-    Plo = (mp_digit)square; \
-    Phi = (mp_digit)(square >> MP_DIGIT_BIT); }
-#elif defined(OSF1)
-#define MP_SQR_D(a, Phi, Plo) \
-  { Plo = asm ("mulq  %a0, %a0, %v0", a);\
-    Phi = asm ("umulh %a0, %a0, %v0", a); }
-#else
-#define MP_SQR_D(a, Phi, Plo) \
-  { mp_digit Pmid; \
-    Plo  = (a  & MP_HALF_DIGIT_MAX) * (a  & MP_HALF_DIGIT_MAX); \
-    Phi  = (a >> MP_HALF_DIGIT_BIT) * (a >> MP_HALF_DIGIT_BIT); \
-    Pmid = (a  & MP_HALF_DIGIT_MAX) * (a >> MP_HALF_DIGIT_BIT); \
-    Phi += Pmid >> (MP_HALF_DIGIT_BIT - 1);  \
-    Pmid <<= (MP_HALF_DIGIT_BIT + 1);  \
-    Plo += Pmid;  \
-    if (Plo < Pmid)  \
-      ++Phi;  \
-  }
-#endif
-
-#if !defined(MP_ASSEMBLY_SQUARE)
-/* Add the squares of the digits of a to the digits of b. */
-void s_mpv_sqr_add_prop(const mp_digit *pa, mp_size a_len, mp_digit *ps)
-{
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_MUL_WORD)
-  mp_word  w;
-  mp_digit d;
-  mp_size  ix;
-
-  w  = 0;
-#define ADD_SQUARE(n) \
-    d = pa[n]; \
-    w += (d * (mp_word)d) + ps[2*n]; \
-    ps[2*n] = ACCUM(w); \
-    w = (w >> DIGIT_BIT) + ps[2*n+1]; \
-    ps[2*n+1] = ACCUM(w); \
-    w = (w >> DIGIT_BIT)
-
-  for (ix = a_len; ix >= 4; ix -= 4) {
-    ADD_SQUARE(0);
-    ADD_SQUARE(1);
-    ADD_SQUARE(2);
-    ADD_SQUARE(3);
-    pa += 4;
-    ps += 8;
-  }
-  if (ix) {
-    ps += 2*ix;
-    pa += ix;
-    switch (ix) {
-    case 3: ADD_SQUARE(-3); /* FALLTHRU */
-    case 2: ADD_SQUARE(-2); /* FALLTHRU */
-    case 1: ADD_SQUARE(-1); /* FALLTHRU */
-    case 0: break;
-    }
-  }
-  while (w) {
-    w += *ps;
-    *ps++ = ACCUM(w);
-    w = (w >> DIGIT_BIT);
-  }
-#else
-  mp_digit carry = 0;
-  while (a_len--) {
-    mp_digit a_i = *pa++;
-    mp_digit a0a0, a1a1;
-
-    MP_SQR_D(a_i, a1a1, a0a0);
-
-    /* here a1a1 and a0a0 constitute a_i ** 2 */
-    a0a0 += carry;
-    if (a0a0 < carry)
-      ++a1a1;
-
-    /* now add to ps */
-    a0a0 += a_i = *ps;
-    if (a0a0 < a_i)
-      ++a1a1;
-    *ps++ = a0a0;
-    a1a1 += a_i = *ps;
-    carry = (a1a1 < a_i);
-    *ps++ = a1a1;
-  }
-  while (carry) {
-    mp_digit s_i = *ps;
-    carry += s_i;
-    *ps++ = carry;
-    carry = carry < s_i;
-  }
-#endif
-}
-#endif
-
-#if (defined(MP_NO_MP_WORD) || defined(MP_NO_DIV_WORD)) \
-&& !defined(MP_ASSEMBLY_DIV_2DX1D)
-/*
-** Divide 64-bit (Nhi,Nlo) by 32-bit divisor, which must be normalized
-** so its high bit is 1.   This code is from NSPR.
-*/
-mp_err s_mpv_div_2dx1d(mp_digit Nhi, mp_digit Nlo, mp_digit divisor,
-                       mp_digit *qp, mp_digit *rp)
-{
-    mp_digit d1, d0, q1, q0;
-    mp_digit r1, r0, m;
-
-    d1 = divisor >> MP_HALF_DIGIT_BIT;
-    d0 = divisor & MP_HALF_DIGIT_MAX;
-    r1 = Nhi % d1;
-    q1 = Nhi / d1;
-    m = q1 * d0;
-    r1 = (r1 << MP_HALF_DIGIT_BIT) | (Nlo >> MP_HALF_DIGIT_BIT);
-    if (r1 < m) {
-        q1--, r1 += divisor;
-        if (r1 >= divisor && r1 < m) {
-            q1--, r1 += divisor;
-        }
-    }
-    r1 -= m;
-    r0 = r1 % d1;
-    q0 = r1 / d1;
-    m = q0 * d0;
-    r0 = (r0 << MP_HALF_DIGIT_BIT) | (Nlo & MP_HALF_DIGIT_MAX);
-    if (r0 < m) {
-        q0--, r0 += divisor;
-        if (r0 >= divisor && r0 < m) {
-            q0--, r0 += divisor;
-        }
-    }
-    if (qp)
-        *qp = (q1 << MP_HALF_DIGIT_BIT) | q0;
-    if (rp)
-        *rp = r0 - m;
-    return MP_OKAY;
-}
-#endif
-
-#if MP_SQUARE
-/* {{{ s_mp_sqr(a) */
-
-mp_err   s_mp_sqr(mp_int *a)
-{
-  mp_err   res;
-  mp_int   tmp;
-
-  if((res = mp_init_size(&tmp, 2 * USED(a), FLAG(a))) != MP_OKAY)
-    return res;
-  res = mp_sqr(a, &tmp);
-  if (res == MP_OKAY) {
-    s_mp_exch(&tmp, a);
-  }
-  mp_clear(&tmp);
-  return res;
-}
-
-/* }}} */
-#endif
-
-/* {{{ s_mp_div(a, b) */
-
-/*
-  s_mp_div(a, b)
-
-  Compute a = a / b and b = a mod b.  Assumes b > a.
- */
-
-mp_err   s_mp_div(mp_int *rem,  /* i: dividend, o: remainder */
-                  mp_int *div,  /* i: divisor                */
-                  mp_int *quot) /* i: 0;        o: quotient  */
-{
-  mp_int   part, t;
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_DIV_WORD)
-  mp_word  q_msd;
-#else
-  mp_digit q_msd;
-#endif
-  mp_err   res;
-  mp_digit d;
-  mp_digit div_msd;
-  int      ix;
-
-  if(mp_cmp_z(div) == 0)
-    return MP_RANGE;
-
-  /* Shortcut if divisor is power of two */
-  if((ix = s_mp_ispow2(div)) >= 0) {
-    MP_CHECKOK( mp_copy(rem, quot) );
-    s_mp_div_2d(quot, (mp_digit)ix);
-    s_mp_mod_2d(rem,  (mp_digit)ix);
-
-    return MP_OKAY;
-  }
-
-  DIGITS(&t) = 0;
-  MP_SIGN(rem) = ZPOS;
-  MP_SIGN(div) = ZPOS;
-
-  /* A working temporary for division     */
-  MP_CHECKOK( mp_init_size(&t, MP_ALLOC(rem), FLAG(rem)));
-
-  /* Normalize to optimize guessing       */
-  MP_CHECKOK( s_mp_norm(rem, div, &d) );
-
-  part = *rem;
-
-  /* Perform the division itself...woo!   */
-  MP_USED(quot) = MP_ALLOC(quot);
-
-  /* Find a partial substring of rem which is at least div */
-  /* If we didn't find one, we're finished dividing    */
-  while (MP_USED(rem) > MP_USED(div) || s_mp_cmp(rem, div) >= 0) {
-    int i;
-    int unusedRem;
-
-    unusedRem = MP_USED(rem) - MP_USED(div);
-    MP_DIGITS(&part) = MP_DIGITS(rem) + unusedRem;
-    MP_ALLOC(&part)  = MP_ALLOC(rem)  - unusedRem;
-    MP_USED(&part)   = MP_USED(div);
-    if (s_mp_cmp(&part, div) < 0) {
-      -- unusedRem;
-#if MP_ARGCHK == 2
-      assert(unusedRem >= 0);
-#endif
-      -- MP_DIGITS(&part);
-      ++ MP_USED(&part);
-      ++ MP_ALLOC(&part);
-    }
-
-    /* Compute a guess for the next quotient digit       */
-    q_msd = MP_DIGIT(&part, MP_USED(&part) - 1);
-    div_msd = MP_DIGIT(div, MP_USED(div) - 1);
-    if (q_msd >= div_msd) {
-      q_msd = 1;
-    } else if (MP_USED(&part) > 1) {
-#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_DIV_WORD)
-      q_msd = (q_msd << MP_DIGIT_BIT) | MP_DIGIT(&part, MP_USED(&part) - 2);
-      q_msd /= div_msd;
-      if (q_msd == RADIX)
-        --q_msd;
-#else
-      mp_digit r;
-      MP_CHECKOK( s_mpv_div_2dx1d(q_msd, MP_DIGIT(&part, MP_USED(&part) - 2),
-                                  div_msd, &q_msd, &r) );
-#endif
-    } else {
-      q_msd = 0;
-    }
-#if MP_ARGCHK == 2
-    assert(q_msd > 0); /* This case should never occur any more. */
-#endif
-    if (q_msd <= 0)
-      break;
-
-    /* See what that multiplies out to                   */
-    mp_copy(div, &t);
-    MP_CHECKOK( s_mp_mul_d(&t, (mp_digit)q_msd) );
-
-    /*
-       If it's too big, back it off.  We should not have to do this
-       more than once, or, in rare cases, twice.  Knuth describes a
-       method by which this could be reduced to a maximum of once, but
-       I didn't implement that here.
-     * When using s_mpv_div_2dx1d, we may have to do this 3 times.
-     */
-    for (i = 4; s_mp_cmp(&t, &part) > 0 && i > 0; --i) {
-      --q_msd;
-      s_mp_sub(&t, div);        /* t -= div */
-    }
-    if (i < 0) {
-      res = MP_RANGE;
-      goto CLEANUP;
-    }
-
-    /* At this point, q_msd should be the right next digit   */
-    MP_CHECKOK( s_mp_sub(&part, &t) );  /* part -= t */
-    s_mp_clamp(rem);
-
-    /*
-      Include the digit in the quotient.  We allocated enough memory
-      for any quotient we could ever possibly get, so we should not
-      have to check for failures here
-     */
-    MP_DIGIT(quot, unusedRem) = (mp_digit)q_msd;
-  }
-
-  /* Denormalize remainder                */
-  if (d) {
-    s_mp_div_2d(rem, d);
-  }
-
-  s_mp_clamp(quot);
-
-CLEANUP:
-  mp_clear(&t);
-
-  return res;
-
-} /* end s_mp_div() */
-
-
-/* }}} */
-
-/* {{{ s_mp_2expt(a, k) */
-
-mp_err   s_mp_2expt(mp_int *a, mp_digit k)
-{
-  mp_err    res;
-  mp_size   dig, bit;
-
-  dig = k / DIGIT_BIT;
-  bit = k % DIGIT_BIT;
-
-  mp_zero(a);
-  if((res = s_mp_pad(a, dig + 1)) != MP_OKAY)
-    return res;
-
-  DIGIT(a, dig) |= ((mp_digit)1 << bit);
-
-  return MP_OKAY;
-
-} /* end s_mp_2expt() */
-
-/* }}} */
-
-/* {{{ s_mp_reduce(x, m, mu) */
-
-/*
-  Compute Barrett reduction, x (mod m), given a precomputed value for
-  mu = b^2k / m, where b = RADIX and k = #digits(m).  This should be
-  faster than straight division, when many reductions by the same
-  value of m are required (such as in modular exponentiation).  This
-  can nearly halve the time required to do modular exponentiation,
-  as compared to using the full integer divide to reduce.
-
-  This algorithm was derived from the _Handbook of Applied
-  Cryptography_ by Menezes, Oorschot and VanStone, Ch. 14,
-  pp. 603-604.
- */
-
-mp_err   s_mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu)
-{
-  mp_int   q;
-  mp_err   res;
-
-  if((res = mp_init_copy(&q, x)) != MP_OKAY)
-    return res;
-
-  s_mp_rshd(&q, USED(m) - 1);  /* q1 = x / b^(k-1)  */
-  s_mp_mul(&q, mu);            /* q2 = q1 * mu      */
-  s_mp_rshd(&q, USED(m) + 1);  /* q3 = q2 / b^(k+1) */
-
-  /* x = x mod b^(k+1), quick (no division) */
-  s_mp_mod_2d(x, DIGIT_BIT * (USED(m) + 1));
-
-  /* q = q * m mod b^(k+1), quick (no division) */
-  s_mp_mul(&q, m);
-  s_mp_mod_2d(&q, DIGIT_BIT * (USED(m) + 1));
-
-  /* x = x - q */
-  if((res = mp_sub(x, &q, x)) != MP_OKAY)
-    goto CLEANUP;
-
-  /* If x < 0, add b^(k+1) to it */
-  if(mp_cmp_z(x) < 0) {
-    mp_set(&q, 1);
-    if((res = s_mp_lshd(&q, USED(m) + 1)) != MP_OKAY)
-      goto CLEANUP;
-    if((res = mp_add(x, &q, x)) != MP_OKAY)
-      goto CLEANUP;
-  }
-
-  /* Back off if it's too big */
-  while(mp_cmp(x, m) >= 0) {
-    if((res = s_mp_sub(x, m)) != MP_OKAY)
-      break;
-  }
-
- CLEANUP:
-  mp_clear(&q);
-
-  return res;
-
-} /* end s_mp_reduce() */
-
-/* }}} */
-
-/* }}} */
-
-/* {{{ Primitive comparisons */
-
-/* {{{ s_mp_cmp(a, b) */
-
-/* Compare |a| <=> |b|, return 0 if equal, <0 if a<b, >0 if a>b           */
-int      s_mp_cmp(const mp_int *a, const mp_int *b)
-{
-  mp_size used_a = MP_USED(a);
-  {
-    mp_size used_b = MP_USED(b);
-
-    if (used_a > used_b)
-      goto IS_GT;
-    if (used_a < used_b)
-      goto IS_LT;
-  }
-  {
-    mp_digit *pa, *pb;
-    mp_digit da = 0, db = 0;
-
-#define CMP_AB(n) if ((da = pa[n]) != (db = pb[n])) goto done
-
-    pa = MP_DIGITS(a) + used_a;
-    pb = MP_DIGITS(b) + used_a;
-    while (used_a >= 4) {
-      pa     -= 4;
-      pb     -= 4;
-      used_a -= 4;
-      CMP_AB(3);
-      CMP_AB(2);
-      CMP_AB(1);
-      CMP_AB(0);
-    }
-    while (used_a-- > 0 && ((da = *--pa) == (db = *--pb)))
-      /* do nothing */;
-done:
-    if (da > db)
-      goto IS_GT;
-    if (da < db)
-      goto IS_LT;
-  }
-  return MP_EQ;
-IS_LT:
-  return MP_LT;
-IS_GT:
-  return MP_GT;
-} /* end s_mp_cmp() */
-
-/* }}} */
-
-/* {{{ s_mp_cmp_d(a, d) */
-
-/* Compare |a| <=> d, return 0 if equal, <0 if a<d, >0 if a>d             */
-int      s_mp_cmp_d(const mp_int *a, mp_digit d)
-{
-  if(USED(a) > 1)
-    return MP_GT;
-
-  if(DIGIT(a, 0) < d)
-    return MP_LT;
-  else if(DIGIT(a, 0) > d)
-    return MP_GT;
-  else
-    return MP_EQ;
-
-} /* end s_mp_cmp_d() */
-
-/* }}} */
-
-/* {{{ s_mp_ispow2(v) */
-
-/*
-  Returns -1 if the value is not a power of two; otherwise, it returns
-  k such that v = 2^k, i.e. lg(v).
- */
-int      s_mp_ispow2(const mp_int *v)
-{
-  mp_digit d;
-  int      extra = 0, ix;
-
-  ix = MP_USED(v) - 1;
-  d = MP_DIGIT(v, ix); /* most significant digit of v */
-
-  extra = s_mp_ispow2d(d);
-  if (extra < 0 || ix == 0)
-    return extra;
-
-  while (--ix >= 0) {
-    if (DIGIT(v, ix) != 0)
-      return -1; /* not a power of two */
-    extra += MP_DIGIT_BIT;
-  }
-
-  return extra;
-
-} /* end s_mp_ispow2() */
-
-/* }}} */
-
-/* {{{ s_mp_ispow2d(d) */
-
-int      s_mp_ispow2d(mp_digit d)
-{
-  if ((d != 0) && ((d & (d-1)) == 0)) { /* d is a power of 2 */
-    int pow = 0;
-#if defined (MP_USE_UINT_DIGIT)
-    if (d & 0xffff0000U)
-      pow += 16;
-    if (d & 0xff00ff00U)
-      pow += 8;
-    if (d & 0xf0f0f0f0U)
-      pow += 4;
-    if (d & 0xccccccccU)
-      pow += 2;
-    if (d & 0xaaaaaaaaU)
-      pow += 1;
-#elif defined(MP_USE_LONG_LONG_DIGIT)
-    if (d & 0xffffffff00000000ULL)
-      pow += 32;
-    if (d & 0xffff0000ffff0000ULL)
-      pow += 16;
-    if (d & 0xff00ff00ff00ff00ULL)
-      pow += 8;
-    if (d & 0xf0f0f0f0f0f0f0f0ULL)
-      pow += 4;
-    if (d & 0xccccccccccccccccULL)
-      pow += 2;
-    if (d & 0xaaaaaaaaaaaaaaaaULL)
-      pow += 1;
-#elif defined(MP_USE_LONG_DIGIT)
-    if (d & 0xffffffff00000000UL)
-      pow += 32;
-    if (d & 0xffff0000ffff0000UL)
-      pow += 16;
-    if (d & 0xff00ff00ff00ff00UL)
-      pow += 8;
-    if (d & 0xf0f0f0f0f0f0f0f0UL)
-      pow += 4;
-    if (d & 0xccccccccccccccccUL)
-      pow += 2;
-    if (d & 0xaaaaaaaaaaaaaaaaUL)
-      pow += 1;
-#else
-#error "unknown type for mp_digit"
-#endif
-    return pow;
-  }
-  return -1;
-
-} /* end s_mp_ispow2d() */
-
-/* }}} */
-
-/* }}} */
-
-/* {{{ Primitive I/O helpers */
-
-/* {{{ s_mp_tovalue(ch, r) */
-
-/*
-  Convert the given character to its digit value, in the given radix.
-  If the given character is not understood in the given radix, -1 is
-  returned.  Otherwise the digit's numeric value is returned.
-
-  The results will be odd if you use a radix < 2 or > 62, you are
-  expected to know what you're up to.
- */
-int      s_mp_tovalue(char ch, int r)
-{
-  int    val, xch;
-
-  if(r > 36)
-    xch = ch;
-  else
-    xch = toupper(ch);
-
-  if(isdigit(xch))
-    val = xch - '0';
-  else if(isupper(xch))
-    val = xch - 'A' + 10;
-  else if(islower(xch))
-    val = xch - 'a' + 36;
-  else if(xch == '+')
-    val = 62;
-  else if(xch == '/')
-    val = 63;
-  else
-    return -1;
-
-  if(val < 0 || val >= r)
-    return -1;
-
-  return val;
-
-} /* end s_mp_tovalue() */
-
-/* }}} */
-
-/* {{{ s_mp_todigit(val, r, low) */
-
-/*
-  Convert val to a radix-r digit, if possible.  If val is out of range
-  for r, returns zero.  Otherwise, returns an ASCII character denoting
-  the value in the given radix.
-
-  The results may be odd if you use a radix < 2 or > 64, you are
-  expected to know what you're doing.
- */
-
-char     s_mp_todigit(mp_digit val, int r, int low)
-{
-  char   ch;
-
-  if(val >= r)
-    return 0;
-
-  ch = s_dmap_1[val];
-
-  if(r <= 36 && low)
-    ch = tolower(ch);
-
-  return ch;
-
-} /* end s_mp_todigit() */
-
-/* }}} */
-
-/* {{{ s_mp_outlen(bits, radix) */
-
-/*
-   Return an estimate for how long a string is needed to hold a radix
-   r representation of a number with 'bits' significant bits, plus an
-   extra for a zero terminator (assuming C style strings here)
- */
-int      s_mp_outlen(int bits, int r)
-{
-  return (int)((double)bits * LOG_V_2(r) + 1.5) + 1;
-
-} /* end s_mp_outlen() */
-
-/* }}} */
-
-/* }}} */
-
-/* {{{ mp_read_unsigned_octets(mp, str, len) */
-/* mp_read_unsigned_octets(mp, str, len)
-   Read in a raw value (base 256) into the given mp_int
-   No sign bit, number is positive.  Leading zeros ignored.
- */
-
-mp_err
-mp_read_unsigned_octets(mp_int *mp, const unsigned char *str, mp_size len)
-{
-  int            count;
-  mp_err         res;
-  mp_digit       d;
-
-  ARGCHK(mp != NULL && str != NULL && len > 0, MP_BADARG);
-
-  mp_zero(mp);
-
-  count = len % sizeof(mp_digit);
-  if (count) {
-    for (d = 0; count-- > 0; --len) {
-      d = (d << 8) | *str++;
-    }
-    MP_DIGIT(mp, 0) = d;
-  }
-
-  /* Read the rest of the digits */
-  for(; len > 0; len -= sizeof(mp_digit)) {
-    for (d = 0, count = sizeof(mp_digit); count > 0; --count) {
-      d = (d << 8) | *str++;
-    }
-    if (MP_EQ == mp_cmp_z(mp)) {
-      if (!d)
-        continue;
-    } else {
-      if((res = s_mp_lshd(mp, 1)) != MP_OKAY)
-        return res;
-    }
-    MP_DIGIT(mp, 0) = d;
-  }
-  return MP_OKAY;
-} /* end mp_read_unsigned_octets() */
-/* }}} */
-
-/* {{{ mp_unsigned_octet_size(mp) */
-int
-mp_unsigned_octet_size(const mp_int *mp)
-{
-  int  bytes;
-  int  ix;
-  mp_digit  d = 0;
-
-  ARGCHK(mp != NULL, MP_BADARG);
-  ARGCHK(MP_ZPOS == SIGN(mp), MP_BADARG);
-
-  bytes = (USED(mp) * sizeof(mp_digit));
-
-  /* subtract leading zeros. */
-  /* Iterate over each digit... */
-  for(ix = USED(mp) - 1; ix >= 0; ix--) {
-    d = DIGIT(mp, ix);
-    if (d)
-        break;
-    bytes -= sizeof(d);
-  }
-  if (!bytes)
-    return 1;
-
-  /* Have MSD, check digit bytes, high order first */
-  for(ix = sizeof(mp_digit) - 1; ix >= 0; ix--) {
-    unsigned char x = (unsigned char)(d >> (ix * CHAR_BIT));
-    if (x)
-        break;
-    --bytes;
-  }
-  return bytes;
-} /* end mp_unsigned_octet_size() */
-/* }}} */
-
-/* {{{ mp_to_unsigned_octets(mp, str) */
-/* output a buffer of big endian octets no longer than specified. */
-mp_err
-mp_to_unsigned_octets(const mp_int *mp, unsigned char *str, mp_size maxlen)
-{
-  int  ix, pos = 0;
-  int  bytes;
-
-  ARGCHK(mp != NULL && str != NULL && !SIGN(mp), MP_BADARG);
-
-  bytes = mp_unsigned_octet_size(mp);
-  ARGCHK(bytes <= maxlen, MP_BADARG);
-
-  /* Iterate over each digit... */
-  for(ix = USED(mp) - 1; ix >= 0; ix--) {
-    mp_digit  d = DIGIT(mp, ix);
-    int       jx;
-
-    /* Unpack digit bytes, high order first */
-    for(jx = sizeof(mp_digit) - 1; jx >= 0; jx--) {
-      unsigned char x = (unsigned char)(d >> (jx * CHAR_BIT));
-      if (!pos && !x)   /* suppress leading zeros */
-        continue;
-      str[pos++] = x;
-    }
-  }
-  if (!pos)
-    str[pos++] = 0;
-  return pos;
-} /* end mp_to_unsigned_octets() */
-/* }}} */
-
-/* {{{ mp_to_signed_octets(mp, str) */
-/* output a buffer of big endian octets no longer than specified. */
-mp_err
-mp_to_signed_octets(const mp_int *mp, unsigned char *str, mp_size maxlen)
-{
-  int  ix, pos = 0;
-  int  bytes;
-
-  ARGCHK(mp != NULL && str != NULL && !SIGN(mp), MP_BADARG);
-
-  bytes = mp_unsigned_octet_size(mp);
-  ARGCHK(bytes <= maxlen, MP_BADARG);
-
-  /* Iterate over each digit... */
-  for(ix = USED(mp) - 1; ix >= 0; ix--) {
-    mp_digit  d = DIGIT(mp, ix);
-    int       jx;
-
-    /* Unpack digit bytes, high order first */
-    for(jx = sizeof(mp_digit) - 1; jx >= 0; jx--) {
-      unsigned char x = (unsigned char)(d >> (jx * CHAR_BIT));
-      if (!pos) {
-        if (!x)         /* suppress leading zeros */
-          continue;
-        if (x & 0x80) { /* add one leading zero to make output positive.  */
-          ARGCHK(bytes + 1 <= maxlen, MP_BADARG);
-          if (bytes + 1 > maxlen)
-            return MP_BADARG;
-          str[pos++] = 0;
-        }
-      }
-      str[pos++] = x;
-    }
-  }
-  if (!pos)
-    str[pos++] = 0;
-  return pos;
-} /* end mp_to_signed_octets() */
-/* }}} */
-
-/* {{{ mp_to_fixlen_octets(mp, str) */
-/* output a buffer of big endian octets exactly as long as requested. */
-mp_err
-mp_to_fixlen_octets(const mp_int *mp, unsigned char *str, mp_size length)
-{
-  int  ix, pos = 0;
-  int  bytes;
-
-  ARGCHK(mp != NULL && str != NULL && !SIGN(mp), MP_BADARG);
-
-  bytes = mp_unsigned_octet_size(mp);
-  ARGCHK(bytes <= length, MP_BADARG);
-
-  /* place any needed leading zeros */
-  for (;length > bytes; --length) {
-        *str++ = 0;
-  }
-
-  /* Iterate over each digit... */
-  for(ix = USED(mp) - 1; ix >= 0; ix--) {
-    mp_digit  d = DIGIT(mp, ix);
-    int       jx;
-
-    /* Unpack digit bytes, high order first */
-    for(jx = sizeof(mp_digit) - 1; jx >= 0; jx--) {
-      unsigned char x = (unsigned char)(d >> (jx * CHAR_BIT));
-      if (!pos && !x)   /* suppress leading zeros */
-        continue;
-      str[pos++] = x;
-    }
-  }
-  if (!pos)
-    str[pos++] = 0;
-  return MP_OKAY;
-} /* end mp_to_fixlen_octets() */
-/* }}} */
-
-
-/*------------------------------------------------------------------------*/
-/* HERE THERE BE DRAGONS                                                  */
--- a/jdk/src/share/native/sun/security/ec/mpi.h	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,409 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- *
- *  Arbitrary precision integer arithmetic library
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the MPI Arbitrary Precision Integer Arithmetic library.
- *
- * The Initial Developer of the Original Code is
- * Michael J. Fromberger.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Netscape Communications Corporation
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _MPI_H
-#define _MPI_H
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-/* $Id: mpi.h,v 1.22 2004/04/27 23:04:36 gerv%gerv.net Exp $ */
-
-#include "mpi-config.h"
-
-#ifndef _WIN32
-#include <sys/param.h>
-#endif /* _WIN32 */
-
-#ifdef _KERNEL
-#include <sys/debug.h>
-#include <sys/systm.h>
-#define assert ASSERT
-#define labs(a) (a >= 0 ? a : -a)
-#define UCHAR_MAX 255
-#define memset(s, c, n) bzero(s, n)
-#define memcpy(a,b,c) bcopy((caddr_t)b, (caddr_t)a, c)
-/*
- * Generic #define's to cover missing things in the kernel
- */
-#ifndef isdigit
-#define isdigit(x)      ((x) >= '0' && (x) <= '9')
-#endif
-#ifndef isupper
-#define isupper(x)      (((unsigned)(x) >= 'A') && ((unsigned)(x) <= 'Z'))
-#endif
-#ifndef islower
-#define islower(x)      (((unsigned)(x) >= 'a') && ((unsigned)(x) <= 'z'))
-#endif
-#ifndef isalpha
-#define isalpha(x)      (isupper(x) || islower(x))
-#endif
-#ifndef toupper
-#define toupper(x)      (islower(x) ? (x) - 'a' + 'A' : (x))
-#endif
-#ifndef tolower
-#define tolower(x)      (isupper(x) ? (x) + 'a' - 'A' : (x))
-#endif
-#ifndef isspace
-#define isspace(x)      (((x) == ' ') || ((x) == '\r') || ((x) == '\n') || \
-                         ((x) == '\t') || ((x) == '\b'))
-#endif
-#endif /* _KERNEL */
-
-#if MP_DEBUG
-#undef MP_IOFUNC
-#define MP_IOFUNC 1
-#endif
-
-#if MP_IOFUNC
-#include <stdio.h>
-#include <ctype.h>
-#endif
-
-#ifndef _KERNEL
-#include <limits.h>
-#endif
-
-#if defined(BSDI)
-#undef ULLONG_MAX
-#endif
-
-#if defined( macintosh )
-#include <Types.h>
-#elif defined( _WIN32_WCE)
-/* #include <sys/types.h> What do we need here ?? */
-#else
-#include <sys/types.h>
-#endif
-
-#define  MP_NEG    1
-#define  MP_ZPOS   0
-
-#define  MP_OKAY          0 /* no error, all is well */
-#define  MP_YES           0 /* yes (boolean result)  */
-#define  MP_NO           -1 /* no (boolean result)   */
-#define  MP_MEM          -2 /* out of memory         */
-#define  MP_RANGE        -3 /* argument out of range */
-#define  MP_BADARG       -4 /* invalid parameter     */
-#define  MP_UNDEF        -5 /* answer is undefined   */
-#define  MP_LAST_CODE    MP_UNDEF
-
-typedef unsigned int      mp_sign;
-typedef unsigned int      mp_size;
-typedef int               mp_err;
-typedef int               mp_flag;
-
-#define MP_32BIT_MAX 4294967295U
-
-#if !defined(ULONG_MAX)
-#error "ULONG_MAX not defined"
-#elif !defined(UINT_MAX)
-#error "UINT_MAX not defined"
-#elif !defined(USHRT_MAX)
-#error "USHRT_MAX not defined"
-#endif
-
-#if defined(ULONG_LONG_MAX)                     /* GCC, HPUX */
-#define MP_ULONG_LONG_MAX ULONG_LONG_MAX
-#elif defined(ULLONG_MAX)                       /* Solaris */
-#define MP_ULONG_LONG_MAX ULLONG_MAX
-/* MP_ULONG_LONG_MAX was defined to be ULLONG_MAX */
-#elif defined(ULONGLONG_MAX)                    /* IRIX, AIX */
-#define MP_ULONG_LONG_MAX ULONGLONG_MAX
-#endif
-
-/* We only use unsigned long for mp_digit iff long is more than 32 bits. */
-#if !defined(MP_USE_UINT_DIGIT) && ULONG_MAX > MP_32BIT_MAX
-typedef unsigned long     mp_digit;
-#define MP_DIGIT_MAX      ULONG_MAX
-#define MP_DIGIT_FMT      "%016lX"   /* printf() format for 1 digit */
-#define MP_HALF_DIGIT_MAX UINT_MAX
-#undef  MP_NO_MP_WORD
-#define MP_NO_MP_WORD 1
-#undef  MP_USE_LONG_DIGIT
-#define MP_USE_LONG_DIGIT 1
-#undef  MP_USE_LONG_LONG_DIGIT
-
-#elif !defined(MP_USE_UINT_DIGIT) && defined(MP_ULONG_LONG_MAX)
-typedef unsigned long long mp_digit;
-#define MP_DIGIT_MAX       MP_ULONG_LONG_MAX
-#define MP_DIGIT_FMT      "%016llX"  /* printf() format for 1 digit */
-#define MP_HALF_DIGIT_MAX  UINT_MAX
-#undef  MP_NO_MP_WORD
-#define MP_NO_MP_WORD 1
-#undef  MP_USE_LONG_LONG_DIGIT
-#define MP_USE_LONG_LONG_DIGIT 1
-#undef  MP_USE_LONG_DIGIT
-
-#else
-typedef unsigned int      mp_digit;
-#define MP_DIGIT_MAX      UINT_MAX
-#define MP_DIGIT_FMT      "%08X"     /* printf() format for 1 digit */
-#define MP_HALF_DIGIT_MAX USHRT_MAX
-#undef  MP_USE_UINT_DIGIT
-#define MP_USE_UINT_DIGIT 1
-#undef  MP_USE_LONG_LONG_DIGIT
-#undef  MP_USE_LONG_DIGIT
-#endif
-
-#if !defined(MP_NO_MP_WORD)
-#if  defined(MP_USE_UINT_DIGIT) && \
-    (defined(MP_ULONG_LONG_MAX) || (ULONG_MAX > UINT_MAX))
-
-#if (ULONG_MAX > UINT_MAX)
-typedef unsigned long     mp_word;
-typedef          long     mp_sword;
-#define MP_WORD_MAX       ULONG_MAX
-
-#else
-typedef unsigned long long mp_word;
-typedef          long long mp_sword;
-#define MP_WORD_MAX       MP_ULONG_LONG_MAX
-#endif
-
-#else
-#define MP_NO_MP_WORD 1
-#endif
-#endif /* !defined(MP_NO_MP_WORD) */
-
-#if !defined(MP_WORD_MAX) && defined(MP_DEFINE_SMALL_WORD)
-typedef unsigned int      mp_word;
-typedef          int      mp_sword;
-#define MP_WORD_MAX       UINT_MAX
-#endif
-
-#ifndef CHAR_BIT
-#define CHAR_BIT 8
-#endif
-
-#define MP_DIGIT_BIT      (CHAR_BIT*sizeof(mp_digit))
-#define MP_WORD_BIT       (CHAR_BIT*sizeof(mp_word))
-#define MP_RADIX          (1+(mp_word)MP_DIGIT_MAX)
-
-#define MP_HALF_DIGIT_BIT (MP_DIGIT_BIT/2)
-#define MP_HALF_RADIX     (1+(mp_digit)MP_HALF_DIGIT_MAX)
-/* MP_HALF_RADIX really ought to be called MP_SQRT_RADIX, but it's named
-** MP_HALF_RADIX because it's the radix for MP_HALF_DIGITs, and it's
-** consistent with the other _HALF_ names.
-*/
-
-
-/* Macros for accessing the mp_int internals           */
-#define  MP_FLAG(MP)     ((MP)->flag)
-#define  MP_SIGN(MP)     ((MP)->sign)
-#define  MP_USED(MP)     ((MP)->used)
-#define  MP_ALLOC(MP)    ((MP)->alloc)
-#define  MP_DIGITS(MP)   ((MP)->dp)
-#define  MP_DIGIT(MP,N)  (MP)->dp[(N)]
-
-/* This defines the maximum I/O base (minimum is 2)   */
-#define MP_MAX_RADIX         64
-
-typedef struct {
-  mp_sign       flag;    /* KM_SLEEP/KM_NOSLEEP        */
-  mp_sign       sign;    /* sign of this quantity      */
-  mp_size       alloc;   /* how many digits allocated  */
-  mp_size       used;    /* how many digits used       */
-  mp_digit     *dp;      /* the digits themselves      */
-} mp_int;
-
-/* Default precision       */
-mp_size mp_get_prec(void);
-void    mp_set_prec(mp_size prec);
-
-/* Memory management       */
-mp_err mp_init(mp_int *mp, int kmflag);
-mp_err mp_init_size(mp_int *mp, mp_size prec, int kmflag);
-mp_err mp_init_copy(mp_int *mp, const mp_int *from);
-mp_err mp_copy(const mp_int *from, mp_int *to);
-void   mp_exch(mp_int *mp1, mp_int *mp2);
-void   mp_clear(mp_int *mp);
-void   mp_zero(mp_int *mp);
-void   mp_set(mp_int *mp, mp_digit d);
-mp_err mp_set_int(mp_int *mp, long z);
-#define mp_set_long(mp,z) mp_set_int(mp,z)
-mp_err mp_set_ulong(mp_int *mp, unsigned long z);
-
-/* Single digit arithmetic */
-mp_err mp_add_d(const mp_int *a, mp_digit d, mp_int *b);
-mp_err mp_sub_d(const mp_int *a, mp_digit d, mp_int *b);
-mp_err mp_mul_d(const mp_int *a, mp_digit d, mp_int *b);
-mp_err mp_mul_2(const mp_int *a, mp_int *c);
-mp_err mp_div_d(const mp_int *a, mp_digit d, mp_int *q, mp_digit *r);
-mp_err mp_div_2(const mp_int *a, mp_int *c);
-mp_err mp_expt_d(const mp_int *a, mp_digit d, mp_int *c);
-
-/* Sign manipulations      */
-mp_err mp_abs(const mp_int *a, mp_int *b);
-mp_err mp_neg(const mp_int *a, mp_int *b);
-
-/* Full arithmetic         */
-mp_err mp_add(const mp_int *a, const mp_int *b, mp_int *c);
-mp_err mp_sub(const mp_int *a, const mp_int *b, mp_int *c);
-mp_err mp_mul(const mp_int *a, const mp_int *b, mp_int *c);
-#if MP_SQUARE
-mp_err mp_sqr(const mp_int *a, mp_int *b);
-#else
-#define mp_sqr(a, b) mp_mul(a, a, b)
-#endif
-mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *q, mp_int *r);
-mp_err mp_div_2d(const mp_int *a, mp_digit d, mp_int *q, mp_int *r);
-mp_err mp_expt(mp_int *a, mp_int *b, mp_int *c);
-mp_err mp_2expt(mp_int *a, mp_digit k);
-mp_err mp_sqrt(const mp_int *a, mp_int *b);
-
-/* Modular arithmetic      */
-#if MP_MODARITH
-mp_err mp_mod(const mp_int *a, const mp_int *m, mp_int *c);
-mp_err mp_mod_d(const mp_int *a, mp_digit d, mp_digit *c);
-mp_err mp_addmod(const mp_int *a, const mp_int *b, const mp_int *m, mp_int *c);
-mp_err mp_submod(const mp_int *a, const mp_int *b, const mp_int *m, mp_int *c);
-mp_err mp_mulmod(const mp_int *a, const mp_int *b, const mp_int *m, mp_int *c);
-#if MP_SQUARE
-mp_err mp_sqrmod(const mp_int *a, const mp_int *m, mp_int *c);
-#else
-#define mp_sqrmod(a, m, c) mp_mulmod(a, a, m, c)
-#endif
-mp_err mp_exptmod(const mp_int *a, const mp_int *b, const mp_int *m, mp_int *c);
-mp_err mp_exptmod_d(const mp_int *a, mp_digit d, const mp_int *m, mp_int *c);
-#endif /* MP_MODARITH */
-
-/* Comparisons             */
-int    mp_cmp_z(const mp_int *a);
-int    mp_cmp_d(const mp_int *a, mp_digit d);
-int    mp_cmp(const mp_int *a, const mp_int *b);
-int    mp_cmp_mag(mp_int *a, mp_int *b);
-int    mp_cmp_int(const mp_int *a, long z, int kmflag);
-int    mp_isodd(const mp_int *a);
-int    mp_iseven(const mp_int *a);
-
-/* Number theoretic        */
-#if MP_NUMTH
-mp_err mp_gcd(mp_int *a, mp_int *b, mp_int *c);
-mp_err mp_lcm(mp_int *a, mp_int *b, mp_int *c);
-mp_err mp_xgcd(const mp_int *a, const mp_int *b, mp_int *g, mp_int *x, mp_int *y);
-mp_err mp_invmod(const mp_int *a, const mp_int *m, mp_int *c);
-mp_err mp_invmod_xgcd(const mp_int *a, const mp_int *m, mp_int *c);
-#endif /* end MP_NUMTH */
-
-/* Input and output        */
-#if MP_IOFUNC
-void   mp_print(mp_int *mp, FILE *ofp);
-#endif /* end MP_IOFUNC */
-
-/* Base conversion         */
-mp_err mp_read_raw(mp_int *mp, char *str, int len);
-int    mp_raw_size(mp_int *mp);
-mp_err mp_toraw(mp_int *mp, char *str);
-mp_err mp_read_radix(mp_int *mp, const char *str, int radix);
-mp_err mp_read_variable_radix(mp_int *a, const char * str, int default_radix);
-int    mp_radix_size(mp_int *mp, int radix);
-mp_err mp_toradix(mp_int *mp, char *str, int radix);
-int    mp_tovalue(char ch, int r);
-
-#define mp_tobinary(M, S)  mp_toradix((M), (S), 2)
-#define mp_tooctal(M, S)   mp_toradix((M), (S), 8)
-#define mp_todecimal(M, S) mp_toradix((M), (S), 10)
-#define mp_tohex(M, S)     mp_toradix((M), (S), 16)
-
-/* Error strings           */
-const  char  *mp_strerror(mp_err ec);
-
-/* Octet string conversion functions */
-mp_err mp_read_unsigned_octets(mp_int *mp, const unsigned char *str, mp_size len);
-int    mp_unsigned_octet_size(const mp_int *mp);
-mp_err mp_to_unsigned_octets(const mp_int *mp, unsigned char *str, mp_size maxlen);
-mp_err mp_to_signed_octets(const mp_int *mp, unsigned char *str, mp_size maxlen);
-mp_err mp_to_fixlen_octets(const mp_int *mp, unsigned char *str, mp_size len);
-
-/* Miscellaneous */
-mp_size mp_trailing_zeros(const mp_int *mp);
-
-#define MP_CHECKOK(x)  if (MP_OKAY > (res = (x))) goto CLEANUP
-#define MP_CHECKERR(x) if (MP_OKAY > (res = (x))) goto CLEANUP
-
-#if defined(MP_API_COMPATIBLE)
-#define NEG             MP_NEG
-#define ZPOS            MP_ZPOS
-#define DIGIT_MAX       MP_DIGIT_MAX
-#define DIGIT_BIT       MP_DIGIT_BIT
-#define DIGIT_FMT       MP_DIGIT_FMT
-#define RADIX           MP_RADIX
-#define MAX_RADIX       MP_MAX_RADIX
-#define FLAG(MP)        MP_FLAG(MP)
-#define SIGN(MP)        MP_SIGN(MP)
-#define USED(MP)        MP_USED(MP)
-#define ALLOC(MP)       MP_ALLOC(MP)
-#define DIGITS(MP)      MP_DIGITS(MP)
-#define DIGIT(MP,N)     MP_DIGIT(MP,N)
-
-#if MP_ARGCHK == 1
-#define  ARGCHK(X,Y)  {if(!(X)){return (Y);}}
-#elif MP_ARGCHK == 2
-#ifdef _KERNEL
-#define  ARGCHK(X,Y)  ASSERT(X)
-#else
-#include <assert.h>
-#define  ARGCHK(X,Y)  assert(X)
-#endif
-#else
-#define  ARGCHK(X,Y)  /*  */
-#endif
-#endif /* defined MP_API_COMPATIBLE */
-
-#endif /* _MPI_H */
--- a/jdk/src/share/native/sun/security/ec/mplogic.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,242 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- *
- *  Bitwise logical operations on MPI values
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the MPI Arbitrary Precision Integer Arithmetic library.
- *
- * The Initial Developer of the Original Code is
- * Michael J. Fromberger.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-/* $Id: mplogic.c,v 1.15 2004/04/27 23:04:36 gerv%gerv.net Exp $ */
-
-#include "mpi-priv.h"
-#include "mplogic.h"
-
-/* {{{ Lookup table for population count */
-
-static unsigned char bitc[] = {
-   0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
-   1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
-   1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
-   2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
-   1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
-   2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
-   2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
-   3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
-   1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
-   2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
-   2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
-   3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
-   2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
-   3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
-   3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
-   4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
-};
-
-/* }}} */
-
-/*
-  mpl_rsh(a, b, d)     - b = a >> d
-  mpl_lsh(a, b, d)     - b = a << d
- */
-
-/* {{{ mpl_rsh(a, b, d) */
-
-mp_err mpl_rsh(const mp_int *a, mp_int *b, mp_digit d)
-{
-  mp_err   res;
-
-  ARGCHK(a != NULL && b != NULL, MP_BADARG);
-
-  if((res = mp_copy(a, b)) != MP_OKAY)
-    return res;
-
-  s_mp_div_2d(b, d);
-
-  return MP_OKAY;
-
-} /* end mpl_rsh() */
-
-/* }}} */
-
-/* {{{ mpl_lsh(a, b, d) */
-
-mp_err mpl_lsh(const mp_int *a, mp_int *b, mp_digit d)
-{
-  mp_err   res;
-
-  ARGCHK(a != NULL && b != NULL, MP_BADARG);
-
-  if((res = mp_copy(a, b)) != MP_OKAY)
-    return res;
-
-  return s_mp_mul_2d(b, d);
-
-} /* end mpl_lsh() */
-
-/* }}} */
-
-/*------------------------------------------------------------------------*/
-/*
-  mpl_set_bit
-
-  Returns MP_OKAY or some error code.
-  Grows a if needed to set a bit to 1.
- */
-mp_err mpl_set_bit(mp_int *a, mp_size bitNum, mp_size value)
-{
-  mp_size      ix;
-  mp_err       rv;
-  mp_digit     mask;
-
-  ARGCHK(a != NULL, MP_BADARG);
-
-  ix = bitNum / MP_DIGIT_BIT;
-  if (ix + 1 > MP_USED(a)) {
-    rv = s_mp_pad(a, ix + 1);
-    if (rv != MP_OKAY)
-      return rv;
-  }
-
-  bitNum = bitNum % MP_DIGIT_BIT;
-  mask = (mp_digit)1 << bitNum;
-  if (value)
-    MP_DIGIT(a,ix) |= mask;
-  else
-    MP_DIGIT(a,ix) &= ~mask;
-  s_mp_clamp(a);
-  return MP_OKAY;
-}
-
-/*
-  mpl_get_bit
-
-  returns 0 or 1 or some (negative) error code.
- */
-mp_err mpl_get_bit(const mp_int *a, mp_size bitNum)
-{
-  mp_size      bit, ix;
-  mp_err       rv;
-
-  ARGCHK(a != NULL, MP_BADARG);
-
-  ix = bitNum / MP_DIGIT_BIT;
-  ARGCHK(ix <= MP_USED(a) - 1, MP_RANGE);
-
-  bit   = bitNum % MP_DIGIT_BIT;
-  rv = (mp_err)(MP_DIGIT(a, ix) >> bit) & 1;
-  return rv;
-}
-
-/*
-  mpl_get_bits
-  - Extracts numBits bits from a, where the least significant extracted bit
-  is bit lsbNum.  Returns a negative value if error occurs.
-  - Because sign bit is used to indicate error, maximum number of bits to
-  be returned is the lesser of (a) the number of bits in an mp_digit, or
-  (b) one less than the number of bits in an mp_err.
-  - lsbNum + numbits can be greater than the number of significant bits in
-  integer a, as long as bit lsbNum is in the high order digit of a.
- */
-mp_err mpl_get_bits(const mp_int *a, mp_size lsbNum, mp_size numBits)
-{
-  mp_size    rshift = (lsbNum % MP_DIGIT_BIT);
-  mp_size    lsWndx = (lsbNum / MP_DIGIT_BIT);
-  mp_digit * digit  = MP_DIGITS(a) + lsWndx;
-  mp_digit   mask   = ((1 << numBits) - 1);
-
-  ARGCHK(numBits < CHAR_BIT * sizeof mask, MP_BADARG);
-  ARGCHK(MP_HOWMANY(lsbNum, MP_DIGIT_BIT) <= MP_USED(a), MP_RANGE);
-
-  if ((numBits + lsbNum % MP_DIGIT_BIT <= MP_DIGIT_BIT) ||
-      (lsWndx + 1 >= MP_USED(a))) {
-    mask &= (digit[0] >> rshift);
-  } else {
-    mask &= ((digit[0] >> rshift) | (digit[1] << (MP_DIGIT_BIT - rshift)));
-  }
-  return (mp_err)mask;
-}
-
-/*
-  mpl_significant_bits
-  returns number of significnant bits in abs(a).
-  returns 1 if value is zero.
- */
-mp_err mpl_significant_bits(const mp_int *a)
-{
-  mp_err bits   = 0;
-  int    ix;
-
-  ARGCHK(a != NULL, MP_BADARG);
-
-  ix = MP_USED(a);
-  for (ix = MP_USED(a); ix > 0; ) {
-    mp_digit d;
-    d = MP_DIGIT(a, --ix);
-    if (d) {
-      while (d) {
-        ++bits;
-        d >>= 1;
-      }
-      break;
-    }
-  }
-  bits += ix * MP_DIGIT_BIT;
-  if (!bits)
-    bits = 1;
-  return bits;
-}
-
-/*------------------------------------------------------------------------*/
-/* HERE THERE BE DRAGONS                                                  */
--- a/jdk/src/share/native/sun/security/ec/mplogic.h	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,105 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- *
- *  Bitwise logical operations on MPI values
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the MPI Arbitrary Precision Integer Arithmetic library.
- *
- * The Initial Developer of the Original Code is
- * Michael J. Fromberger.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _MPLOGIC_H
-#define _MPLOGIC_H
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-/* $Id: mplogic.h,v 1.7 2004/04/27 23:04:36 gerv%gerv.net Exp $ */
-
-#include "mpi.h"
-
-/*
-  The logical operations treat an mp_int as if it were a bit vector,
-  without regard to its sign (an mp_int is represented in a signed
-  magnitude format).  Values are treated as if they had an infinite
-  string of zeros left of the most-significant bit.
- */
-
-/* Parity results                    */
-
-#define MP_EVEN       MP_YES
-#define MP_ODD        MP_NO
-
-/* Bitwise functions                 */
-
-mp_err mpl_not(mp_int *a, mp_int *b);            /* one's complement  */
-mp_err mpl_and(mp_int *a, mp_int *b, mp_int *c); /* bitwise AND       */
-mp_err mpl_or(mp_int *a, mp_int *b, mp_int *c);  /* bitwise OR        */
-mp_err mpl_xor(mp_int *a, mp_int *b, mp_int *c); /* bitwise XOR       */
-
-/* Shift functions                   */
-
-mp_err mpl_rsh(const mp_int *a, mp_int *b, mp_digit d);   /* right shift    */
-mp_err mpl_lsh(const mp_int *a, mp_int *b, mp_digit d);   /* left shift     */
-
-/* Bit count and parity              */
-
-mp_err mpl_num_set(mp_int *a, int *num);         /* count set bits    */
-mp_err mpl_num_clear(mp_int *a, int *num);       /* count clear bits  */
-mp_err mpl_parity(mp_int *a);                    /* determine parity  */
-
-/* Get & Set the value of a bit */
-
-mp_err mpl_set_bit(mp_int *a, mp_size bitNum, mp_size value);
-mp_err mpl_get_bit(const mp_int *a, mp_size bitNum);
-mp_err mpl_get_bits(const mp_int *a, mp_size lsbNum, mp_size numBits);
-mp_err mpl_significant_bits(const mp_int *a);
-
-#endif /* _MPLOGIC_H */
--- a/jdk/src/share/native/sun/security/ec/mpmontg.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,199 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Netscape security libraries.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2000
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Sheueling Chang Shantz <sheueling.chang@sun.com>,
- *   Stephen Fung <stephen.fung@sun.com>, and
- *   Douglas Stebila <douglas@stebila.ca> of Sun Laboratories.
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-/* $Id: mpmontg.c,v 1.20 2006/08/29 02:41:38 nelson%bolyard.com Exp $ */
-
-/* This file implements moduluar exponentiation using Montgomery's
- * method for modular reduction.  This file implements the method
- * described as "Improvement 1" in the paper "A Cryptogrpahic Library for
- * the Motorola DSP56000" by Stephen R. Dusse' and Burton S. Kaliski Jr.
- * published in "Advances in Cryptology: Proceedings of EUROCRYPT '90"
- * "Lecture Notes in Computer Science" volume 473, 1991, pg 230-244,
- * published by Springer Verlag.
- */
-
-#define MP_USING_CACHE_SAFE_MOD_EXP 1
-#ifndef _KERNEL
-#include <string.h>
-#include <stddef.h> /* ptrdiff_t */
-#endif
-#include "mpi-priv.h"
-#include "mplogic.h"
-#include "mpprime.h"
-#ifdef MP_USING_MONT_MULF
-#include "montmulf.h"
-#endif
-
-/* if MP_CHAR_STORE_SLOW is defined, we  */
-/* need to know endianness of this platform. */
-#ifdef MP_CHAR_STORE_SLOW
-#if !defined(MP_IS_BIG_ENDIAN) && !defined(MP_IS_LITTLE_ENDIAN)
-#error "You must define MP_IS_BIG_ENDIAN or MP_IS_LITTLE_ENDIAN\n" \
-       "  if you define MP_CHAR_STORE_SLOW."
-#endif
-#endif
-
-#ifndef STATIC
-#define STATIC
-#endif
-
-#define MAX_ODD_INTS    32   /* 2 ** (WINDOW_BITS - 1) */
-
-#ifndef _KERNEL
-#if defined(_WIN32_WCE)
-#define ABORT  res = MP_UNDEF; goto CLEANUP
-#else
-#define ABORT abort()
-#endif
-#else
-#define ABORT  res = MP_UNDEF; goto CLEANUP
-#endif /* _KERNEL */
-
-/* computes T = REDC(T), 2^b == R */
-mp_err s_mp_redc(mp_int *T, mp_mont_modulus *mmm)
-{
-  mp_err res;
-  mp_size i;
-
-  i = MP_USED(T) + MP_USED(&mmm->N) + 2;
-  MP_CHECKOK( s_mp_pad(T, i) );
-  for (i = 0; i < MP_USED(&mmm->N); ++i ) {
-    mp_digit m_i = MP_DIGIT(T, i) * mmm->n0prime;
-    /* T += N * m_i * (MP_RADIX ** i); */
-    MP_CHECKOK( s_mp_mul_d_add_offset(&mmm->N, m_i, T, i) );
-  }
-  s_mp_clamp(T);
-
-  /* T /= R */
-  s_mp_div_2d(T, mmm->b);
-
-  if ((res = s_mp_cmp(T, &mmm->N)) >= 0) {
-    /* T = T - N */
-    MP_CHECKOK( s_mp_sub(T, &mmm->N) );
-#ifdef DEBUG
-    if ((res = mp_cmp(T, &mmm->N)) >= 0) {
-      res = MP_UNDEF;
-      goto CLEANUP;
-    }
-#endif
-  }
-  res = MP_OKAY;
-CLEANUP:
-  return res;
-}
-
-#if !defined(MP_ASSEMBLY_MUL_MONT) && !defined(MP_MONT_USE_MP_MUL)
-mp_err s_mp_mul_mont(const mp_int *a, const mp_int *b, mp_int *c,
-                   mp_mont_modulus *mmm)
-{
-  mp_digit *pb;
-  mp_digit m_i;
-  mp_err   res;
-  mp_size  ib;
-  mp_size  useda, usedb;
-
-  ARGCHK(a != NULL && b != NULL && c != NULL, MP_BADARG);
-
-  if (MP_USED(a) < MP_USED(b)) {
-    const mp_int *xch = b;      /* switch a and b, to do fewer outer loops */
-    b = a;
-    a = xch;
-  }
-
-  MP_USED(c) = 1; MP_DIGIT(c, 0) = 0;
-  ib = MP_USED(a) + MP_MAX(MP_USED(b), MP_USED(&mmm->N)) + 2;
-  if((res = s_mp_pad(c, ib)) != MP_OKAY)
-    goto CLEANUP;
-
-  useda = MP_USED(a);
-  pb = MP_DIGITS(b);
-  s_mpv_mul_d(MP_DIGITS(a), useda, *pb++, MP_DIGITS(c));
-  s_mp_setz(MP_DIGITS(c) + useda + 1, ib - (useda + 1));
-  m_i = MP_DIGIT(c, 0) * mmm->n0prime;
-  s_mp_mul_d_add_offset(&mmm->N, m_i, c, 0);
-
-  /* Outer loop:  Digits of b */
-  usedb = MP_USED(b);
-  for (ib = 1; ib < usedb; ib++) {
-    mp_digit b_i    = *pb++;
-
-    /* Inner product:  Digits of a */
-    if (b_i)
-      s_mpv_mul_d_add_prop(MP_DIGITS(a), useda, b_i, MP_DIGITS(c) + ib);
-    m_i = MP_DIGIT(c, ib) * mmm->n0prime;
-    s_mp_mul_d_add_offset(&mmm->N, m_i, c, ib);
-  }
-  if (usedb < MP_USED(&mmm->N)) {
-    for (usedb = MP_USED(&mmm->N); ib < usedb; ++ib ) {
-      m_i = MP_DIGIT(c, ib) * mmm->n0prime;
-      s_mp_mul_d_add_offset(&mmm->N, m_i, c, ib);
-    }
-  }
-  s_mp_clamp(c);
-  s_mp_div_2d(c, mmm->b);
-  if (s_mp_cmp(c, &mmm->N) >= 0) {
-    MP_CHECKOK( s_mp_sub(c, &mmm->N) );
-  }
-  res = MP_OKAY;
-
-CLEANUP:
-  return res;
-}
-#endif
--- a/jdk/src/share/native/sun/security/ec/mpprime.h	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,89 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- *
- *  Utilities for finding and working with prime and pseudo-prime
- *  integers
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the MPI Arbitrary Precision Integer Arithmetic library.
- *
- * The Initial Developer of the Original Code is
- * Michael J. Fromberger.
- * Portions created by the Initial Developer are Copyright (C) 1997
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _MP_PRIME_H
-#define _MP_PRIME_H
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include "mpi.h"
-
-extern const int prime_tab_size;   /* number of primes available */
-extern const mp_digit prime_tab[];
-
-/* Tests for divisibility    */
-mp_err  mpp_divis(mp_int *a, mp_int *b);
-mp_err  mpp_divis_d(mp_int *a, mp_digit d);
-
-/* Random selection          */
-mp_err  mpp_random(mp_int *a);
-mp_err  mpp_random_size(mp_int *a, mp_size prec);
-
-/* Pseudo-primality testing  */
-mp_err  mpp_divis_vector(mp_int *a, const mp_digit *vec, int size, int *which);
-mp_err  mpp_divis_primes(mp_int *a, mp_digit *np);
-mp_err  mpp_fermat(mp_int *a, mp_digit w);
-mp_err mpp_fermat_list(mp_int *a, const mp_digit *primes, mp_size nPrimes);
-mp_err  mpp_pprime(mp_int *a, int nt);
-mp_err mpp_sieve(mp_int *trial, const mp_digit *primes, mp_size nPrimes,
-                 unsigned char *sieve, mp_size nSieve);
-mp_err mpp_make_prime(mp_int *start, mp_size nBits, mp_size strong,
-                      unsigned long * nTries);
-
-#endif /* _MP_PRIME_H */
--- a/jdk/src/share/native/sun/security/ec/oid.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,473 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Netscape security libraries.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1994-2000
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-#include <sys/types.h>
-
-#ifndef _WIN32
-#ifndef __linux__
-#include <sys/systm.h>
-#endif /* __linux__ */
-#include <sys/param.h>
-#endif /* _WIN32 */
-
-#ifdef _KERNEL
-#include <sys/kmem.h>
-#else
-#include <string.h>
-#endif
-#include "ec.h"
-#include "ecl-curve.h"
-#include "ecc_impl.h"
-#include "secoidt.h"
-
-#define CERTICOM_OID            0x2b, 0x81, 0x04
-#define SECG_OID                CERTICOM_OID, 0x00
-
-#define ANSI_X962_OID           0x2a, 0x86, 0x48, 0xce, 0x3d
-#define ANSI_X962_CURVE_OID     ANSI_X962_OID, 0x03
-#define ANSI_X962_GF2m_OID      ANSI_X962_CURVE_OID, 0x00
-#define ANSI_X962_GFp_OID       ANSI_X962_CURVE_OID, 0x01
-
-#define CONST_OID static const unsigned char
-
-/* ANSI X9.62 prime curve OIDs */
-/* NOTE: prime192v1 is the same as secp192r1, prime256v1 is the
- * same as secp256r1
- */
-CONST_OID ansiX962prime192v1[] = { ANSI_X962_GFp_OID, 0x01 };
-CONST_OID ansiX962prime192v2[] = { ANSI_X962_GFp_OID, 0x02 };
-CONST_OID ansiX962prime192v3[] = { ANSI_X962_GFp_OID, 0x03 };
-CONST_OID ansiX962prime239v1[] = { ANSI_X962_GFp_OID, 0x04 };
-CONST_OID ansiX962prime239v2[] = { ANSI_X962_GFp_OID, 0x05 };
-CONST_OID ansiX962prime239v3[] = { ANSI_X962_GFp_OID, 0x06 };
-CONST_OID ansiX962prime256v1[] = { ANSI_X962_GFp_OID, 0x07 };
-
-/* SECG prime curve OIDs */
-CONST_OID secgECsecp112r1[] = { SECG_OID, 0x06 };
-CONST_OID secgECsecp112r2[] = { SECG_OID, 0x07 };
-CONST_OID secgECsecp128r1[] = { SECG_OID, 0x1c };
-CONST_OID secgECsecp128r2[] = { SECG_OID, 0x1d };
-CONST_OID secgECsecp160k1[] = { SECG_OID, 0x09 };
-CONST_OID secgECsecp160r1[] = { SECG_OID, 0x08 };
-CONST_OID secgECsecp160r2[] = { SECG_OID, 0x1e };
-CONST_OID secgECsecp192k1[] = { SECG_OID, 0x1f };
-CONST_OID secgECsecp224k1[] = { SECG_OID, 0x20 };
-CONST_OID secgECsecp224r1[] = { SECG_OID, 0x21 };
-CONST_OID secgECsecp256k1[] = { SECG_OID, 0x0a };
-CONST_OID secgECsecp384r1[] = { SECG_OID, 0x22 };
-CONST_OID secgECsecp521r1[] = { SECG_OID, 0x23 };
-
-/* SECG characterisitic two curve OIDs */
-CONST_OID secgECsect113r1[] = {SECG_OID, 0x04 };
-CONST_OID secgECsect113r2[] = {SECG_OID, 0x05 };
-CONST_OID secgECsect131r1[] = {SECG_OID, 0x16 };
-CONST_OID secgECsect131r2[] = {SECG_OID, 0x17 };
-CONST_OID secgECsect163k1[] = {SECG_OID, 0x01 };
-CONST_OID secgECsect163r1[] = {SECG_OID, 0x02 };
-CONST_OID secgECsect163r2[] = {SECG_OID, 0x0f };
-CONST_OID secgECsect193r1[] = {SECG_OID, 0x18 };
-CONST_OID secgECsect193r2[] = {SECG_OID, 0x19 };
-CONST_OID secgECsect233k1[] = {SECG_OID, 0x1a };
-CONST_OID secgECsect233r1[] = {SECG_OID, 0x1b };
-CONST_OID secgECsect239k1[] = {SECG_OID, 0x03 };
-CONST_OID secgECsect283k1[] = {SECG_OID, 0x10 };
-CONST_OID secgECsect283r1[] = {SECG_OID, 0x11 };
-CONST_OID secgECsect409k1[] = {SECG_OID, 0x24 };
-CONST_OID secgECsect409r1[] = {SECG_OID, 0x25 };
-CONST_OID secgECsect571k1[] = {SECG_OID, 0x26 };
-CONST_OID secgECsect571r1[] = {SECG_OID, 0x27 };
-
-/* ANSI X9.62 characteristic two curve OIDs */
-CONST_OID ansiX962c2pnb163v1[] = { ANSI_X962_GF2m_OID, 0x01 };
-CONST_OID ansiX962c2pnb163v2[] = { ANSI_X962_GF2m_OID, 0x02 };
-CONST_OID ansiX962c2pnb163v3[] = { ANSI_X962_GF2m_OID, 0x03 };
-CONST_OID ansiX962c2pnb176v1[] = { ANSI_X962_GF2m_OID, 0x04 };
-CONST_OID ansiX962c2tnb191v1[] = { ANSI_X962_GF2m_OID, 0x05 };
-CONST_OID ansiX962c2tnb191v2[] = { ANSI_X962_GF2m_OID, 0x06 };
-CONST_OID ansiX962c2tnb191v3[] = { ANSI_X962_GF2m_OID, 0x07 };
-CONST_OID ansiX962c2onb191v4[] = { ANSI_X962_GF2m_OID, 0x08 };
-CONST_OID ansiX962c2onb191v5[] = { ANSI_X962_GF2m_OID, 0x09 };
-CONST_OID ansiX962c2pnb208w1[] = { ANSI_X962_GF2m_OID, 0x0a };
-CONST_OID ansiX962c2tnb239v1[] = { ANSI_X962_GF2m_OID, 0x0b };
-CONST_OID ansiX962c2tnb239v2[] = { ANSI_X962_GF2m_OID, 0x0c };
-CONST_OID ansiX962c2tnb239v3[] = { ANSI_X962_GF2m_OID, 0x0d };
-CONST_OID ansiX962c2onb239v4[] = { ANSI_X962_GF2m_OID, 0x0e };
-CONST_OID ansiX962c2onb239v5[] = { ANSI_X962_GF2m_OID, 0x0f };
-CONST_OID ansiX962c2pnb272w1[] = { ANSI_X962_GF2m_OID, 0x10 };
-CONST_OID ansiX962c2pnb304w1[] = { ANSI_X962_GF2m_OID, 0x11 };
-CONST_OID ansiX962c2tnb359v1[] = { ANSI_X962_GF2m_OID, 0x12 };
-CONST_OID ansiX962c2pnb368w1[] = { ANSI_X962_GF2m_OID, 0x13 };
-CONST_OID ansiX962c2tnb431r1[] = { ANSI_X962_GF2m_OID, 0x14 };
-
-#define OI(x) { siDEROID, (unsigned char *)x, sizeof x }
-#ifndef SECOID_NO_STRINGS
-#define OD(oid,tag,desc,mech,ext) { OI(oid), tag, desc, mech, ext }
-#else
-#define OD(oid,tag,desc,mech,ext) { OI(oid), tag, 0, mech, ext }
-#endif
-
-#define CKM_INVALID_MECHANISM 0xffffffffUL
-
-/* XXX this is incorrect */
-#define INVALID_CERT_EXTENSION 1
-
-#define CKM_ECDSA                      0x00001041
-#define CKM_ECDSA_SHA1                 0x00001042
-#define CKM_ECDH1_DERIVE               0x00001050
-
-static SECOidData ANSI_prime_oids[] = {
-    { { siDEROID, NULL, 0 }, ECCurve_noName,
-        "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
-
-    OD( ansiX962prime192v1, ECCurve_NIST_P192,
-        "ANSI X9.62 elliptic curve prime192v1 (aka secp192r1, NIST P-192)",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( ansiX962prime192v2, ECCurve_X9_62_PRIME_192V2,
-        "ANSI X9.62 elliptic curve prime192v2",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( ansiX962prime192v3, ECCurve_X9_62_PRIME_192V3,
-        "ANSI X9.62 elliptic curve prime192v3",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( ansiX962prime239v1, ECCurve_X9_62_PRIME_239V1,
-        "ANSI X9.62 elliptic curve prime239v1",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( ansiX962prime239v2, ECCurve_X9_62_PRIME_239V2,
-        "ANSI X9.62 elliptic curve prime239v2",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( ansiX962prime239v3, ECCurve_X9_62_PRIME_239V3,
-        "ANSI X9.62 elliptic curve prime239v3",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( ansiX962prime256v1, ECCurve_NIST_P256,
-        "ANSI X9.62 elliptic curve prime256v1 (aka secp256r1, NIST P-256)",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION )
-};
-
-static SECOidData SECG_oids[] = {
-    { { siDEROID, NULL, 0 }, ECCurve_noName,
-        "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
-
-    OD( secgECsect163k1, ECCurve_NIST_K163,
-        "SECG elliptic curve sect163k1 (aka NIST K-163)",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsect163r1, ECCurve_SECG_CHAR2_163R1,
-        "SECG elliptic curve sect163r1",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsect239k1, ECCurve_SECG_CHAR2_239K1,
-        "SECG elliptic curve sect239k1",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsect113r1, ECCurve_SECG_CHAR2_113R1,
-        "SECG elliptic curve sect113r1",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsect113r2, ECCurve_SECG_CHAR2_113R2,
-        "SECG elliptic curve sect113r2",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsecp112r1, ECCurve_SECG_PRIME_112R1,
-        "SECG elliptic curve secp112r1",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsecp112r2, ECCurve_SECG_PRIME_112R2,
-        "SECG elliptic curve secp112r2",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsecp160r1, ECCurve_SECG_PRIME_160R1,
-        "SECG elliptic curve secp160r1",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsecp160k1, ECCurve_SECG_PRIME_160K1,
-        "SECG elliptic curve secp160k1",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsecp256k1, ECCurve_SECG_PRIME_256K1,
-        "SECG elliptic curve secp256k1",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    { { siDEROID, NULL, 0 }, ECCurve_noName,
-        "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
-    { { siDEROID, NULL, 0 }, ECCurve_noName,
-        "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
-    { { siDEROID, NULL, 0 }, ECCurve_noName,
-        "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
-    { { siDEROID, NULL, 0 }, ECCurve_noName,
-        "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
-    OD( secgECsect163r2, ECCurve_NIST_B163,
-        "SECG elliptic curve sect163r2 (aka NIST B-163)",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsect283k1, ECCurve_NIST_K283,
-        "SECG elliptic curve sect283k1 (aka NIST K-283)",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsect283r1, ECCurve_NIST_B283,
-        "SECG elliptic curve sect283r1 (aka NIST B-283)",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    { { siDEROID, NULL, 0 }, ECCurve_noName,
-        "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
-    { { siDEROID, NULL, 0 }, ECCurve_noName,
-        "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
-    { { siDEROID, NULL, 0 }, ECCurve_noName,
-        "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
-    { { siDEROID, NULL, 0 }, ECCurve_noName,
-        "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
-    OD( secgECsect131r1, ECCurve_SECG_CHAR2_131R1,
-        "SECG elliptic curve sect131r1",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsect131r2, ECCurve_SECG_CHAR2_131R2,
-        "SECG elliptic curve sect131r2",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsect193r1, ECCurve_SECG_CHAR2_193R1,
-        "SECG elliptic curve sect193r1",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsect193r2, ECCurve_SECG_CHAR2_193R2,
-        "SECG elliptic curve sect193r2",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsect233k1, ECCurve_NIST_K233,
-        "SECG elliptic curve sect233k1 (aka NIST K-233)",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsect233r1, ECCurve_NIST_B233,
-        "SECG elliptic curve sect233r1 (aka NIST B-233)",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsecp128r1, ECCurve_SECG_PRIME_128R1,
-        "SECG elliptic curve secp128r1",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsecp128r2, ECCurve_SECG_PRIME_128R2,
-        "SECG elliptic curve secp128r2",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsecp160r2, ECCurve_SECG_PRIME_160R2,
-        "SECG elliptic curve secp160r2",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsecp192k1, ECCurve_SECG_PRIME_192K1,
-        "SECG elliptic curve secp192k1",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsecp224k1, ECCurve_SECG_PRIME_224K1,
-        "SECG elliptic curve secp224k1",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsecp224r1, ECCurve_NIST_P224,
-        "SECG elliptic curve secp224r1 (aka NIST P-224)",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsecp384r1, ECCurve_NIST_P384,
-        "SECG elliptic curve secp384r1 (aka NIST P-384)",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsecp521r1, ECCurve_NIST_P521,
-        "SECG elliptic curve secp521r1 (aka NIST P-521)",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsect409k1, ECCurve_NIST_K409,
-        "SECG elliptic curve sect409k1 (aka NIST K-409)",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsect409r1, ECCurve_NIST_B409,
-        "SECG elliptic curve sect409r1 (aka NIST B-409)",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsect571k1, ECCurve_NIST_K571,
-        "SECG elliptic curve sect571k1 (aka NIST K-571)",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( secgECsect571r1, ECCurve_NIST_B571,
-        "SECG elliptic curve sect571r1 (aka NIST B-571)",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION )
-};
-
-static SECOidData ANSI_oids[] = {
-    { { siDEROID, NULL, 0 }, ECCurve_noName,
-        "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
-
-    /* ANSI X9.62 named elliptic curves (characteristic two field) */
-    OD( ansiX962c2pnb163v1, ECCurve_X9_62_CHAR2_PNB163V1,
-        "ANSI X9.62 elliptic curve c2pnb163v1",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( ansiX962c2pnb163v2, ECCurve_X9_62_CHAR2_PNB163V2,
-        "ANSI X9.62 elliptic curve c2pnb163v2",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( ansiX962c2pnb163v3, ECCurve_X9_62_CHAR2_PNB163V3,
-        "ANSI X9.62 elliptic curve c2pnb163v3",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( ansiX962c2pnb176v1, ECCurve_X9_62_CHAR2_PNB176V1,
-        "ANSI X9.62 elliptic curve c2pnb176v1",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( ansiX962c2tnb191v1, ECCurve_X9_62_CHAR2_TNB191V1,
-        "ANSI X9.62 elliptic curve c2tnb191v1",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( ansiX962c2tnb191v2, ECCurve_X9_62_CHAR2_TNB191V2,
-        "ANSI X9.62 elliptic curve c2tnb191v2",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( ansiX962c2tnb191v3, ECCurve_X9_62_CHAR2_TNB191V3,
-        "ANSI X9.62 elliptic curve c2tnb191v3",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    { { siDEROID, NULL, 0 }, ECCurve_noName,
-        "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
-    { { siDEROID, NULL, 0 }, ECCurve_noName,
-        "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
-    OD( ansiX962c2pnb208w1, ECCurve_X9_62_CHAR2_PNB208W1,
-        "ANSI X9.62 elliptic curve c2pnb208w1",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( ansiX962c2tnb239v1, ECCurve_X9_62_CHAR2_TNB239V1,
-        "ANSI X9.62 elliptic curve c2tnb239v1",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( ansiX962c2tnb239v2, ECCurve_X9_62_CHAR2_TNB239V2,
-        "ANSI X9.62 elliptic curve c2tnb239v2",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( ansiX962c2tnb239v3, ECCurve_X9_62_CHAR2_TNB239V3,
-        "ANSI X9.62 elliptic curve c2tnb239v3",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    { { siDEROID, NULL, 0 }, ECCurve_noName,
-        "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
-    { { siDEROID, NULL, 0 }, ECCurve_noName,
-        "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
-    OD( ansiX962c2pnb272w1, ECCurve_X9_62_CHAR2_PNB272W1,
-        "ANSI X9.62 elliptic curve c2pnb272w1",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( ansiX962c2pnb304w1, ECCurve_X9_62_CHAR2_PNB304W1,
-        "ANSI X9.62 elliptic curve c2pnb304w1",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( ansiX962c2tnb359v1, ECCurve_X9_62_CHAR2_TNB359V1,
-        "ANSI X9.62 elliptic curve c2tnb359v1",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( ansiX962c2pnb368w1, ECCurve_X9_62_CHAR2_PNB368W1,
-        "ANSI X9.62 elliptic curve c2pnb368w1",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION ),
-    OD( ansiX962c2tnb431r1, ECCurve_X9_62_CHAR2_TNB431R1,
-        "ANSI X9.62 elliptic curve c2tnb431r1",
-        CKM_INVALID_MECHANISM,
-        INVALID_CERT_EXTENSION )
-};
-
-SECOidData *
-SECOID_FindOID(const SECItem *oid)
-{
-    SECOidData *po;
-    SECOidData *ret;
-    int i;
-
-    if (oid->len == 8) {
-        if (oid->data[6] == 0x00) {
-                /* XXX bounds check */
-                po = &ANSI_oids[oid->data[7]];
-                if (memcmp(oid->data, po->oid.data, 8) == 0)
-                        ret = po;
-        }
-        if (oid->data[6] == 0x01) {
-                /* XXX bounds check */
-                po = &ANSI_prime_oids[oid->data[7]];
-                if (memcmp(oid->data, po->oid.data, 8) == 0)
-                        ret = po;
-        }
-    } else if (oid->len == 5) {
-        /* XXX bounds check */
-        po = &SECG_oids[oid->data[4]];
-        if (memcmp(oid->data, po->oid.data, 5) == 0)
-                ret = po;
-    } else {
-        ret = NULL;
-    }
-    return(ret);
-}
-
-ECCurveName
-SECOID_FindOIDTag(const SECItem *oid)
-{
-    SECOidData *oiddata;
-
-    oiddata = SECOID_FindOID (oid);
-    if (oiddata == NULL)
-        return ECCurve_noName;
-
-    return oiddata->offset;
-}
--- a/jdk/src/share/native/sun/security/ec/secitem.c	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,199 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Netscape security libraries.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1994-2000
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-/*
- * Support routines for SECItem data structure.
- *
- * $Id: secitem.c,v 1.14 2006/05/22 22:24:34 wtchang%redhat.com Exp $
- */
-
-#include <sys/types.h>
-
-#ifndef _WIN32
-#ifndef __linux__
-#include <sys/systm.h>
-#endif /* __linux__ */
-#include <sys/param.h>
-#endif /* _WIN32 */
-
-#ifdef _KERNEL
-#include <sys/kmem.h>
-#else
-#include <string.h>
-
-#ifndef _WIN32
-#include <strings.h>
-#endif /* _WIN32 */
-
-#include <assert.h>
-#endif
-#include "ec.h"
-#include "ecl-curve.h"
-#include "ecc_impl.h"
-
-void SECITEM_FreeItem(SECItem *, PRBool);
-
-SECItem *
-SECITEM_AllocItem(PRArenaPool *arena, SECItem *item, unsigned int len,
-    int kmflag)
-{
-    SECItem *result = NULL;
-    void *mark = NULL;
-
-    if (arena != NULL) {
-        mark = PORT_ArenaMark(arena);
-    }
-
-    if (item == NULL) {
-        if (arena != NULL) {
-            result = PORT_ArenaZAlloc(arena, sizeof(SECItem), kmflag);
-        } else {
-            result = PORT_ZAlloc(sizeof(SECItem), kmflag);
-        }
-        if (result == NULL) {
-            goto loser;
-        }
-    } else {
-        PORT_Assert(item->data == NULL);
-        result = item;
-    }
-
-    result->len = len;
-    if (len) {
-        if (arena != NULL) {
-            result->data = PORT_ArenaAlloc(arena, len, kmflag);
-        } else {
-            result->data = PORT_Alloc(len, kmflag);
-        }
-        if (result->data == NULL) {
-            goto loser;
-        }
-    } else {
-        result->data = NULL;
-    }
-
-    if (mark) {
-        PORT_ArenaUnmark(arena, mark);
-    }
-    return(result);
-
-loser:
-    if ( arena != NULL ) {
-        if (mark) {
-            PORT_ArenaRelease(arena, mark);
-        }
-        if (item != NULL) {
-            item->data = NULL;
-            item->len = 0;
-        }
-    } else {
-        if (result != NULL) {
-            SECITEM_FreeItem(result, (item == NULL) ? PR_TRUE : PR_FALSE);
-        }
-        /*
-         * If item is not NULL, the above has set item->data and
-         * item->len to 0.
-         */
-    }
-    return(NULL);
-}
-
-SECStatus
-SECITEM_CopyItem(PRArenaPool *arena, SECItem *to, const SECItem *from,
-   int kmflag)
-{
-    to->type = from->type;
-    if (from->data && from->len) {
-        if ( arena ) {
-            to->data = (unsigned char*) PORT_ArenaAlloc(arena, from->len,
-                kmflag);
-        } else {
-            to->data = (unsigned char*) PORT_Alloc(from->len, kmflag);
-        }
-
-        if (!to->data) {
-            return SECFailure;
-        }
-        PORT_Memcpy(to->data, from->data, from->len);
-        to->len = from->len;
-    } else {
-        to->data = 0;
-        to->len = 0;
-    }
-    return SECSuccess;
-}
-
-void
-SECITEM_FreeItem(SECItem *zap, PRBool freeit)
-{
-    if (zap) {
-#ifdef _KERNEL
-        kmem_free(zap->data, zap->len);
-#else
-        free(zap->data);
-#endif
-        zap->data = 0;
-        zap->len = 0;
-        if (freeit) {
-#ifdef _KERNEL
-            kmem_free(zap, sizeof (SECItem));
-#else
-            free(zap);
-#endif
-        }
-    }
-}
--- a/jdk/src/share/native/sun/security/ec/secoidt.h	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,103 +0,0 @@
-/* *********************************************************************
- *
- * Sun elects to have this file available under and governed by the
- * Mozilla Public License Version 1.1 ("MPL") (see
- * http://www.mozilla.org/MPL/ for full license text). For the avoidance
- * of doubt and subject to the following, Sun also elects to allow
- * licensees to use this file under the MPL, the GNU General Public
- * License version 2 only or the Lesser General Public License version
- * 2.1 only. Any references to the "GNU General Public License version 2
- * or later" or "GPL" in the following shall be construed to mean the
- * GNU General Public License version 2 only. Any references to the "GNU
- * Lesser General Public License version 2.1 or later" or "LGPL" in the
- * following shall be construed to mean the GNU Lesser General Public
- * License version 2.1 only. However, the following notice accompanied
- * the original version of this file:
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Netscape security libraries.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1994-2000
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- *********************************************************************** */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _SECOIDT_H_
-#define _SECOIDT_H_
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
-/*
- * secoidt.h - public data structures for ASN.1 OID functions
- *
- * $Id: secoidt.h,v 1.23 2007/05/05 22:45:16 nelson%bolyard.com Exp $
- */
-
-typedef struct SECOidDataStr SECOidData;
-typedef struct SECAlgorithmIDStr SECAlgorithmID;
-
-/*
-** An X.500 algorithm identifier
-*/
-struct SECAlgorithmIDStr {
-    SECItem algorithm;
-    SECItem parameters;
-};
-
-#define SEC_OID_SECG_EC_SECP192R1 SEC_OID_ANSIX962_EC_PRIME192V1
-#define SEC_OID_SECG_EC_SECP256R1 SEC_OID_ANSIX962_EC_PRIME256V1
-#define SEC_OID_PKCS12_KEY_USAGE  SEC_OID_X509_KEY_USAGE
-
-/* fake OID for DSS sign/verify */
-#define SEC_OID_SHA SEC_OID_MISS_DSS
-
-typedef enum {
-    INVALID_CERT_EXTENSION = 0,
-    UNSUPPORTED_CERT_EXTENSION = 1,
-    SUPPORTED_CERT_EXTENSION = 2
-} SECSupportExtenTag;
-
-struct SECOidDataStr {
-    SECItem            oid;
-    ECCurveName        offset;
-    const char *       desc;
-    unsigned long      mechanism;
-    SECSupportExtenTag supportedExtension;
-                                /* only used for x.509 v3 extensions, so
-                                   that we can print the names of those
-                                   extensions that we don't even support */
-};
-
-#endif /* _SECOIDT_H_ */
--- a/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java	Fri Oct 16 18:02:31 2009 -0700
@@ -326,13 +326,6 @@
                 if (log.isLoggable(PlatformLogger.FINE)) {
                     dumpPeers();
                 }
-
-                awtLock();
-                try {
-                    XlibWrapper.XSetErrorHandler(saved_error_handler);
-                } finally {
-                    awtUnlock();
-                }
             }
         });
     }
--- a/jdk/src/solaris/classes/sun/net/www/protocol/http/NTLMAuthentication.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/solaris/classes/sun/net/www/protocol/http/NTLMAuthentication.java	Fri Oct 16 18:02:31 2009 -0700
@@ -244,13 +244,6 @@
         }
     }
 
-    /* This is a no-op for NTLM, because there is no authentication information
-     * provided by the server to the client
-     */
-    public void checkResponse (String header, String method, URL url) throws IOException {
-    }
-
-
     private void copybytes (byte[] dest, int destpos, String src, String enc) {
         try {
             byte[] x = src.getBytes(enc);
--- a/jdk/src/windows/classes/sun/awt/shell/Win32ShellFolder2.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/windows/classes/sun/awt/shell/Win32ShellFolder2.java	Fri Oct 16 18:02:31 2009 -0700
@@ -922,7 +922,7 @@
     // Dispose the HICON
     private static native void disposeIcon(long hIcon);
 
-    public static native int[] getFileChooserBitmapBits();
+    static native int[] getStandardViewButton0(int iconIndex);
 
     // Should be called from the COM thread
     private long getIShellIcon() {
@@ -933,34 +933,6 @@
         return pIShellIcon;
     }
 
-
-    static int[] fileChooserBitmapBits = null;
-    static Image[] fileChooserIcons = new Image[47];
-
-    static Image getFileChooserIcon(int i) {
-        if (fileChooserIcons[i] != null) {
-            return fileChooserIcons[i];
-        } else {
-            if (fileChooserBitmapBits == null) {
-                fileChooserBitmapBits = getFileChooserBitmapBits();
-            }
-            if (fileChooserBitmapBits != null) {
-                int nImages = fileChooserBitmapBits.length / (16*16);
-                int[] bitmapBits = new int[16 * 16];
-                for (int y = 0; y < 16; y++) {
-                    for (int x = 0; x < 16; x++) {
-                        bitmapBits[y * 16 + x] = fileChooserBitmapBits[y * (nImages * 16) + (i * 16) + x];
-                    }
-                }
-                BufferedImage img = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
-                img.setRGB(0, 0, 16, 16, bitmapBits, 0, 16);
-                fileChooserIcons[i] = img;
-            }
-        }
-        return fileChooserIcons[i];
-    }
-
-
     private static Image makeIcon(long hIcon, boolean getLargeIcon) {
         if (hIcon != 0L && hIcon != -1L) {
             // Get the bits.  This has the side effect of setting the imageHash value for this object.
--- a/jdk/src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java	Fri Oct 16 18:02:31 2009 -0700
@@ -25,7 +25,8 @@
 
 package sun.awt.shell;
 
-import java.awt.Toolkit;
+import java.awt.*;
+import java.awt.image.BufferedImage;
 
 import java.io.File;
 import java.io.FileNotFoundException;
@@ -33,6 +34,7 @@
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.*;
+import java.util.List;
 import java.util.concurrent.*;
 
 import sun.security.action.LoadLibraryAction;
@@ -98,6 +100,29 @@
         return parent;
     }
 
+    private static final int VIEW_LIST = 2;
+    private static final int VIEW_DETAILS = 3;
+    private static final int VIEW_PARENTFOLDER = 8;
+    private static final int VIEW_NEWFOLDER = 11;
+
+    private static final Image[] STANDARD_VIEW_BUTTONS = new Image[12];
+
+    private static Image getStandardViewButton(int iconIndex) {
+        Image result = STANDARD_VIEW_BUTTONS[iconIndex];
+
+        if (result != null) {
+            return result;
+        }
+
+        BufferedImage img = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
+
+        img.setRGB(0, 0, 16, 16, Win32ShellFolder2.getStandardViewButton0(iconIndex), 0, 16);
+
+        STANDARD_VIEW_BUTTONS[iconIndex] = img;
+
+        return img;
+    }
+
     // Special folders
     private static Win32ShellFolder2 desktop;
     private static Win32ShellFolder2 drives;
@@ -105,12 +130,6 @@
     private static Win32ShellFolder2 network;
     private static Win32ShellFolder2 personal;
 
-    private static final boolean USE_SHELL32_ICONS = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
-        public Boolean run() {
-            return OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_XP) >= 0;
-        }
-    });
-
     static Win32ShellFolder2 getDesktop() {
         if (desktop == null) {
             try {
@@ -206,9 +225,9 @@
      *    folders, such as Desktop, Documents, History, Network, Home, etc.
      *    This is used in the shortcut panel of the filechooser on Windows 2000
      *    and Windows Me.
-     *  "fileChooserIcon nn":
-     *    Returns an <code>Image</code> - icon nn from resource 216 in shell32.dll,
-     *      or if not found there from resource 124 in comctl32.dll (Windows only).
+     *  "fileChooserIcon <icon>":
+     *    Returns an <code>Image</code> - icon can be ListView, DetailsView, UpFolder, NewFolder or
+     *    ViewMenu (Windows only).
      *  "optionPaneIcon iconName":
      *    Returns an <code>Image</code> - icon from the system icon list
      *
@@ -303,26 +322,23 @@
             }
             return folders.toArray(new File[folders.size()]);
         } else if (key.startsWith("fileChooserIcon ")) {
-            int i = -1;
-            String name = key.substring(key.indexOf(" ")+1);
-            try {
-                i = Integer.parseInt(name);
-            } catch (NumberFormatException ex) {
-                if (name.equals("ListView")) {
-                    i = (USE_SHELL32_ICONS) ? 21 : 2;
-                } else if (name.equals("DetailsView")) {
-                    i = (USE_SHELL32_ICONS) ? 23 : 3;
-                } else if (name.equals("UpFolder")) {
-                    i = (USE_SHELL32_ICONS) ? 28 : 8;
-                } else if (name.equals("NewFolder")) {
-                    i = (USE_SHELL32_ICONS) ? 31 : 11;
-                } else if (name.equals("ViewMenu")) {
-                    i = (USE_SHELL32_ICONS) ? 21 : 2;
-                }
+            String name = key.substring(key.indexOf(" ") + 1);
+
+            int iconIndex;
+
+            if (name.equals("ListView") || name.equals("ViewMenu")) {
+                iconIndex = VIEW_LIST;
+            } else if (name.equals("DetailsView")) {
+                iconIndex = VIEW_DETAILS;
+            } else if (name.equals("UpFolder")) {
+                iconIndex = VIEW_PARENTFOLDER;
+            } else if (name.equals("NewFolder")) {
+                iconIndex = VIEW_NEWFOLDER;
+            } else {
+                return null;
             }
-            if (i >= 0) {
-                return Win32ShellFolder2.getFileChooserIcon(i);
-            }
+
+            return getStandardViewButton(iconIndex);
         } else if (key.startsWith("optionPaneIcon ")) {
             Win32ShellFolder2.SystemIcon iconType;
             if (key == "optionPaneIcon Error") {
--- a/jdk/src/windows/classes/sun/net/www/protocol/http/NTLMAuthentication.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/windows/classes/sun/net/www/protocol/http/NTLMAuthentication.java	Fri Oct 16 18:02:31 2009 -0700
@@ -192,9 +192,4 @@
         }
     }
 
-    /* This is a no-op for NTLM, because there is no authentication information
-     * provided by the server to the client
-     */
-    public void checkResponse (String header, String method, URL url) throws IOException {
-    }
 }
--- a/jdk/src/windows/classes/sun/security/krb5/internal/tools/Kinit.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/windows/classes/sun/security/krb5/internal/tools/Kinit.java	Fri Oct 16 18:02:31 2009 -0700
@@ -1,5 +1,5 @@
 /*
- * Portions Copyright 2000-2007 Sun Microsystems, Inc.  All Rights Reserved.
+ * Portions Copyright 2000-2009 Sun Microsystems, Inc.  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
@@ -252,15 +252,15 @@
                 }
                 KRBError error = ke.getError();
                 int etype = error.getEType();
-                byte[] salt = error.getSalt();
+                String salt = error.getSalt();
                 byte[] s2kparams = error.getParams();
                 if (useKeytab) {
-                    as_req = new KrbAsReq(skeys, true, etype, salt, s2kparams,
-                                        opt, principal, sname,
+                    as_req = new KrbAsReq(skeys, true, etype, salt,
+                                        s2kparams, opt, principal, sname,
                                         null, null, null, null, addresses, null);
                 } else {
-                    as_req = new KrbAsReq(psswd, true, etype, salt, s2kparams,
-                                        opt, principal, sname,
+                    as_req = new KrbAsReq(psswd, true, etype, salt,
+                                        s2kparams, opt, principal, sname,
                                         null, null, null, null, addresses, null);
                 }
                 as_rep = sendASRequest(as_req, useKeytab, realm, psswd, skeys);
--- a/jdk/src/windows/classes/sun/security/krb5/internal/tools/Klist.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/windows/classes/sun/security/krb5/internal/tools/Klist.java	Fri Oct 16 18:02:31 2009 -0700
@@ -30,17 +30,12 @@
 
 package sun.security.krb5.internal.tools;
 
+import java.net.InetAddress;
 import sun.security.krb5.*;
 import sun.security.krb5.internal.*;
 import sun.security.krb5.internal.ccache.*;
 import sun.security.krb5.internal.ktab.*;
 import sun.security.krb5.internal.crypto.EType;
-import sun.security.krb5.KrbCryptoException;
-import java.lang.RuntimeException;
-import java.io.IOException;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.io.File;
 
 /**
  * This class can execute as a command-line tool to list entries in
@@ -51,9 +46,9 @@
  */
 public class Klist {
     Object target;
-    // for credentials cache, options are 'f'  and 'e';
+    // for credentials cache, options are 'f', 'e', 'a' and 'n';
     // for  keytab, optionsare 't' and 'K' and 'e'
-    char[] options = new char[3];
+    char[] options = new char[4];
     String name;       // the name of credentials cache and keytable.
     char action;       // actions would be 'c' for credentials cache
     // and 'k' for keytable.
@@ -62,7 +57,7 @@
     /**
      * The main program that can be invoked at command line.
      * <br>Usage: klist
-     * [[-c] [-f] [-e]] [-k [-t] [-K]] [name]
+     * [[-c] [-f] [-e] [-a [-n]]] [-k [-t] [-K]] [name]
      * -c specifes that credential cache is to be listed
      * -k specifies that key tab is to be listed
      * name name of the credentials cache or keytab
@@ -70,6 +65,8 @@
      * <ul>
      * <li><b>-f</b>  shows credentials flags
      * <li><b>-e</b>  shows the encryption type
+     * <li><b>-a</b>  shows addresses
+     * <li><b>-n</b>  do not reverse-resolve addresses
      * </ul>
      * available options for keytabs:
      * <li><b>-t</b> shows keytab entry timestamps
@@ -141,6 +138,12 @@
                 case 'k':
                     action = 'k';
                     break;
+                case 'a':
+                    options[2] = 'a';
+                    break;
+                case 'n':
+                    options[3] = 'n';
+                    break;
                 case 'f':
                     options[1] = 'f';
                     break;
@@ -202,7 +205,7 @@
                 }
                 if (options[2] == 't') {
                     System.out.println("\t Time stamp: " +
-                                       reformat(entries[i].getTimeStamp().toDate().toString()));
+                            reformat(entries[i].getTimeStamp().toDate().toString()));
                 }
             }
         }
@@ -249,12 +252,33 @@
                     System.out.println("     Expires:         " + endtime);
                     if (options[0] == 'e') {
                         etype = EType.toString(creds[i].getEType());
-                        System.out.println("\t Encryption type: " + etype);
+                        System.out.println("     Encryption type: " + etype);
                     }
                     if (options[1] == 'f') {
-                        System.out.println("\t Flags:           " +
+                        System.out.println("     Flags:           " +
                                            creds[i].getTicketFlags().toString());
                     }
+                    if (options[2] == 'a') {
+                        boolean first = true;
+                        InetAddress[] caddr
+                                = creds[i].setKrbCreds().getClientAddresses();
+                        if (caddr != null) {
+                            for (InetAddress ia: caddr) {
+                                String out;
+                                if (options[3] == 'n') {
+                                    out = ia.getHostAddress();
+                                } else {
+                                    out = ia.getCanonicalHostName();
+                                }
+                                System.out.println("     " +
+                                        (first?"Addresses:":"          ") +
+                                        "       " + out);
+                                first = false;
+                            }
+                        } else {
+                            System.out.println("     [No host addresses info]");
+                        }
+                    }
                 } catch (RealmException e) {
                     System.out.println("Error reading principal from "+
                                        "the entry.");
@@ -295,7 +319,7 @@
      */
     void printHelp() {
         System.out.println("\nUsage: klist " +
-                           "[[-c] [-f] [-e]] [-k [-t] [-K]] [name]");
+                           "[[-c] [-f] [-e] [-a [-n]]] [-k [-t] [-K]] [name]");
         System.out.println("   name\t name of credentials cache or " +
                            " keytab with the prefix. File-based cache or "
                            + "keytab's prefix is FILE:.");
@@ -305,6 +329,8 @@
         System.out.println("   options for credentials caches:");
         System.out.println("\t-f \t shows credentials flags");
         System.out.println("\t-e \t shows the encryption type");
+        System.out.println("\t-a \t shows addresses");
+        System.out.println("\t  -n \t   do not reverse-resolve addresses");
         System.out.println("   options for keytabs:");
         System.out.println("\t-t \t shows keytab entry timestamps");
         System.out.println("\t-K \t shows keytab entry key value");
--- a/jdk/src/windows/native/sun/windows/ShellFolder2.cpp	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/src/windows/native/sun/windows/ShellFolder2.cpp	Fri Oct 16 18:02:31 2009 -0700
@@ -256,7 +256,6 @@
 static IShellIcon* getIShellIcon(IShellFolder* pIShellFolder) {
     // http://msdn.microsoft.com/library/en-us/shellcc/platform/Shell/programmersguide/shell_int/shell_int_programming/std_ifaces.asp
     HRESULT hres;
-    HICON hIcon = NULL;
     IShellIcon* pIShellIcon;
     if (pIShellFolder != NULL) {
         hres = pIShellFolder->QueryInterface(IID_IShellIcon, (void**)&pIShellIcon);
@@ -965,89 +964,40 @@
 
 /*
  * Class:     sun_awt_shell_Win32ShellFolder2
- * Method:    getFileChooserBitmapBits
- * Signature: ()[I
+ * Method:    getStandardViewButton0
+ * Signature: (I)[I
  */
-JNIEXPORT jintArray JNICALL Java_sun_awt_shell_Win32ShellFolder2_getFileChooserBitmapBits
-    (JNIEnv* env, jclass cls)
+JNIEXPORT jintArray JNICALL Java_sun_awt_shell_Win32ShellFolder2_getStandardViewButton0
+    (JNIEnv* env, jclass cls, jint iconIndex)
 {
-    HBITMAP hBitmap = NULL;
-    BITMAP bm;
-    HINSTANCE libComCtl32;
-    HINSTANCE libShell32;
+    jintArray result = NULL;
 
-    libShell32 = LoadLibrary(TEXT("shell32.dll"));
-    if (libShell32 != NULL) {
-        hBitmap = (HBITMAP)LoadImage(libShell32,
-                    IS_WINVISTA ? TEXT("IDB_TB_SH_DEF_16") : MAKEINTRESOURCE(216),
-                    IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
+    // Create a toolbar
+    HWND hWndToolbar = ::CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
+        0, 0, 0, 0, 0,
+        NULL, NULL, NULL, NULL);
+
+    if (hWndToolbar != NULL) {
+        SendMessage(hWndToolbar, TB_LOADIMAGES, (WPARAM)IDB_VIEW_SMALL_COLOR, (LPARAM)HINST_COMMCTRL);
 
-        if (hBitmap == NULL) {
-            // version of shell32.dll doesn't match OS version.
-            // So we either are in a Vista Compatibility Mode
-            // or shell32.dll was copied from OS of another version
-            hBitmap = (HBITMAP)LoadImage(libShell32,
-                    IS_WINVISTA ? MAKEINTRESOURCE(216) : TEXT("IDB_TB_SH_DEF_16"),
-                    IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
+        HIMAGELIST hImageList = (HIMAGELIST) SendMessage(hWndToolbar, TB_GETIMAGELIST, 0, 0);
+
+        if (hImageList != NULL) {
+            HICON hIcon = ImageList_GetIcon(hImageList, iconIndex, ILD_TRANSPARENT);
+
+            if (hIcon != NULL) {
+                result = Java_sun_awt_shell_Win32ShellFolder2_getIconBits(env, cls, ptr_to_jlong(hIcon), 16);
+
+                DestroyIcon(hIcon);
+            }
+
+            ImageList_Destroy(hImageList);
         }
-    }
-    if (hBitmap == NULL) {
-        libComCtl32 = LoadLibrary(TEXT("comctl32.dll"));
-        if (libComCtl32 != NULL) {
-            hBitmap = (HBITMAP)LoadImage(libComCtl32, MAKEINTRESOURCE(124),
-                                         IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
-        }
-    }
-    if (hBitmap == NULL) {
-        return NULL;
+
+        DestroyWindow(hWndToolbar);
     }
 
-    GetObject(hBitmap, sizeof(bm), (LPSTR)&bm);
-
-    // Get the screen DC
-    HDC dc = GetDC(NULL);
-    if (dc == NULL) {
-        return NULL;
-    }
-
-    // Set up BITMAPINFO
-    BITMAPINFO bmi;
-    memset(&bmi, 0, sizeof(BITMAPINFO));
-    bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
-    bmi.bmiHeader.biWidth = bm.bmWidth;
-    bmi.bmiHeader.biHeight = -bm.bmHeight;
-    bmi.bmiHeader.biPlanes = 1;
-    bmi.bmiHeader.biBitCount = 32;
-    bmi.bmiHeader.biCompression = BI_RGB;
-    // Extract the color bitmap
-    int numPixels = bm.bmWidth * bm.bmHeight;
-    //long colorBits[192 * 16];
-    long *colorBits = (long*)safe_Malloc(numPixels * sizeof(long));
-    if (GetDIBits(dc, hBitmap, 0, bm.bmHeight, colorBits, &bmi, DIB_RGB_COLORS) == 0) {
-        return NULL;
-    }
-
-    // Release DC
-    ReleaseDC(NULL, dc);
-
-    // The color of the first pixel defines the transparency, according
-    // to the documentation for LR_LOADTRANSPARENT at
-    // http://msdn.microsoft.com/library/psdk/winui/resource_9fhi.htm
-    long transparent = colorBits[0];
-    for (int i=0; i < numPixels; i++) {
-        if (colorBits[i] != transparent) {
-            colorBits[i] |= 0xff000000;
-        }
-    }
-
-    // Create java array
-    jintArray bits = env->NewIntArray(numPixels);
-    // Copy values to java array
-    env->SetIntArrayRegion(bits, 0, numPixels, colorBits);
-    // Fix 4745575 GDI Resource Leak
-    ::DeleteObject(hBitmap);
-    ::FreeLibrary(libComCtl32);
-    return bits;
+    return result;
 }
 
 /*
--- a/jdk/test/com/sun/jdi/ShellScaffold.sh	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/test/com/sun/jdi/ShellScaffold.sh	Fri Oct 16 18:02:31 2009 -0700
@@ -193,11 +193,17 @@
 {
     # Return 0 if $1 is the pid of a running process.
     if [ -z "$isWin98" ] ; then
-        #   Never use plain 'ps', which requires a "controlling terminal"
-        #     and will fail  with a "ps: no controlling terminal" error.
-        #     Running under 'rsh' will cause this ps error.
-        # cygwin ps puts an I in column 1 for some reason.
-        $psCmd -e | $grep '^I* *'"$1 " > $devnull 2>&1
+        if [ "$osname" = SunOS ] ; then
+            #Solaris and OpenSolaris use pgrep and not ps in psCmd
+            findPidCmd="$psCmd"
+        else
+            #   Never use plain 'ps', which requires a "controlling terminal"
+            #     and will fail  with a "ps: no controlling terminal" error.
+            #     Running under 'rsh' will cause this ps error.
+            # cygwin ps puts an I in column 1 for some reason.
+            findPidCmd="$psCmd -e"
+        fi
+	$findPidCmd | $grep '^I* *'"$1 " > $devnull 2>&1
         return $?
     fi
 
@@ -292,7 +298,17 @@
          # On linux, core files take a long time, and can leave
          # zombie processes
          if [ "$osname" = SunOS ] ; then
-             psCmd="/usr/ucb/ps -axwww"
+             #Experiments show Solaris '/usr/ucb/ps -axwww' and
+             #'/usr/bin/pgrep -f -l' provide the same small amount of the
+             #argv string (PRARGSZ=80 in /usr/include/sys/procfs.h)
+             # 1) This seems to have been working OK in ShellScaffold.
+             # 2) OpenSolaris does not provide /usr/ucb/ps, so use pgrep
+             #    instead
+             #The alternative would be to use /usr/bin/pargs [pid] to get
+             #all the args for a process, splice them back into one
+             #long string, then grep.
+             UU=`/usr/bin/id -un`
+             psCmd="pgrep -f -l -U $UU"
          else
              ulimit -c 0
              # See bug 6238593.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/Compare.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,142 @@
+/*
+ * Copyright 2009 Google, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6582946
+ * @summary Test the primitive wrappers compare and compareTo methods
+ */
+
+import java.util.Random;
+
+public class Compare {
+
+    final Random rnd = new Random();
+
+    boolean toBoolean(long x) { return x > 0; }
+
+    void compareAll(long x, long y) {
+        check(Double.compare(x, y) ==
+              Double.valueOf(x).compareTo(Double.valueOf(y)));
+        check(Float.compare(x, y) ==
+              Float.valueOf(x).compareTo(Float.valueOf(y)));
+        check(Long.compare(x, y) ==
+              Long.valueOf(x).compareTo(Long.valueOf(y)));
+        check(Integer.compare((int) x, (int) y) ==
+              Integer.valueOf((int) x).compareTo(Integer.valueOf((int) y)));
+        check(Short.compare((short) x, (short) y) ==
+              Short.valueOf((short) x).compareTo(Short.valueOf((short) y)));
+        check(Character.compare((char) x, (char) y) ==
+              Character.valueOf((char) x).compareTo(Character.valueOf((char) y)));
+        check(Byte.compare((byte) x, (byte) y) ==
+              Byte.valueOf((byte) x).compareTo(Byte.valueOf((byte) y)));
+        check(Boolean.compare(toBoolean(x), toBoolean(y)) ==
+              Boolean.valueOf(toBoolean(x)).compareTo(Boolean.valueOf(toBoolean(y))));
+
+        check(Double.compare(x, y) == -Double.compare(y, x));
+        check(Float.compare(x, y) == -Float.compare(y, x));
+        check(Long.compare(x, y) == -Long.compare(y, x));
+        check(Integer.compare((int) x, (int) y) ==
+              -Integer.compare((int) y, (int) x));
+        check(Short.compare((short) x, (short) y) ==
+              -Short.compare((short) y, (short) x));
+        check(Character.compare((char) x, (char) y) ==
+              -Character.compare((char) y, (char) x));
+        check(Byte.compare((byte) x, (byte) y) ==
+              -Byte.compare((byte) y, (byte) x));
+
+        equal(Long.compare(x, y),
+              x < y ? -1 : x > y ? 1 : 0);
+
+        {
+            int a = (int) x, b = (int) y;
+            equal(Integer.compare(a, b),
+                  a < b ? -1 : a > b ? 1 : 0);
+        }
+
+        {
+            short a = (short) x, b = (short) y;
+            equal(Short.compare(a, b),
+                  a - b);
+        }
+
+        {
+            char a = (char) x, b = (char) y;
+            equal(Character.compare(a, b),
+                  a - b);
+        }
+
+        {
+            byte a = (byte) x, b = (byte) y;
+            equal(Byte.compare(a, b),
+                  a - b);
+        }
+
+        {
+            boolean a = toBoolean(x), b = toBoolean(y);
+            equal(Boolean.compare(a, b),
+                  a == b ? 0 : a ? 1 : -1);
+        }
+    }
+
+    void test(String args[]) throws Exception {
+        long[] longs = {
+            Long.MIN_VALUE,
+            Integer.MIN_VALUE,
+            Short.MIN_VALUE,
+            Character.MIN_VALUE,
+            Byte.MIN_VALUE,
+            -1, 0, 1,
+            Byte.MAX_VALUE,
+            Character.MAX_VALUE,
+            Short.MAX_VALUE,
+            Integer.MAX_VALUE,
+            Long.MAX_VALUE,
+            rnd.nextLong(),
+            rnd.nextInt(),
+        };
+
+        for (long x : longs) {
+            for (long y : longs) {
+                compareAll(x, y);
+            }
+        }
+    }
+
+    //--------------------- Infrastructure ---------------------------
+    volatile int passed = 0, failed = 0;
+    void pass() {passed++;}
+    void fail() {failed++; Thread.dumpStack();}
+    void fail(String msg) {System.err.println(msg); fail();}
+    void unexpected(Throwable t) {failed++; t.printStackTrace();}
+    void check(boolean cond) {if (cond) pass(); else fail();}
+    void equal(Object x, Object y) {
+        if (x == null ? y == null : x.equals(y)) pass();
+        else fail(x + " not equal to " + y);}
+    public static void main(String[] args) throws Throwable {
+        new Compare().instanceMain(args);}
+    public void instanceMain(String[] args) throws Throwable {
+        try {test(args);} catch (Throwable t) {unexpected(t);}
+        System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
+        if (failed > 0) throw new AssertionError("Some tests failed");}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/HashCode.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2009 Google, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4245470
+ * @summary Test the primitive wrappers hashCode()
+ */
+
+import java.util.Random;
+
+public class HashCode {
+
+    final Random rnd = new Random();
+
+    void test(String args[]) throws Exception {
+        int[] ints = {
+            Integer.MIN_VALUE,
+            Short.MIN_VALUE,
+            Character.MIN_VALUE,
+            Byte.MIN_VALUE,
+            -1, 0, 1,
+            Byte.MAX_VALUE,
+            Character.MAX_VALUE,
+            Short.MAX_VALUE,
+            Integer.MAX_VALUE,
+            rnd.nextInt(),
+        };
+
+        for (int x : ints) {
+            check(    new Long(x).hashCode() == (int)((long)x ^ (long)x>>>32));
+            check(Long.valueOf(x).hashCode() == (int)((long)x ^ (long)x>>>32));
+            check(    new Integer(x).hashCode() == x);
+            check(Integer.valueOf(x).hashCode() == x);
+            check(    new Short((short)x).hashCode() == (short) x);
+            check(Short.valueOf((short)x).hashCode() == (short) x);
+            check(    new Character((char) x).hashCode() == (char) x);
+            check(Character.valueOf((char) x).hashCode() == (char) x);
+            check(    new Byte((byte) x).hashCode() == (byte) x);
+            check(Byte.valueOf((byte) x).hashCode() == (byte) x);
+        }
+    }
+
+    //--------------------- Infrastructure ---------------------------
+    volatile int passed = 0, failed = 0;
+    void pass() {passed++;}
+    void fail() {failed++; Thread.dumpStack();}
+    void fail(String msg) {System.err.println(msg); fail();}
+    void unexpected(Throwable t) {failed++; t.printStackTrace();}
+    void check(boolean cond) {if (cond) pass(); else fail();}
+    void equal(Object x, Object y) {
+        if (x == null ? y == null : x.equals(y)) pass();
+        else fail(x + " not equal to " + y);}
+    public static void main(String[] args) throws Throwable {
+        new HashCode().instanceMain(args);}
+    public void instanceMain(String[] args) throws Throwable {
+        try {test(args);} catch (Throwable t) {unexpected(t);}
+        System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
+        if (failed > 0) throw new AssertionError("Some tests failed");}
+}
--- a/jdk/test/java/net/Authenticator/B4933582.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/test/java/net/Authenticator/B4933582.java	Fri Oct 16 18:02:31 2009 -0700
@@ -125,9 +125,16 @@
         firstTime = args[0].equals ("first");
         MyAuthenticator auth = new MyAuthenticator ();
         Authenticator.setDefault (auth);
-        AuthCacheValue.setAuthCache (new CacheImpl());
+        CacheImpl cache;
         try {
-            server = new HttpServer (new B4933582(), 1, 10, 5009);
+            if (firstTime) {
+                server = new HttpServer (new B4933582(), 1, 10, 0);
+                cache = new CacheImpl (server.getLocalPort());
+            } else {
+                cache = new CacheImpl ();
+                server = new HttpServer(new B4933582(), 1, 10, cache.getPort());
+            }
+            AuthCacheValue.setAuthCache (cache);
             System.out.println ("Server: listening on port: " + server.getLocalPort());
             client ("http://localhost:"+server.getLocalPort()+"/d1/foo.html");
         } catch (Exception e) {
@@ -172,8 +179,15 @@
 
     static class CacheImpl extends AuthCacheImpl {
         HashMap map;
+        int port; // need to store the port number the server is using
+
         CacheImpl () throws IOException {
+            this (-1);
+        }
+
+        CacheImpl (int port) throws IOException {
             super();
+            this.port = port;
             File src = new File ("cache.ser");
             if (src.exists()) {
                 ObjectInputStream is = new ObjectInputStream (
@@ -181,6 +195,8 @@
                 );
                 try {
                     map = (HashMap)is.readObject ();
+                    this.port = (Integer)is.readObject ();
+                    System.out.println ("read port from file " + port);
                 } catch (ClassNotFoundException e) {
                     assert false;
                 }
@@ -192,6 +208,10 @@
             setMap (map);
         }
 
+        int getPort () {
+            return port;
+        }
+
         private void writeMap () {
             try {
                 File dst = new File ("cache.ser");
@@ -203,6 +223,8 @@
                         new FileOutputStream (dst)
                 );
                 os.writeObject(map);
+                os.writeObject(port);
+                System.out.println ("wrote port " + port);
                 os.close();
             } catch (IOException e) {}
         }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/net/Authenticator/B6870935.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,262 @@
+/*
+ * Copyright 2001-2009 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6870935
+ * @run main/othervm -Dhttp.nonProxyHosts="" -Dhttp.auth.digest.validateProxy=true B6870935
+ */
+
+import java.io.*;
+import java.util.*;
+import java.net.*;
+import java.security.*;
+import sun.net.www.*;
+
+/* This is one simple test of the RFC2617 digest authentication behavior
+ * It specifically tests that the client correctly checks the returned
+ * Authentication-Info header field from the server and throws an exception
+ * if the password is wrong
+ */
+
+public class B6870935 {
+
+    static char[] passwd = "password".toCharArray();
+    static String username = "user";
+    static String nonce = "abcdefghijklmnopqrstuvwxyz";
+    static String realm = "wallyworld";
+    static String uri = "http://www.ibm.com";
+    static volatile boolean error = false;
+
+    static class DigestServer extends Thread {
+
+        ServerSocket s;
+        InputStream  is;
+        OutputStream os;
+        int port;
+
+        String reply1 = "HTTP/1.1 407 Proxy Authentication Required\r\n"+
+            "Proxy-Authenticate: Digest realm=\""+realm+"\" domain=/ "+
+            "nonce=\""+nonce+"\" qop=\"auth\"\r\n\r\n";
+
+        String reply2 = "HTTP/1.1 200 OK\r\n" +
+            "Date: Mon, 15 Jan 2001 12:18:21 GMT\r\n" +
+            "Server: Apache/1.3.14 (Unix)\r\n" +
+            "Content-Type: text/html; charset=iso-8859-1\r\n" +
+            "Transfer-encoding: chunked\r\n\r\n"+
+            "B\r\nHelloWorld1\r\n"+
+            "B\r\nHelloWorld2\r\n"+
+            "B\r\nHelloWorld3\r\n"+
+            "B\r\nHelloWorld4\r\n"+
+            "B\r\nHelloWorld5\r\n"+
+            "0\r\n"+
+            "Proxy-Authentication-Info: ";
+
+        DigestServer (ServerSocket y) {
+            s = y;
+            port = s.getLocalPort();
+        }
+
+        public void run () {
+            try {
+                Socket s1 = s.accept ();
+                is = s1.getInputStream ();
+                os = s1.getOutputStream ();
+                is.read ();
+                os.write (reply1.getBytes());
+                Thread.sleep (2000);
+                s1.close ();
+
+                s1 = s.accept ();
+                is = s1.getInputStream ();
+                os = s1.getOutputStream ();
+                is.read ();
+                // need to get the cnonce out of the response
+                MessageHeader header = new MessageHeader (is);
+                String raw = header.findValue ("Proxy-Authorization");
+                HeaderParser parser = new HeaderParser (raw);
+                String cnonce = parser.findValue ("cnonce");
+                String cnstring = parser.findValue ("nc");
+                String clientrsp = parser.findValue ("response");
+                String expected = computeDigest(
+                        true, username,passwd,realm,
+                        "GET", uri, nonce, cnonce, cnstring
+                );
+                if (!expected.equals(clientrsp)) {
+                    s1.close ();
+                    s.close ();
+                    error = true;
+                    return;
+                }
+
+                String reply = reply2 + getAuthorization (
+                        realm, false, uri, "GET", cnonce,
+                        cnstring, passwd, username
+                ) +"\r\n";
+                os.write (reply.getBytes());
+                Thread.sleep (2000);
+                s1.close ();
+            }
+            catch (Exception e) {
+                System.out.println (e);
+                e.printStackTrace();
+            }
+        }
+
+        private String getAuthorization (String realm, boolean isRequest, String uri, String method, String cnonce, String cnstring, char[] password, String username) {
+            String response;
+
+            try {
+                response = computeDigest(isRequest, username,passwd,realm,
+                                            method, uri, nonce, cnonce, cnstring);
+            } catch (NoSuchAlgorithmException ex) {
+                return null;
+            }
+
+            String value = "Digest"
+                            + " qop=\"auth"
+                            + "\", cnonce=\"" + cnonce
+                            + "\", rspauth=\"" + response
+                            + "\", nc=\"" + cnstring + "\"";
+            return (value+ "\r\n");
+        }
+
+        private String computeDigest(
+                            boolean isRequest, String userName, char[] password,
+                            String realm, String connMethod,
+                            String requestURI, String nonceString,
+                            String cnonce, String ncValue
+                        ) throws NoSuchAlgorithmException
+        {
+
+            String A1, HashA1;
+
+            MessageDigest md = MessageDigest.getInstance("MD5");
+
+            {
+                A1 = userName + ":" + realm + ":";
+                HashA1 = encode(A1, password, md);
+            }
+
+            String A2;
+            if (isRequest) {
+                A2 = connMethod + ":" + requestURI;
+            } else {
+                A2 = ":" + requestURI;
+            }
+            String HashA2 = encode(A2, null, md);
+            String combo, finalHash;
+
+            { /* RRC2617 when qop=auth */
+                combo = HashA1+ ":" + nonceString + ":" + ncValue + ":" +
+                            cnonce + ":auth:" +HashA2;
+
+            }
+            finalHash = encode(combo, null, md);
+            return finalHash;
+        }
+
+        private final static char charArray[] = {
+            '0', '1', '2', '3', '4', '5', '6', '7',
+            '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
+        };
+
+        private String encode(String src, char[] passwd, MessageDigest md) {
+            md.update(src.getBytes());
+            if (passwd != null) {
+                byte[] passwdBytes = new byte[passwd.length];
+                for (int i=0; i<passwd.length; i++)
+                    passwdBytes[i] = (byte)passwd[i];
+                md.update(passwdBytes);
+                Arrays.fill(passwdBytes, (byte)0x00);
+            }
+            byte[] digest = md.digest();
+
+            StringBuffer res = new StringBuffer(digest.length * 2);
+            for (int i = 0; i < digest.length; i++) {
+                int hashchar = ((digest[i] >>> 4) & 0xf);
+                res.append(charArray[hashchar]);
+                hashchar = (digest[i] & 0xf);
+                res.append(charArray[hashchar]);
+            }
+            return res.toString();
+        }
+    }
+
+
+    static class MyAuthenticator extends Authenticator {
+        public MyAuthenticator () {
+            super ();
+        }
+
+        public PasswordAuthentication getPasswordAuthentication ()
+        {
+            return (new PasswordAuthentication (username, passwd));
+        }
+    }
+
+
+    public static void main(String[] args) throws Exception {
+        int nLoops = 1;
+        int nSize = 10;
+        int port, n =0;
+        byte b[] = new byte[nSize];
+        DigestServer server;
+        ServerSocket sock;
+
+        try {
+            sock = new ServerSocket (0);
+            port = sock.getLocalPort ();
+        }
+        catch (Exception e) {
+            System.out.println ("Exception: " + e);
+            return;
+        }
+
+        server = new DigestServer(sock);
+        server.start ();
+
+        try  {
+
+            Authenticator.setDefault (new MyAuthenticator ());
+            SocketAddress addr = new InetSocketAddress ("127.0.0.1", port);
+            Proxy proxy = new Proxy (Proxy.Type.HTTP, addr);
+            String s = "http://www.ibm.com";
+            URL url = new URL(s);
+            java.net.URLConnection conURL =  url.openConnection(proxy);
+
+            InputStream in = conURL.getInputStream();
+            int c;
+            while ((c = in.read ()) != -1) {
+            }
+            in.close ();
+        }
+        catch(IOException e) {
+            e.printStackTrace();
+            error = true;
+        }
+        if (error) {
+            throw new RuntimeException ("Error in test");
+        }
+    }
+}
--- a/jdk/test/java/net/MulticastSocket/SetOutgoingIf.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/test/java/net/MulticastSocket/SetOutgoingIf.java	Fri Oct 16 18:02:31 2009 -0700
@@ -27,7 +27,6 @@
  * @summary Re-test IPv6 (and specifically MulticastSocket) with latest Linux & USAGI code
  */
 import java.net.*;
-import java.util.concurrent.*;
 import java.util.*;
 
 
@@ -68,37 +67,61 @@
 
         // We need 2 or more network interfaces to run the test
         //
-        List<NetworkInterface> nics = new ArrayList<NetworkInterface>();
+        List<NetIf> netIfs = new ArrayList<NetIf>();
+        int index = 1;
         for (NetworkInterface nic : Collections.list(NetworkInterface.getNetworkInterfaces())) {
-            if (!nic.isLoopback())
-                nics.add(nic);
+            // we should use only network interfaces with multicast support which are in "up" state
+            if (!nic.isLoopback() && nic.supportsMulticast() && nic.isUp()) {
+                NetIf netIf = NetIf.create(nic);
+
+                // now determine what (if any) type of addresses are assigned to this interface
+                for (InetAddress addr : Collections.list(nic.getInetAddresses())) {
+                    if (addr instanceof Inet4Address) {
+                        netIf.ipv4Address(true);
+                    } else if (addr instanceof Inet6Address) {
+                        netIf.ipv6Address(true);
+                    }
+                }
+                if (netIf.ipv4Address() || netIf.ipv6Address()) {
+                    netIf.index(index++);
+                    netIfs.add(netIf);
+                    debug("Using: " + nic);
+                }
+            }
         }
-        if (nics.size() <= 1) {
+        if (netIfs.size() <= 1) {
             System.out.println("Need 2 or more network interfaces to run. Bye.");
             return;
         }
 
-        // We will send packets to one ipv4, one ipv4-mapped, and one ipv6
+        // We will send packets to one ipv4, and one ipv6
         // multicast group using each network interface :-
         //      224.1.1.1        --|
-        //      ::ffff:224.1.1.2 -----> using network interface #1
-        //      ff02::1:1        --|
+        //      ff02::1:1        --|--> using network interface #1
         //      224.1.2.1        --|
-        //      ::ffff:224.1.2.2 -----> using network interface #2
-        //      ff02::1:2        --|
+        //      ff02::1:2        --|--> using network interface #2
         // and so on.
         //
-        List<InetAddress> groups = new ArrayList<InetAddress>();
-        for (int i = 0; i < nics.size(); i++) {
-            InetAddress groupv4 = InetAddress.getByName("224.1." + (i+1) + ".1");
-            InetAddress groupv4mapped = InetAddress.getByName("::ffff:224.1." + (i+1) + ".2");
-            InetAddress groupv6 = InetAddress.getByName("ff02::1:" + (i+1));
-            groups.add(groupv4);
-            groups.add(groupv4mapped);
-            groups.add(groupv6);
+        for (NetIf netIf : netIfs) {
+            int NetIfIndex = netIf.index();
+            List<InetAddress> groups = new ArrayList<InetAddress>();
 
-            // use a separated thread to send to those 3 groups
-            Thread sender = new Thread(new Sender(nics.get(i), groupv4, groupv4mapped, groupv6, PORT));
+            if (netIf.ipv4Address()) {
+                InetAddress groupv4 = InetAddress.getByName("224.1." + NetIfIndex + ".1");
+                groups.add(groupv4);
+            }
+            if (netIf.ipv6Address()) {
+                InetAddress groupv6 = InetAddress.getByName("ff02::1:" + NetIfIndex);
+                groups.add(groupv6);
+            }
+
+            debug("Adding " + groups + " groups for " + netIf.nic().getName());
+            netIf.groups(groups);
+
+            // use a separated thread to send to those 2 groups
+            Thread sender = new Thread(new Sender(netIf,
+                                                  groups,
+                                                  PORT));
             sender.setDaemon(true); // we want sender to stop when main thread exits
             sender.start();
         }
@@ -107,75 +130,135 @@
         // from the expected network interface
         //
         byte[] buf = new byte[1024];
-        for (InetAddress group : groups) {
-        MulticastSocket mcastsock = new MulticastSocket(PORT);
-        mcastsock.setSoTimeout(5000);   // 5 second
-            DatagramPacket packet = new DatagramPacket(buf, 0, buf.length);
-
-            mcastsock.joinGroup(new InetSocketAddress(group, PORT), nics.get(groups.indexOf(group) / 3));
+        for (NetIf netIf : netIfs) {
+            NetworkInterface nic = netIf.nic();
+            for (InetAddress group : netIf.groups()) {
+                MulticastSocket mcastsock = new MulticastSocket(PORT);
+                mcastsock.setSoTimeout(5000);   // 5 second
+                DatagramPacket packet = new DatagramPacket(buf, 0, buf.length);
 
-            try {
-                mcastsock.receive(packet);
-            } catch (Exception e) {
-                // test failed if any exception
-                throw new RuntimeException(e);
-            }
+                // the interface supports the IP multicast group
+                debug("Joining " + group + " on " + nic.getName());
+                mcastsock.joinGroup(new InetSocketAddress(group, PORT), nic);
+
+                try {
+                    mcastsock.receive(packet);
+                    debug("received packet on " + packet.getAddress());
+                } catch (Exception e) {
+                    // test failed if any exception
+                    throw new RuntimeException(e);
+                }
 
-            // now check which network interface this packet comes from
-            NetworkInterface from = NetworkInterface.getByInetAddress(packet.getAddress());
-            NetworkInterface shouldbe = nics.get(groups.indexOf(group) / 3);
-            if (!from.equals(shouldbe)) {
-                System.out.println("Packets on group "
-                                    + group + " should come from "
-                                    + shouldbe.getName() + ", but came from "
-                                    + from.getName());
-                //throw new RuntimeException("Test failed.");
+                // now check which network interface this packet comes from
+                NetworkInterface from = NetworkInterface.getByInetAddress(packet.getAddress());
+                NetworkInterface shouldbe = nic;
+                if (!from.equals(shouldbe)) {
+                    System.out.println("Packets on group "
+                                        + group + " should come from "
+                                        + shouldbe.getName() + ", but came from "
+                                        + from.getName());
+                    //throw new RuntimeException("Test failed.");
+                }
+
+                mcastsock.leaveGroup(new InetSocketAddress(group, PORT), nic);
             }
+        }
+    }
 
-            mcastsock.leaveGroup(new InetSocketAddress(group, PORT), nics.get(groups.indexOf(group) / 3));
-        }
+    private static boolean debug = true;
+
+    static void debug(String message) {
+        if (debug)
+            System.out.println(message);
     }
 }
 
 class Sender implements Runnable {
-    private NetworkInterface nic;
-    private InetAddress group1;
-    private InetAddress group2;
-    private InetAddress group3;
+    private NetIf netIf;
+    private List<InetAddress> groups;
     private int port;
 
-    public Sender(NetworkInterface nic,
-                    InetAddress groupv4, InetAddress groupv4mapped, InetAddress groupv6,
-                    int port) {
-        this.nic = nic;
-        group1 = groupv4;
-        group2 = groupv4mapped;
-        group3 = groupv6;
+    public Sender(NetIf netIf,
+                  List<InetAddress> groups,
+                  int port) {
+        this.netIf = netIf;
+        this.groups = groups;
         this.port = port;
     }
 
     public void run() {
         try {
             MulticastSocket mcastsock = new MulticastSocket();
-            mcastsock.setNetworkInterface(nic);
+            mcastsock.setNetworkInterface(netIf.nic());
+            List<DatagramPacket> packets = new LinkedList<DatagramPacket>();
 
             byte[] buf = "hello world".getBytes();
-            DatagramPacket packet1 = new DatagramPacket(buf, buf.length,
-                                        new InetSocketAddress(group1, port));
-            DatagramPacket packet2 = new DatagramPacket(buf, buf.length,
-                                        new InetSocketAddress(group2, port));
-            DatagramPacket packet3 = new DatagramPacket(buf, buf.length,
-                                        new InetSocketAddress(group3, port));
+            for (InetAddress group : groups) {
+                packets.add(new DatagramPacket(buf, buf.length, new InetSocketAddress(group, port)));
+            }
 
             for (;;) {
-                mcastsock.send(packet1);
-                mcastsock.send(packet2);
-                mcastsock.send(packet3);
+                for (DatagramPacket packet : packets)
+                    mcastsock.send(packet);
 
-                Thread.currentThread().sleep(1000);   // sleep 1 second
+                Thread.sleep(1000);   // sleep 1 second
             }
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
     }
 }
+
+@SuppressWarnings("unchecked")
+class NetIf {
+    private boolean ipv4Address; //false
+    private boolean ipv6Address; //false
+    private int index;
+    List<InetAddress> groups = Collections.EMPTY_LIST;
+    private final NetworkInterface nic;
+
+    private NetIf(NetworkInterface nic) {
+        this.nic = nic;
+    }
+
+    static NetIf create(NetworkInterface nic) {
+        return new NetIf(nic);
+    }
+
+    NetworkInterface nic() {
+        return nic;
+    }
+
+    boolean ipv4Address() {
+        return ipv4Address;
+    }
+
+    void ipv4Address(boolean ipv4Address) {
+        this.ipv4Address = ipv4Address;
+    }
+
+    boolean ipv6Address() {
+        return ipv6Address;
+    }
+
+    void ipv6Address(boolean ipv6Address) {
+        this.ipv6Address = ipv6Address;
+    }
+
+    int index() {
+        return index;
+    }
+
+    void index(int index) {
+        this.index = index;
+    }
+
+    List<InetAddress> groups() {
+        return groups;
+    }
+
+    void groups(List<InetAddress> groups) {
+        this.groups = groups;
+    }
+}
+
--- a/jdk/test/java/nio/channels/Channels/Basic.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/test/java/nio/channels/Channels/Basic.java	Fri Oct 16 18:02:31 2009 -0700
@@ -22,7 +22,7 @@
  */
 
 /* @test
- * @bug 4417152 4481572 6248930 6725399
+ * @bug 4417152 4481572 6248930 6725399 6884800
  * @summary Test Channels basic functionality
  */
 
@@ -225,8 +225,7 @@
     private static void testNewInputStream(File blah) throws Exception {
         FileInputStream fis = new FileInputStream(blah);
         FileChannel fc = fis.getChannel();
-        ReadableByteChannel rbc = (ReadableByteChannel)fc;
-        InputStream is = Channels.newInputStream(rbc);
+        InputStream is = Channels.newInputStream(fc);
         int messageSize = message.length() * ITERATIONS * 3 + 1;
         byte bb[] = new byte[messageSize];
 
@@ -234,8 +233,13 @@
         int totalRead = 0;
         while (bytesRead != -1) {
             totalRead += bytesRead;
+            long rem = Math.min(fc.size() - totalRead, (long)Integer.MAX_VALUE);
+            if (is.available() != (int)rem)
+                throw new RuntimeException("available not useful or not maximally useful");
             bytesRead = is.read(bb, totalRead, messageSize - totalRead);
         }
+        if (is.available() != 0)
+           throw new RuntimeException("available() should return 0 at EOF");
 
         String result = new String(bb, 0, totalRead, encoding);
         int len = message.length();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JComponent/4337267/bug4337267.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,254 @@
+/*
+ * @test
+ * @bug 4337267
+ * @summary test that numeric shaping works in Swing components
+ * @author Sergey Groznyh
+ * @run main bug4337267
+ */
+
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.font.NumericShaper;
+import java.awt.font.TextAttribute;
+import java.awt.image.BufferedImage;
+import javax.swing.BoxLayout;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextArea;
+import javax.swing.SwingUtilities;
+
+public class bug4337267 {
+    TestJPanel p1, p2;
+    TestBufferedImage i1, i2;
+    JComponent[] printq;
+    JFrame window;
+    static boolean testFailed = false;
+    static boolean done = false;
+
+    String shaped =
+            "000 (E) 111 (A) \u0641\u0642\u0643 \u0662\u0662\u0662 (E) 333";
+    String text = "000 (E) 111 (A) \u0641\u0642\u0643 222 (E) 333";
+
+    void run() {
+        initUI();
+        testTextComponent();
+        testNonTextComponentHTML();
+        testNonTextComponentPlain();
+
+        doneTask();
+    }
+
+    void initUI() {
+        window = new JFrame("bug4337267");
+        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+        window.setSize(800, 600);
+        Component content = createContentPane();
+        window.add(content);
+        window.setVisible(true);
+    }
+
+    Runnable printComponents = new Runnable() {
+        public void run() {
+            printComponent(printq[0], i1);
+            printComponent(printq[1], i2);
+        }
+    };
+
+    Runnable compareRasters = new Runnable() {
+        public void run() {
+            assertEquals(p1.image, p2.image);
+            assertEquals(i1, i2);
+        }
+    };
+
+    void doneTask() {
+        final Object monitor = this;
+        SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+                done = true;
+                synchronized(monitor) {
+                    monitor.notify();
+                }
+            }
+        });
+    }
+
+
+    void fail(String message) {
+        testFailed = true;
+        throw new RuntimeException(message);
+    }
+
+    void assertEquals(Object o1, Object o2) {
+        if ((o1 == null) && (o2 != null)) {
+            fail("Expected null, got " + o2);
+        } else if ((o1 != null) && (o2 == null)) {
+            fail("Expected " + o1 + ", got null");
+        } else if (!o1.equals(o2)) {
+            fail("Expected " + o1 + ", got " + o2);
+        }
+    }
+
+    void testTextComponent() {
+        System.out.println("testTextComponent:");
+        JTextArea area1 = new JTextArea();
+        injectComponent(p1, area1, false);
+        area1.setText(shaped);
+        JTextArea area2 = new JTextArea();
+        injectComponent(p2, area2, true);
+        area2.setText(text);
+        window.repaint();
+        printq = new JComponent[] { area1, area2 };
+        SwingUtilities.invokeLater(printComponents);
+        SwingUtilities.invokeLater(compareRasters);
+    }
+
+    void testNonTextComponentHTML() {
+        System.out.println("testNonTextComponentHTML:");
+        JLabel label1 = new JLabel();
+        injectComponent(p1, label1, false);
+        label1.setText("<html>" + shaped);
+        JLabel label2 = new JLabel();
+        injectComponent(p2, label2, true);
+        label2.setText("<html>" + text);
+        window.repaint();
+        printq = new JComponent[] { label1, label2 };
+        SwingUtilities.invokeLater(printComponents);
+        SwingUtilities.invokeLater(compareRasters);
+    }
+
+    void testNonTextComponentPlain() {
+        System.out.println("testNonTextComponentHTML:");
+        JLabel label1 = new JLabel();
+        injectComponent(p1, label1, false);
+        label1.setText(shaped);
+        JLabel label2 = new JLabel();
+        injectComponent(p2, label2, true);
+        label2.setText(text);
+        window.repaint();
+        printq = new JComponent[] { label1, label2 };
+        SwingUtilities.invokeLater(printComponents);
+        SwingUtilities.invokeLater(compareRasters);
+    }
+
+    void setShaping(JComponent c) {
+        c.putClientProperty(TextAttribute.NUMERIC_SHAPING,
+                    NumericShaper.getContextualShaper(NumericShaper.ARABIC));
+    }
+
+    void injectComponent(JComponent p, JComponent c, boolean shape) {
+        if (shape) {
+            setShaping(c);
+        }
+        p.removeAll();
+        p.add(c);
+    }
+
+    void printComponent(JComponent c, TestBufferedImage i) {
+        Graphics g = i.getGraphics();
+        g.setColor(c.getBackground());
+        g.fillRect(0, 0, i.getWidth(), i.getHeight());
+        c.print(g);
+    }
+
+    Component createContentPane() {
+        Dimension size = new Dimension(500, 100);
+        i1 = new TestBufferedImage(size.width, size.height,
+                                                BufferedImage.TYPE_INT_ARGB);
+        i2 = new TestBufferedImage(size.width, size.height,
+                                                BufferedImage.TYPE_INT_ARGB);
+        p1 = new TestJPanel();
+        p1.setPreferredSize(size);
+        p2 = new TestJPanel();
+        p2.setPreferredSize(size);
+        JPanel panel = new JPanel();
+        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
+        panel.add(p1);
+        panel.add(p2);
+
+        return panel;
+    }
+
+    static class TestBufferedImage extends BufferedImage {
+        int MAX_GLITCHES = 0;
+
+        TestBufferedImage(int width, int height, int imageType) {
+            super(width, height, imageType);
+        }
+
+        @Override
+        public boolean equals(Object other) {
+            if (! (other instanceof TestBufferedImage)) {
+                return false;
+            }
+            TestBufferedImage image2 = (TestBufferedImage) other;
+            int width = getWidth();
+            int height = getHeight();
+            if ((image2.getWidth() != width) || (image2.getHeight() != height)) {
+                return false;
+            }
+            int glitches = 0;
+            for (int x = 0; x < width; x++) {
+                for (int y = 0; y < height; y++) {
+                    int rgb1 = getRGB(x, y);
+                    int rgb2 = image2.getRGB(x, y);
+                    if (rgb1 != rgb2) {
+                        //System.out.println(x+" "+y+" "+rgb1+" "+rgb2);
+                        glitches++;
+                    }
+                }
+            }
+            return glitches <= MAX_GLITCHES;
+        }
+    }
+
+    static class TestJPanel extends JPanel {
+        TestBufferedImage image = createImage(new Dimension(1, 1));
+
+        TestBufferedImage createImage(Dimension d) {
+            return new TestBufferedImage(d.width, d.height,
+                                                BufferedImage.TYPE_INT_ARGB);
+        }
+
+        public void setPreferredSize(Dimension size) {
+            super.setPreferredSize(size);
+            image = createImage(size);
+        }
+
+        public void paint(Graphics g) {
+            Graphics g0 = image.getGraphics();
+            super.paint(g0);
+            g.drawImage(image, 0, 0, this);
+        }
+    }
+
+
+
+    public static void main(String[] args) throws Throwable {
+        final bug4337267 test = new bug4337267();
+        SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+                test.run();
+            }
+        });
+
+         synchronized(test) {
+            while (!done) {
+                try {
+                    test.wait();
+                } catch (InterruptedException ex) {
+                    // do nothing
+                }
+            }
+        }
+
+        if (testFailed) {
+            throw new RuntimeException("FAIL");
+        }
+
+        System.out.println("OK");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JFileChooser/6489130/bug6489130.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @bug 6489130
+ * @summary FileChooserDemo hung by keeping pressing Enter key
+ * @author Pavel Porvatov
+   @run main bug6489130
+ */
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+public class bug6489130 {
+    private final JFileChooser chooser = new JFileChooser();
+
+    private static final CountDownLatch MUX = new CountDownLatch(1);
+
+    private final Timer timer = new Timer(1000, new ActionListener() {
+        public void actionPerformed(ActionEvent e) {
+            switch (state) {
+                case 0:
+                case 1: {
+                    SwingUtilities.invokeLater(new Runnable() {
+                        public void run() {
+                            chooser.showOpenDialog(null);
+                        }
+                    });
+
+                    break;
+                }
+
+                case 2:
+                case 3: {
+                    Window[] windows = Frame.getWindows();
+
+                    if (windows.length > 0) {
+                        windows[0].dispose();
+                    }
+
+                    break;
+                }
+
+                case 4: {
+                    MUX.countDown();
+
+                    break;
+                }
+            }
+
+            state++;
+        }
+    });
+
+    private int state = 0;
+
+    public static void main(String[] args) throws InterruptedException {
+        SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+                new bug6489130().run();
+            }
+        });
+
+        if (!MUX.await(10, TimeUnit.SECONDS)) {
+            throw new RuntimeException("Timeout");
+        }
+    }
+
+    private void run() {
+        timer.start();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JFileChooser/6840086/bug6840086.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+   @bug 6840086
+   @summary JFileChooser lacks icons on top right when running on Windows 7
+   @author Pavel Porvatov
+   @run main bug6840086
+*/
+
+import sun.awt.OSInfo;
+import sun.awt.shell.ShellFolder;
+
+import java.awt.*;
+
+public class bug6840086 {
+    private static final String[] KEYS = {
+        "fileChooserIcon ListView",
+        "fileChooserIcon ViewMenu",
+        "fileChooserIcon DetailsView",
+        "fileChooserIcon UpFolder",
+        "fileChooserIcon NewFolder",
+    };
+
+    public static void main(String[] args) {
+        if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
+            System.out.println("The test was skipped because it is sensible only for Windows.");
+
+            return;
+        }
+
+        for (String key : KEYS) {
+            Image image = (Image) ShellFolder.get(key);
+
+            if (image == null) {
+                throw new RuntimeException("The image '" + key + "' not found.");
+            }
+
+            if (image != ShellFolder.get(key)) {
+                throw new RuntimeException("The image '" + key + "' is not cached.");
+            }
+        }
+
+        System.out.println("The test passed.");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JLayer/6875716/bug6875716.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @bug 6875716
+ * @summary JLayer.remove((Component)null) should behave consistently in (not) throwing NPE
+ * @author Alexander Potochkin
+ */
+
+import javax.swing.*;
+import java.awt.*;
+
+public class bug6875716 {
+
+    public static void main(String[] args) throws Exception {
+        JLayer<Component> layer = new JLayer<Component>(new Component(){});
+        layer.setGlassPane(null);
+        try {
+            layer.remove((Component)null);
+        } catch (NullPointerException e) {
+            //this is what we expect
+            return;
+        }
+        throw new RuntimeException("Test failed");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JMenuItem/6883341/bug6883341.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+ /*
+ * @test
+ * @bug 6883341
+ * @summary Checks that menu items with no text don't throw an exception
+ * @author Alexander Potochkin
+ * @run main bug6883341
+ */
+
+import javax.swing.*;
+
+public class bug6883341 {
+
+    private static void createGui() {
+        JPopupMenu menu = new JPopupMenu();
+        menu.add(new JMenuItem());
+        menu.setVisible(true);
+        menu.setVisible(false);
+    }
+
+    public static void main(String[] args) throws Exception {
+        SwingUtilities.invokeAndWait(new Runnable() {
+            public void run() {
+                bug6883341.createGui();
+            }
+        });
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/sun/misc/BootClassLoaderHook/TestHook.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+import java.io.File;
+import java.util.TreeSet;
+import java.util.Set;
+import sun.misc.BootClassLoaderHook;
+
+/* @test
+ * @bug     6888802
+ * @summary Sanity test of BootClassLoaderHook interface
+ *
+ * @build TestHook
+ * @run main TestHook
+ */
+
+public class TestHook extends BootClassLoaderHook {
+
+    private static final TestHook hook = new TestHook();
+    private static Set<String> names = new TreeSet<String>();
+    private static final String LOGRECORD_CLASS =
+        "java.util.logging.LogRecord";
+    private static final String NONEXIST_RESOURCE =
+        "non.exist.resource";
+    private static final String LIBHELLO = "hello";
+
+    public static void main(String[] args) throws Exception {
+        BootClassLoaderHook.setHook(hook);
+        if (BootClassLoaderHook.getHook() == null) {
+           throw new RuntimeException("Null boot classloader hook ");
+        }
+
+        testHook();
+
+        if (!names.contains(LOGRECORD_CLASS)) {
+           throw new RuntimeException("loadBootstrapClass for " + LOGRECORD_CLASS + " not called");
+        }
+
+        if (!names.contains(NONEXIST_RESOURCE)) {
+           throw new RuntimeException("getBootstrapResource for " + NONEXIST_RESOURCE + " not called");
+        }
+        if (!names.contains(LIBHELLO)) {
+           throw new RuntimeException("loadLibrary for " + LIBHELLO + " not called");
+        }
+
+        Set<String> copy = new TreeSet<String>();
+        copy.addAll(names);
+        for (String s : copy) {
+            System.out.println("  Loaded " + s);
+        }
+
+        if (BootClassLoaderHook.getBootstrapPaths().length > 0) {
+           throw new RuntimeException("Unexpected returned value from getBootstrapPaths()");
+        }
+    }
+
+    private static void testHook() throws Exception {
+        Class.forName(LOGRECORD_CLASS);
+        ClassLoader.getSystemResource(NONEXIST_RESOURCE);
+        try {
+          System.loadLibrary(LIBHELLO);
+        } catch (UnsatisfiedLinkError e) {
+        }
+    }
+
+    public String loadBootstrapClass(String className) {
+        names.add(className);
+        return null;
+    }
+
+    public String getBootstrapResource(String resourceName) {
+        names.add(resourceName);
+        return null;
+    }
+
+    public boolean loadLibrary(String libname) {
+        names.add(libname);
+        return false;
+    }
+
+    public File[] getAdditionalBootstrapPaths() {
+        return new File[0];
+    }
+
+    public boolean isCurrentThreadPrefetching() {
+        return false;
+    }
+
+    public boolean prefetchFile(String name) {
+        return false;
+    }
+}
--- a/jdk/test/sun/net/www/httptest/HttpTransaction.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/test/sun/net/www/httptest/HttpTransaction.java	Fri Oct 16 18:02:31 2009 -0700
@@ -102,7 +102,8 @@
         if (rspheaders != null) {
             buf.append (rspheaders.toString()).append("\r\n");
         }
-        buf.append ("Body: ").append (new String(rspbody)).append("\r\n");
+        String rbody = rspbody == null? "": new String (rspbody);
+        buf.append ("Body: ").append (rbody).append("\r\n");
         return new String (buf);
     }
 
--- a/jdk/test/sun/security/krb5/IPv6.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/test/sun/security/krb5/IPv6.java	Fri Oct 16 18:02:31 2009 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 6877357
+ * @bug 6877357 6885166
  * @summary IPv6 address does not work
  */
 
@@ -57,6 +57,7 @@
         PrintStream out = new PrintStream(new FileOutputStream("ipv6.conf"));
         out.println("[libdefaults]");
         out.println("default_realm = V6");
+        out.println("kdc_timeout = 1");
         out.println("[realms]");
         out.println("V6 = {");
         for (String[] hp: kdcs) {
@@ -95,10 +96,12 @@
         po.flush();
 
         System.setOut(oldout);
-        String[] lines = new String(bo.toByteArray()).split("\n");
+        BufferedReader br = new BufferedReader(new StringReader(
+                new String(bo.toByteArray())));
         int cc = 0;
         Pattern r = Pattern.compile(".*KrbKdcReq send: kdc=(.*) UDP:(\\d+),.*");
-        for (String line: lines) {
+        String line;
+        while ((line = br.readLine()) != null) {
             Matcher m = r.matcher(line.subSequence(0, line.length()));
             if (m.matches()) {
                 System.out.println("------------------");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/sun/security/krb5/RFC396xTest.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,248 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+/*
+ * @test
+ * @bug 6862679
+ * @summary ESC: AD Authentication with user with umlauts fails
+ */
+
+import java.lang.reflect.Array;
+import java.lang.reflect.Method;
+import sun.security.krb5.EncryptedData;
+import sun.security.krb5.internal.crypto.Des;
+import sun.security.krb5.internal.crypto.EType;
+import sun.security.krb5.internal.crypto.crc32;
+import sun.security.krb5.internal.crypto.dk.AesDkCrypto;
+import sun.security.krb5.internal.crypto.dk.Des3DkCrypto;
+import sun.security.krb5.internal.crypto.dk.DkCrypto;
+import java.nio.*;
+import javax.crypto.*;
+import javax.crypto.spec.*;
+
+public class RFC396xTest {
+
+    static final String gclef = new String(Character.toChars(0x1d11e));
+
+    /** Creates a new instance of NewClass */
+    public static void main(String[] args) throws Exception {
+        System.setProperty("sun.security.krb5.msinterop.des.s2kcharset",
+                "utf-8");
+        test();
+    }
+
+    static void test() throws Exception {
+        // RFC 3961
+        // A.1
+        Method nfold = DkCrypto.class.getDeclaredMethod("nfold", byte[].class, Integer.TYPE);
+        nfold.setAccessible(true);
+        assertStringEquals(hex((byte[])nfold.invoke(null, "012345".getBytes("UTF-8"), 64)), "be072631276b1955");
+        assertStringEquals(hex((byte[])nfold.invoke(null, "password".getBytes("UTF-8"), 56)), "78a07b6caf85fa");
+        assertStringEquals(hex((byte[])nfold.invoke(null, "Rough Consensus, and Running Code".getBytes("UTF-8"), 64)), "bb6ed30870b7f0e0");
+        assertStringEquals(hex((byte[])nfold.invoke(null, "password".getBytes("UTF-8"), 168)), "59e4a8ca7c0385c3c37b3f6d2000247cb6e6bd5b3e");
+        assertStringEquals(hex((byte[])nfold.invoke(null, "MASSACHVSETTS INSTITVTE OF TECHNOLOGY".getBytes("UTF-8"), 192)), "db3b0d8f0b061e603282b308a50841229ad798fab9540c1b");
+        assertStringEquals(hex((byte[])nfold.invoke(null, "Q".getBytes("UTF-8"), 168)), "518a54a215a8452a518a54a215a8452a518a54a215");
+        assertStringEquals(hex((byte[])nfold.invoke(null, "ba".getBytes("UTF-8"), 168)), "fb25d531ae8974499f52fd92ea9857c4ba24cf297e");
+        assertStringEquals(hex((byte[])nfold.invoke(null, "kerberos".getBytes("UTF-8"), 64)), "6b65726265726f73");
+        assertStringEquals(hex((byte[])nfold.invoke(null, "kerberos".getBytes("UTF-8"), 128)), "6b65726265726f737b9b5b2b93132b93");
+        assertStringEquals(hex((byte[])nfold.invoke(null, "kerberos".getBytes("UTF-8"), 168)), "8372c236344e5f1550cd0747e15d62ca7a5a3bcea4");
+        assertStringEquals(hex((byte[])nfold.invoke(null, "kerberos".getBytes("UTF-8"), 256)), "6b65726265726f737b9b5b2b93132b935c9bdcdad95c9899c4cae4dee6d6cae4");
+
+        // A.2
+        assertStringEquals(hex(Des.string_to_key_bytes("passwordATHENA.MIT.EDUraeburn".toCharArray())), "cbc22fae235298e3");
+        assertStringEquals(hex(Des.string_to_key_bytes("potatoeWHITEHOUSE.GOVdanny".toCharArray())), "df3d32a74fd92a01");
+        assertStringEquals(hex(Des.string_to_key_bytes((gclef+"EXAMPLE.COMpianist").toCharArray())), "4ffb26bab0cd9413");
+        assertStringEquals(hex(Des.string_to_key_bytes("\u00dfATHENA.MIT.EDUJuri\u0161i\u0107".toCharArray())), "62c81a5232b5e69d");
+        // Next 2 won't pass, since there's no real weak key here
+        //assertStringEquals(hex(Des.string_to_key_bytes("11119999AAAAAAAA".toCharArray())), "984054d0f1a73e31");
+        //assertStringEquals(hex(Des.string_to_key_bytes("NNNN6666FFFFAAAA".toCharArray())), "c4bf6b25adf7a4f8");
+
+        // A.3
+        Object o = Des3DkCrypto.class.getConstructor().newInstance();
+        Method dr = DkCrypto.class.getDeclaredMethod("dr", byte[].class, byte[].class);
+        Method randomToKey = DkCrypto.class.getDeclaredMethod("randomToKey", byte[].class);
+        dr.setAccessible(true);
+        randomToKey.setAccessible(true);
+        assertStringEquals(hex((byte[])randomToKey.invoke(o, (byte[])dr.invoke(o,
+                xeh("dce06b1f64c857a11c3db57c51899b2cc1791008ce973b92"),
+                xeh("0000000155")))),
+                "925179d04591a79b5d3192c4a7e9c289b049c71f6ee604cd");
+        assertStringEquals(hex((byte[])randomToKey.invoke(o, (byte[])dr.invoke(o,
+                xeh("5e13d31c70ef765746578531cb51c15bf11ca82c97cee9f2"),
+                xeh("00000001aa")))),
+                "9e58e5a146d9942a101c469845d67a20e3c4259ed913f207");
+        assertStringEquals(hex((byte[])randomToKey.invoke(o, (byte[])dr.invoke(o,
+                xeh("98e6fd8a04a4b6859b75a176540b9752bad3ecd610a252bc"),
+                xeh("0000000155")))),
+                "13fef80d763e94ec6d13fd2ca1d085070249dad39808eabf");
+        assertStringEquals(hex((byte[])randomToKey.invoke(o, (byte[])dr.invoke(o,
+                xeh("622aec25a2fe2cad7094680b7c64940280084c1a7cec92b5"),
+                xeh("00000001aa")))),
+                "f8dfbf04b097e6d9dc0702686bcb3489d91fd9a4516b703e");
+        assertStringEquals(hex((byte[])randomToKey.invoke(o, (byte[])dr.invoke(o,
+                xeh("d3f8298ccb166438dcb9b93ee5a7629286a491f838f802fb"),
+                xeh("6b65726265726f73")))),
+                "2370da575d2a3da864cebfdc5204d56df779a7df43d9da43");
+        assertStringEquals(hex((byte[])randomToKey.invoke(o, (byte[])dr.invoke(o,
+                xeh("c1081649ada74362e6a1459d01dfd30d67c2234c940704da"),
+                xeh("0000000155")))),
+                "348057ec98fdc48016161c2a4c7a943e92ae492c989175f7");
+        assertStringEquals(hex((byte[])randomToKey.invoke(o, (byte[])dr.invoke(o,
+                xeh("5d154af238f46713155719d55e2f1f790dd661f279a7917c"),
+                xeh("00000001aa")))),
+                "a8808ac267dada3dcbe9a7c84626fbc761c294b01315e5c1");
+        assertStringEquals(hex((byte[])randomToKey.invoke(o, (byte[])dr.invoke(o,
+                xeh("798562e049852f57dc8c343ba17f2ca1d97394efc8adc443"),
+                xeh("0000000155")))),
+                "c813f88a3be3b334f75425ce9175fbe3c8493b89c8703b49");
+        assertStringEquals(hex((byte[])randomToKey.invoke(o, (byte[])dr.invoke(o,
+                xeh("26dce334b545292f2feab9a8701a89a4b99eb9942cecd016"),
+                xeh("00000001aa")))),
+                "f48ffd6e83f83e7354e694fd252cf83bfe58f7d5ba37ec5d");
+
+        // A.4
+        assertStringEquals(hex(new Des3DkCrypto().stringToKey("passwordATHENA.MIT.EDUraeburn".toCharArray())), "850bb51358548cd05e86768c313e3bfef7511937dcf72c3e");
+        assertStringEquals(hex(new Des3DkCrypto().stringToKey("potatoeWHITEHOUSE.GOVdanny".toCharArray())), "dfcd233dd0a43204ea6dc437fb15e061b02979c1f74f377a");
+        assertStringEquals(hex(new Des3DkCrypto().stringToKey("pennyEXAMPLE.COMbuckaroo".toCharArray())), "6d2fcdf2d6fbbc3ddcadb5da5710a23489b0d3b69d5d9d4a");
+        assertStringEquals(hex(new Des3DkCrypto().stringToKey("\u00DFATHENA.MIT.EDUJuri\u0161i\u0107".toCharArray())), "16d5a40e1ce3bacb61b9dce00470324c831973a7b952feb0");
+        assertStringEquals(hex(new Des3DkCrypto().stringToKey((gclef+"EXAMPLE.COMpianist").toCharArray())), "85763726585dbc1cce6ec43e1f751f07f1c4cbb098f40b19");
+
+        // A.5
+        assertStringEquals(hex(crc32.byte2crc32sum_bytes("foo".getBytes("UTF-8"))), "33bc3273");
+        assertStringEquals(hex(crc32.byte2crc32sum_bytes("test0123456789".getBytes("UTF-8"))), "d6883eb8");
+        assertStringEquals(hex(crc32.byte2crc32sum_bytes("MASSACHVSETTS INSTITVTE OF TECHNOLOGY".getBytes("UTF-8"))), "f78041e3");
+        assertStringEquals(hex(crc32.byte2crc32sum_bytes(new byte[] {(byte)0x80, 0})), "4b98833b");
+        assertStringEquals(hex(crc32.byte2crc32sum_bytes(new byte[] {0, 8})), "3288db0e");
+        assertStringEquals(hex(crc32.byte2crc32sum_bytes(new byte[] {0, (byte)0x80})), "2083b8ed");
+        assertStringEquals(hex(crc32.byte2crc32sum_bytes(new byte[] {(byte)0x80})), "2083b8ed");
+        assertStringEquals(hex(crc32.byte2crc32sum_bytes(new byte[] {(byte)0x80, 0, 0, 0})), "3bb659ed");
+        assertStringEquals(hex(crc32.byte2crc32sum_bytes(new byte[] {0, 0, 0, 1})), "96300777");
+
+        // RFC 3962
+        AesDkCrypto a1 = new AesDkCrypto(128);
+        Method pbkdf2 = AesDkCrypto.class.getDeclaredMethod("PBKDF2", char[].class, byte[].class, Integer.TYPE, Integer.TYPE);
+        Method s2k = AesDkCrypto.class.getDeclaredMethod("stringToKey", char[].class, byte[].class, byte[].class);
+        pbkdf2.setAccessible(true);
+        s2k.setAccessible(true);
+        assertStringEquals(hex((byte[])pbkdf2.invoke(null, "password".toCharArray(), "ATHENA.MIT.EDUraeburn".getBytes("UTF-8"), 1, 128)), "cd ed b5 28 1b b2 f8 01 56 5a 11 22 b2 56 35 15");
+        assertStringEquals(hex(a1.stringToKey("password".toCharArray(), "ATHENA.MIT.EDUraeburn", i2b(1))), "42 26 3c 6e 89 f4 fc 28 b8 df 68 ee 09 79 9f 15");
+        assertStringEquals(hex((byte[])pbkdf2.invoke(null, "password".toCharArray(), "ATHENA.MIT.EDUraeburn".getBytes("UTF-8"), 1, 256)), "cd ed b5 28 1b b2 f8 01 56 5a 11 22 b2 56 35 15  0a d1 f7 a0 4b b9 f3 a3 33 ec c0 e2 e1 f7 08 37");
+        assertStringEquals(hex((byte[])pbkdf2.invoke(null, "password".toCharArray(), "ATHENA.MIT.EDUraeburn".getBytes("UTF-8"), 2, 128)), "01 db ee 7f 4a 9e 24 3e 98 8b 62 c7 3c da 93 5d");
+        assertStringEquals(hex(a1.stringToKey("password".toCharArray(), "ATHENA.MIT.EDUraeburn", i2b(2))), "c6 51 bf 29 e2 30 0a c2 7f a4 69 d6 93 bd da 13");
+        assertStringEquals(hex((byte[])pbkdf2.invoke(null, "password".toCharArray(), "ATHENA.MIT.EDUraeburn".getBytes("UTF-8"), 2, 256)), "01 db ee 7f 4a 9e 24 3e 98 8b 62 c7 3c da 93 5d  a0 53 78 b9 32 44 ec 8f 48 a9 9e 61 ad 79 9d 86");
+        assertStringEquals(hex((byte[])pbkdf2.invoke(null, "password".toCharArray(), "ATHENA.MIT.EDUraeburn".getBytes("UTF-8"), 1200, 128)), "5c 08 eb 61 fd f7 1e 4e 4e c3 cf 6b a1 f5 51 2b");
+        assertStringEquals(hex(a1.stringToKey("password".toCharArray(), "ATHENA.MIT.EDUraeburn", i2b(1200))), "4c 01 cd 46 d6 32 d0 1e 6d be 23 0a 01 ed 64 2a");
+        assertStringEquals(hex((byte[])pbkdf2.invoke(null, "password".toCharArray(), "ATHENA.MIT.EDUraeburn".getBytes("UTF-8"), 1200, 256)), "5c 08 eb 61 fd f7 1e 4e 4e c3 cf 6b a1 f5 51 2b  a7 e5 2d db c5 e5 14 2f 70 8a 31 e2 e6 2b 1e 13");
+        assertStringEquals(hex((byte[])pbkdf2.invoke(null, "password".toCharArray(), xeh("1234567878563412"), 5, 128)), "d1 da a7 86 15 f2 87 e6 a1 c8 b1 20 d7 06 2a 49");
+        assertStringEquals(hex((byte[])s2k.invoke(a1, "password".toCharArray(), xeh("1234567878563412"), i2b(5))), "e9 b2 3d 52 27 37 47 dd 5c 35 cb 55 be 61 9d 8e");
+        assertStringEquals(hex((byte[])pbkdf2.invoke(null, "password".toCharArray(), xeh("1234567878563412"), 5, 256)), "d1 da a7 86 15 f2 87 e6 a1 c8 b1 20 d7 06 2a 49  3f 98 d2 03 e6 be 49 a6 ad f4 fa 57 4b 6e 64 ee");
+        assertStringEquals(hex((byte[])pbkdf2.invoke(null, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX".toCharArray(), "pass phrase equals block size".getBytes("UTF-8"), 1200, 128)), "13 9c 30 c0 96 6b c3 2b a5 5f db f2 12 53 0a c9");
+        assertStringEquals(hex(a1.stringToKey("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX".toCharArray(), "pass phrase equals block size", i2b(1200))), "59 d1 bb 78 9a 82 8b 1a a5 4e f9 c2 88 3f 69 ed");
+        assertStringEquals(hex((byte[])pbkdf2.invoke(null, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX".toCharArray(), "pass phrase equals block size".getBytes("UTF-8"), 1200, 256)), "13 9c 30 c0 96 6b c3 2b a5 5f db f2 12 53 0a c9  c5 ec 59 f1 a4 52 f5 cc 9a d9 40 fe a0 59 8e d1");
+        assertStringEquals(hex((byte[])pbkdf2.invoke(null, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX".toCharArray(), "pass phrase exceeds block size".getBytes("UTF-8"), 1200, 128)), "9c ca d6 d4 68 77 0c d5 1b 10 e6 a6 87 21 be 61");
+        assertStringEquals(hex(a1.stringToKey("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX".toCharArray(), "pass phrase exceeds block size", i2b(1200))), "cb 80 05 dc 5f 90 17 9a 7f 02 10 4c 00 18 75 1d");
+        assertStringEquals(hex((byte[])pbkdf2.invoke(null, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX".toCharArray(), "pass phrase exceeds block size".getBytes("UTF-8"), 1200, 256)), "9c ca d6 d4 68 77 0c d5 1b 10 e6 a6 87 21 be 61  1a 8b 4d 28 26 01 db 3b 36 be 92 46 91 5e c8 2a");
+        assertStringEquals(hex((byte[])pbkdf2.invoke(null, gclef.toCharArray(), "EXAMPLE.COMpianist".getBytes("UTF-8"), 50, 128)), "6b 9c f2 6d 45 45 5a 43 a5 b8 bb 27 6a 40 3b 39");
+        assertStringEquals(hex(a1.stringToKey(gclef.toCharArray(), "EXAMPLE.COMpianist", i2b(50))), "f1 49 c1 f2 e1 54 a7 34 52 d4 3e 7f e6 2a 56 e5");
+        assertStringEquals(hex((byte[])pbkdf2.invoke(null, gclef.toCharArray(), "EXAMPLE.COMpianist".getBytes("UTF-8"), 50, 256)), "6b 9c f2 6d 45 45 5a 43 a5 b8 bb 27 6a 40 3b 39  e7 fe 37 a0 c4 1e 02 c2 81 ff 30 69 e1 e9 4f 52");
+
+        if (EType.isSupported(EncryptedData.ETYPE_AES256_CTS_HMAC_SHA1_96)) {
+            AesDkCrypto a2 = new AesDkCrypto(256);
+            assertStringEquals(hex(a2.stringToKey("password".toCharArray(), "ATHENA.MIT.EDUraeburn", i2b(1))), "fe 69 7b 52 bc 0d 3c e1 44 32 ba 03 6a 92 e6 5b  bb 52 28 09 90 a2 fa 27 88 39 98 d7 2a f3 01 61");
+            assertStringEquals(hex(a2.stringToKey("password".toCharArray(), "ATHENA.MIT.EDUraeburn", i2b(2))), "a2 e1 6d 16 b3 60 69 c1 35 d5 e9 d2 e2 5f 89 61  02 68 56 18 b9 59 14 b4 67 c6 76 22 22 58 24 ff");
+            assertStringEquals(hex(a2.stringToKey("password".toCharArray(), "ATHENA.MIT.EDUraeburn", i2b(1200))), "55 a6 ac 74 0a d1 7b 48 46 94 10 51 e1 e8 b0 a7  54 8d 93 b0 ab 30 a8 bc 3f f1 62 80 38 2b 8c 2a");
+            assertStringEquals(hex((byte[])s2k.invoke(a2, "password".toCharArray(), xeh("1234567878563412"), i2b(5))), "97 a4 e7 86 be 20 d8 1a 38 2d 5e bc 96 d5 90 9c  ab cd ad c8 7c a4 8f 57 45 04 15 9f 16 c3 6e 31");
+            assertStringEquals(hex(a2.stringToKey("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX".toCharArray(), "pass phrase equals block size", i2b(1200))), "89 ad ee 36 08 db 8b c7 1f 1b fb fe 45 94 86 b0  56 18 b7 0c ba e2 20 92 53 4e 56 c5 53 ba 4b 34");
+            assertStringEquals(hex(a2.stringToKey("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX".toCharArray(), "pass phrase exceeds block size", i2b(1200))), "d7 8c 5c 9c b8 72 a8 c9 da d4 69 7f 0b b5 b2 d2 14 96 c8 2b eb 2c ae da 21 12 fc ee a0 57 40 1b");
+            assertStringEquals(hex(a2.stringToKey(gclef.toCharArray(), "EXAMPLE.COMpianist", i2b(50))), "4b 6d 98 39 f8 44 06 df 1f 09 cc 16 6d b4 b8 3c  57 18 48 b7 84 a3 d6 bd c3 46 58 9a 3e 39 3f 9e");
+        }
+
+        Cipher cipher = Cipher.getInstance("AES/CTS/NoPadding");
+
+        cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(
+                xeh("63 68 69 63 6b 65 6e 20 74 65 72 69 79 61 6b 69"), "AES"),
+                new IvParameterSpec(
+                xeh("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"), 0, 16));
+        assertStringEquals(hex(cipher.doFinal(
+                xeh("49 20 77 6f 75 6c 64 20 6c 69 6b 65 20 74 68 65 20"))),
+                "c6 35 35 68 f2 bf 8c b4 d8 a5 80 36 2d a7 ff 7f  97");
+        assertStringEquals(hex(cipher.doFinal(
+                xeh("49 20 77 6f 75 6c 64 20 6c 69 6b 65 20 74 68 65  20 47 65 6e 65 72 61 6c 20 47 61 75 27 73 20"))),
+                "fc 00 78 3e 0e fd b2 c1 d4 45 d4 c8 ef f7 ed 22  97 68 72 68 d6 ec cc c0 c0 7b 25 e2 5e cf e5");
+        assertStringEquals(hex(cipher.doFinal(
+                xeh("49 20 77 6f 75 6c 64 20 6c 69 6b 65 20 74 68 65  20 47 65 6e 65 72 61 6c 20 47 61 75 27 73 20 43"))),
+                "39 31 25 23 a7 86 62 d5 be 7f cb cc 98 eb f5 a8  97 68 72 68 d6 ec cc c0 c0 7b 25 e2 5e cf e5 84");
+        assertStringEquals(hex(cipher.doFinal(
+                xeh("49 20 77 6f 75 6c 64 20 6c 69 6b 65 20 74 68 65  20 47 65 6e 65 72 61 6c 20 47 61 75 27 73 20 43  68 69 63 6b 65 6e 2c 20 70 6c 65 61 73 65 2c"))),
+                "97 68 72 68 d6 ec cc c0 c0 7b 25 e2 5e cf e5 84  b3 ff fd 94 0c 16 a1 8c 1b 55 49 d2 f8 38 02 9e  39 31 25 23 a7 86 62 d5 be 7f cb cc 98 eb f5");
+        assertStringEquals(hex(cipher.doFinal(
+                xeh("49 20 77 6f 75 6c 64 20 6c 69 6b 65 20 74 68 65  20 47 65 6e 65 72 61 6c 20 47 61 75 27 73 20 43  68 69 63 6b 65 6e 2c 20 70 6c 65 61 73 65 2c 20"))),
+                "97 68 72 68 d6 ec cc c0 c0 7b 25 e2 5e cf e5 84  9d ad 8b bb 96 c4 cd c0 3b c1 03 e1 a1 94 bb d8  39 31 25 23 a7 86 62 d5 be 7f cb cc 98 eb f5 a8");
+        assertStringEquals(hex(cipher.doFinal(
+                xeh("49 20 77 6f 75 6c 64 20 6c 69 6b 65 20 74 68 65  20 47 65 6e 65 72 61 6c 20 47 61 75 27 73 20 43  68 69 63 6b 65 6e 2c 20 70 6c 65 61 73 65 2c 20  61 6e 64 20 77 6f 6e 74 6f 6e 20 73 6f 75 70 2e"))),
+                "97 68 72 68 d6 ec cc c0 c0 7b 25 e2 5e cf e5 84  39 31 25 23 a7 86 62 d5 be 7f cb cc 98 eb f5 a8  48 07 ef e8 36 ee 89 a5 26 73 0d bc 2f 7b c8 40  9d ad 8b bb 96 c4 cd c0 3b c1 03 e1 a1 94 bb d8");
+    }
+
+    static byte[] i2b(int i) {
+        ByteBuffer bb = ByteBuffer.allocate(4);
+        byte[] b = new byte[4];
+        bb.putInt(i);
+        bb.flip();
+        bb.get(b);
+        return b;
+    }
+
+    static String hex(byte[] bs) {
+        StringBuffer sb = new StringBuffer(bs.length * 2);
+        for(byte b: bs) {
+            char c = (char)((b+256)%256);
+            if (c / 16 < 10)
+                sb.append((char)(c/16+'0'));
+            else
+                sb.append((char)(c/16-10+'a'));
+            if (c % 16 < 10)
+                sb.append((char)(c%16+'0'));
+            else
+                sb.append((char)(c%16-10+'a'));
+        }
+        return new String(sb);
+    }
+
+    static byte[] xeh(String in) {
+        in = in.replaceAll(" ", "");
+        int len = in.length()/2;
+        byte[] out = new byte[len];
+        for (int i=0; i<len; i++) {
+            out[i] = (byte)Integer.parseInt(in.substring(i*2, i*2+2), 16);
+        }
+        return out;
+    }
+
+    static void assertStringEquals(String a, String b) {
+        a = a.replaceAll(" ", "");
+        b = b.replaceAll(" ", "");
+        if (!a.equals(b)) {
+            throw new RuntimeException("Not equal: " + a + " AND " + b);
+        }
+        System.err.print(".");
+    }
+}
--- a/jdk/test/sun/security/ssl/sun/net/www/httpstest/HttpTransaction.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/jdk/test/sun/security/ssl/sun/net/www/httpstest/HttpTransaction.java	Fri Oct 16 18:02:31 2009 -0700
@@ -102,7 +102,8 @@
         if (rspheaders != null) {
             buf.append (rspheaders.toString()).append("\r\n");
         }
-        buf.append ("Body: ").append (new String(rspbody)).append("\r\n");
+        String rbody = rspbody == null? "": new String (rspbody);
+        buf.append ("Body: ").append (rbody).append("\r\n");
         return new String (buf);
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/sun/security/tools/jarsigner/passtype.sh	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,72 @@
+#
+# Copyright 2009 Sun Microsystems, Inc.  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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+# CA 95054 USA or visit www.sun.com if you need additional information or
+# have any questions.
+#
+
+# @test
+# @bug 6868579
+# @summary RFE: jarsigner to support reading password from environment variable
+#
+
+if [ "${TESTJAVA}" = "" ] ; then
+  JAVAC_CMD=`which javac`
+  TESTJAVA=`dirname $JAVAC_CMD`/..
+fi
+
+# set platform-dependent variables
+OS=`uname -s`
+case "$OS" in
+  Windows_* )
+    FS="\\"
+    ;;
+  * )
+    FS="/"
+    ;;
+esac
+
+KS=pt.jks
+JFILE=pt.jar
+
+KT="$TESTJAVA${FS}bin${FS}keytool -keystore $KS -validity 300"
+JAR=$TESTJAVA${FS}bin${FS}jar
+JARSIGNER=$TESTJAVA${FS}bin${FS}jarsigner
+
+rm $KS $JFILE
+
+$KT -alias a -dname CN=a -keyalg rsa -genkey \
+        -storepass test12 -keypass test12 || exit 1
+PASSENV=test12 $KT -alias b -dname CN=b -keyalg rsa -genkey \
+        -storepass:env PASSENV -keypass:env PASSENV || exit 2
+echo test12 > passfile
+$KT -alias c -dname CN=c -keyalg rsa -genkey \
+        -storepass:file passfile -keypass:file passfile || exit 3
+
+echo A > A
+$JAR cvf $JFILE A
+
+$JARSIGNER -keystore $KS -storepass test12 $JFILE a || exit 4
+PASSENV=test12 $JARSIGNER -keystore $KS -storepass:env PASSENV $JFILE b || exit 5
+$JARSIGNER -keystore $KS -storepass:file passfile $JFILE b || exit 6
+
+$JARSIGNER -keystore $KS -verify -debug -strict $JFILE || exit 7
+
+exit 0
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/sun/security/tools/keytool/newhelp.sh	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,53 @@
+#
+# Copyright 2009 Sun Microsystems, Inc.  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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+# CA 95054 USA or visit www.sun.com if you need additional information or
+# have any questions.
+#
+
+# @test
+# @bug 6324292
+# @summary keytool -help is unhelpful
+#
+
+if [ "${TESTJAVA}" = "" ] ; then
+  JAVAC_CMD=`which javac`
+  TESTJAVA=`dirname $JAVAC_CMD`/..
+fi
+
+# set platform-dependent variables
+OS=`uname -s`
+case "$OS" in
+  Windows_* )
+    FS="\\"
+    ;;
+  * )
+    FS="/"
+    ;;
+esac
+
+LANG=C
+$TESTJAVA${FS}bin${FS}keytool -help 2> h1 || exit 1
+$TESTJAVA${FS}bin${FS}keytool -help -list 2> h2 || exit 2
+
+grep Commands: h1 || exit 3
+grep Options: h2 || exit 4
+
+exit 0
+
--- a/langtools/.hgtags	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/.hgtags	Fri Oct 16 18:02:31 2009 -0700
@@ -47,3 +47,4 @@
 97d06f3e87873e310aa2f3fbca58fc8872d86b9f jdk7-b70
 33c8c38e1757006c17d80499fb3347102501fae5 jdk7-b71
 261c54b2312ed26d6ec45c675831375460250519 jdk7-b72
+9596dff460935f09684c11d156ce591f92584f0d jdk7-b73
--- a/langtools/make/build.xml	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/make/build.xml	Fri Oct 16 18:02:31 2009 -0700
@@ -286,10 +286,10 @@
                               jarclasspath="javadoc.jar doclets.jar javac.jar"/>
     </target>
 
-    <target name="build-javah" depends="build-javadoc">
+    <target name="build-javah" depends="build-javac">
         <build-tool name="javah"
                     includes="${javah.includes}"
-                    jarclasspath="javadoc.jar doclets.jar javac.jar"/>
+                    jarclasspath="javac.jar"/>
     </target>
 
     <target name="build-classes-javah" depends="build-classes-javadoc">
--- a/langtools/src/share/classes/com/sun/tools/apt/comp/Apt.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/apt/comp/Apt.java	Fri Oct 16 18:02:31 2009 -0700
@@ -201,7 +201,7 @@
                     computeAnnotationSet(param, annotationSet);
 
             if (symbol.members() != null) {
-                for(Scope.Entry e: symbol.members().table)
+                for(Scope.Entry e = symbol.members().elems; e != null; e = e.sibling)
                     computeAnnotationSet(e.sym, annotationSet);
             }
         }
--- a/langtools/src/share/classes/com/sun/tools/apt/mirror/util/SourcePositionImpl.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/apt/mirror/util/SourcePositionImpl.java	Fri Oct 16 18:02:31 2009 -0700
@@ -67,15 +67,15 @@
     public String toString() {
         int ln = line();
         return (ln == Position.NOPOS)
-                ? sourcefile.toString()
-                : sourcefile + ":" + ln;
+                ? sourcefile.getName()
+                : sourcefile.getName() + ":" + ln;
     }
 
     /**
      * {@inheritDoc}
      */
     public File file() {
-        return new File(sourcefile.toString());
+        return new File(sourcefile.toUri());
     }
 
     /**
--- a/langtools/src/share/classes/com/sun/tools/javac/file/BaseFileObject.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/file/BaseFileObject.java	Fri Oct 16 18:02:31 2009 -0700
@@ -34,6 +34,7 @@
 import java.nio.charset.CharsetDecoder;
 import javax.lang.model.element.Modifier;
 import javax.lang.model.element.NestingKind;
+import javax.tools.FileObject;
 import javax.tools.JavaFileObject;
 
 import static javax.tools.JavaFileObject.Kind.*;
@@ -49,33 +50,15 @@
         this.fileManager = fileManager;
     }
 
-    public JavaFileObject.Kind getKind() {
-        String n = getName();
-        if (n.endsWith(CLASS.extension))
-            return CLASS;
-        else if (n.endsWith(SOURCE.extension))
-            return SOURCE;
-        else if (n.endsWith(HTML.extension))
-            return HTML;
-        else
-            return OTHER;
-    }
+    /** Return a short name for the object, such as for use in raw diagnostics
+     */
+    public abstract String getShortName();
 
     @Override
     public String toString() {
-        return getPath();
+        return getClass().getSimpleName() + "[" + getName() + "]";
     }
 
-    /** @deprecated see bug 6410637 */
-    @Deprecated
-    public String getPath() {
-        return getName();
-    }
-
-    /** @deprecated see bug 6410637 */
-    @Deprecated
-    abstract public String getName();
-
     public NestingKind getNestingKind() { return null; }
 
     public Modifier getAccessLevel()  { return null; }
@@ -90,6 +73,17 @@
 
     protected abstract String inferBinaryName(Iterable<? extends File> path);
 
+    protected static JavaFileObject.Kind getKind(String filename) {
+        if (filename.endsWith(CLASS.extension))
+            return CLASS;
+        else if (filename.endsWith(SOURCE.extension))
+            return SOURCE;
+        else if (filename.endsWith(HTML.extension))
+            return HTML;
+        else
+            return OTHER;
+    }
+
     protected static String removeExtension(String fileName) {
         int lastDot = fileName.lastIndexOf(".");
         return (lastDot == -1 ? fileName : fileName.substring(0, lastDot));
@@ -115,6 +109,17 @@
         }
     }
 
+    /** Return the last component of a presumed hierarchical URI.
+     *  From the scheme specific part of the URI, it returns the substring
+     *  after the last "/" if any, or everything if no "/" is found.
+     */
+    public static String getSimpleName(FileObject fo) {
+        URI uri = fo.toUri();
+        String s = uri.getSchemeSpecificPart();
+        return s.substring(s.lastIndexOf("/") + 1); // safe when / not found
+
+    }
+
     /** The file manager that created this JavaFileObject. */
     protected final JavacFileManager fileManager;
 }
--- a/langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java	Fri Oct 16 18:02:31 2009 -0700
@@ -1116,36 +1116,6 @@
         throw new IllegalArgumentException("Invalid relative path: " + file);
     }
 
-    @SuppressWarnings("deprecation") // bug 6410637
-    public static String getJavacFileName(FileObject file) {
-        if (file instanceof BaseFileObject)
-            return ((BaseFileObject)file).getPath();
-        URI uri = file.toUri();
-        String scheme = uri.getScheme();
-        if (scheme == null || scheme.equals("file") || scheme.equals("jar"))
-            return uri.getPath();
-        else
-            return uri.toString();
-    }
-
-    @SuppressWarnings("deprecation") // bug 6410637
-    public static String getJavacBaseFileName(FileObject file) {
-        if (file instanceof BaseFileObject)
-            return ((BaseFileObject)file).getName();
-        URI uri = file.toUri();
-        String scheme = uri.getScheme();
-        if (scheme == null || scheme.equals("file") || scheme.equals("jar")) {
-            String path = uri.getPath();
-            if (path == null)
-                return null;
-            if (scheme != null && scheme.equals("jar"))
-                path = path.substring(path.lastIndexOf('!') + 1);
-            return path.substring(path.lastIndexOf('/') + 1);
-        } else {
-            return uri.toString();
-        }
-    }
-
     private static <T> T nullCheck(T o) {
         o.getClass(); // null check
         return o;
--- a/langtools/src/share/classes/com/sun/tools/javac/file/Old199.java	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-/*
- * Copyright 2006-2008 Sun Microsystems, Inc.  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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Sun designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Sun in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- */
-
-package com.sun.tools.javac.file;
-
-import javax.tools.FileObject;
-
-/**
- * Provides an easy migration to JSR 199 v3.3.  The class is
- * deprecated as we should remove it as soon as possible.
- *
- * <p><b>This is NOT part of any API supported by Sun Microsystems.
- * If you write code that depends on this, you do so at your own
- * risk.  This code and its internal interfaces are subject to change
- * or deletion without notice.</b></p>
- *
- * @author Peter von der Ah\u00e9
- */
-@Deprecated
-public class Old199 {
-
-    private Old199() {}
-
-    public static String getPath(FileObject jfo) {
-        return JavacFileManager.getJavacFileName(jfo);
-    }
-
-    public static String getName(FileObject jfo) {
-        return JavacFileManager.getJavacBaseFileName(jfo);
-    }
-
-}
--- a/langtools/src/share/classes/com/sun/tools/javac/file/RegularFileObject.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/file/RegularFileObject.java	Fri Oct 16 18:02:31 2009 -0700
@@ -68,98 +68,38 @@
         this.f = f;
     }
 
+    @Override
+    public URI toUri() {
+        return f.toURI().normalize();
+    }
+
+    @Override
+    public String getName() {
+        return f.getPath();
+    }
+
+    @Override
+    public String getShortName() {
+        return name;
+    }
+
+    @Override
+    public JavaFileObject.Kind getKind() {
+        return getKind(name);
+    }
+
+    @Override
     public InputStream openInputStream() throws IOException {
         return new FileInputStream(f);
     }
 
     @Override
-    protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) {
-        return fileManager.getDecoder(fileManager.getEncodingName(), ignoreEncodingErrors);
-    }
-
     public OutputStream openOutputStream() throws IOException {
         ensureParentDirectoriesExist();
         return new FileOutputStream(f);
     }
 
-    public Writer openWriter() throws IOException {
-        ensureParentDirectoriesExist();
-        return new OutputStreamWriter(new FileOutputStream(f), fileManager.getEncodingName());
-    }
-
     @Override
-    protected String inferBinaryName(Iterable<? extends File> path) {
-        String fPath = f.getPath();
-        //System.err.println("RegularFileObject " + file + " " +r.getPath());
-        for (File dir: path) {
-            //System.err.println("dir: " + dir);
-            String dPath = dir.getPath();
-            if (dPath.length() == 0)
-                dPath = System.getProperty("user.dir");
-            if (!dPath.endsWith(File.separator))
-                dPath += File.separator;
-            if (fPath.regionMatches(true, 0, dPath, 0, dPath.length())
-                && new File(fPath.substring(0, dPath.length())).equals(new File(dPath))) {
-                String relativeName = fPath.substring(dPath.length());
-                return removeExtension(relativeName).replace(File.separatorChar, '.');
-            }
-        }
-        return null;
-    }
-
-    private void ensureParentDirectoriesExist() throws IOException {
-        if (!hasParents) {
-            File parent = f.getParentFile();
-            if (parent != null && !parent.exists()) {
-                if (!parent.mkdirs()) {
-                    if (!parent.exists() || !parent.isDirectory()) {
-                        throw new IOException("could not create parent directories");
-                    }
-                }
-            }
-            hasParents = true;
-        }
-    }
-
-    @Deprecated
-    public String getName() {
-        return name;
-    }
-
-    public boolean isNameCompatible(String cn, JavaFileObject.Kind kind) {
-        cn.getClass();
-        // null check
-        if (kind == Kind.OTHER && getKind() != kind) {
-            return false;
-        }
-        String n = cn + kind.extension;
-        if (name.equals(n)) {
-            return true;
-        }
-        if (name.equalsIgnoreCase(n)) {
-            try {
-                // allow for Windows
-                return f.getCanonicalFile().getName().equals(n);
-            } catch (IOException e) {
-            }
-        }
-        return false;
-    }
-
-    @Deprecated
-    @Override
-    public String getPath() {
-        return f.getPath();
-    }
-
-    public long getLastModified() {
-        return f.lastModified();
-    }
-
-    public boolean delete() {
-        return f.delete();
-    }
-
     public CharBuffer getCharContent(boolean ignoreEncodingErrors) throws IOException {
         CharBuffer cb = fileManager.getCachedContent(this);
         if (cb == null) {
@@ -184,6 +124,82 @@
     }
 
     @Override
+    public Writer openWriter() throws IOException {
+        ensureParentDirectoriesExist();
+        return new OutputStreamWriter(new FileOutputStream(f), fileManager.getEncodingName());
+    }
+
+    @Override
+    public long getLastModified() {
+        return f.lastModified();
+    }
+
+    @Override
+    public boolean delete() {
+        return f.delete();
+    }
+
+    @Override
+    protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) {
+        return fileManager.getDecoder(fileManager.getEncodingName(), ignoreEncodingErrors);
+    }
+
+    @Override
+    protected String inferBinaryName(Iterable<? extends File> path) {
+        String fPath = f.getPath();
+        //System.err.println("RegularFileObject " + file + " " +r.getPath());
+        for (File dir: path) {
+            //System.err.println("dir: " + dir);
+            String dPath = dir.getPath();
+            if (dPath.length() == 0)
+                dPath = System.getProperty("user.dir");
+            if (!dPath.endsWith(File.separator))
+                dPath += File.separator;
+            if (fPath.regionMatches(true, 0, dPath, 0, dPath.length())
+                && new File(fPath.substring(0, dPath.length())).equals(new File(dPath))) {
+                String relativeName = fPath.substring(dPath.length());
+                return removeExtension(relativeName).replace(File.separatorChar, '.');
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public boolean isNameCompatible(String cn, JavaFileObject.Kind kind) {
+        cn.getClass();
+        // null check
+        if (kind == Kind.OTHER && getKind() != kind) {
+            return false;
+        }
+        String n = cn + kind.extension;
+        if (name.equals(n)) {
+            return true;
+        }
+        if (name.equalsIgnoreCase(n)) {
+            try {
+                // allow for Windows
+                return f.getCanonicalFile().getName().equals(n);
+            } catch (IOException e) {
+            }
+        }
+        return false;
+    }
+
+    private void ensureParentDirectoriesExist() throws IOException {
+        if (!hasParents) {
+            File parent = f.getParentFile();
+            if (parent != null && !parent.exists()) {
+                if (!parent.mkdirs()) {
+                    if (!parent.exists() || !parent.isDirectory()) {
+                        throw new IOException("could not create parent directories");
+                    }
+                }
+            }
+            hasParents = true;
+        }
+    }
+
+    @Override
     public boolean equals(Object other) {
         if (!(other instanceof RegularFileObject)) {
             return false;
@@ -200,8 +216,4 @@
     public int hashCode() {
         return f.hashCode();
     }
-
-    public URI toUri() {
-        return f.toURI().normalize();
-    }
 }
--- a/langtools/src/share/classes/com/sun/tools/javac/file/SymbolArchive.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/file/SymbolArchive.java	Fri Oct 16 18:02:31 2009 -0700
@@ -95,7 +95,7 @@
 
         @Override
         protected String inferBinaryName(Iterable<? extends File> path) {
-            String entryName = getZipEntryName();
+            String entryName = entry.getName();
             String prefix = ((SymbolArchive) zarch).prefix.path;
             if (entryName.startsWith(prefix))
                 entryName = entryName.substring(prefix.length());
--- a/langtools/src/share/classes/com/sun/tools/javac/file/ZipArchive.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/file/ZipArchive.java	Fri Oct 16 18:02:31 2009 -0700
@@ -147,51 +147,37 @@
             this.entry = entry;
         }
 
+        public URI toUri() {
+            File zipFile = new File(zarch.zdir.getName());
+            return createJarUri(zipFile, entry.getName());
+        }
+
+        @Override
+        public String getName() {
+            return zarch.zdir.getName() + "(" + entry.getName() + ")";
+        }
+
+        @Override
+        public String getShortName() {
+            return new File(zarch.zdir.getName()).getName() + "(" + entry + ")";
+        }
+
+        @Override
+        public JavaFileObject.Kind getKind() {
+            return getKind(entry.getName());
+        }
+
+        @Override
         public InputStream openInputStream() throws IOException {
             return zarch.zdir.getInputStream(entry);
         }
 
+        @Override
         public OutputStream openOutputStream() throws IOException {
             throw new UnsupportedOperationException();
         }
 
         @Override
-        protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) {
-            return fileManager.getDecoder(fileManager.getEncodingName(), ignoreEncodingErrors);
-        }
-
-        public Writer openWriter() throws IOException {
-            throw new UnsupportedOperationException();
-        }
-
-        @Deprecated
-        public String getName() {
-            return name;
-        }
-
-        public boolean isNameCompatible(String cn, JavaFileObject.Kind k) {
-            cn.getClass();
-            // null check
-            if (k == Kind.OTHER && getKind() != k) {
-                return false;
-            }
-            return name.equals(cn + k.extension);
-        }
-
-        @Deprecated
-        @Override
-        public String getPath() {
-            return zarch.zdir.getName() + "(" + entry + ")";
-        }
-
-        public long getLastModified() {
-            return entry.getTime();
-        }
-
-        public boolean delete() {
-            throw new UnsupportedOperationException();
-        }
-
         public CharBuffer getCharContent(boolean ignoreEncodingErrors) throws IOException {
             CharBuffer cb = fileManager.getCachedContent(this);
             if (cb == null) {
@@ -216,6 +202,42 @@
         }
 
         @Override
+        public Writer openWriter() throws IOException {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public long getLastModified() {
+            return entry.getTime();
+        }
+
+        @Override
+        public boolean delete() {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) {
+            return fileManager.getDecoder(fileManager.getEncodingName(), ignoreEncodingErrors);
+        }
+
+        @Override
+        protected String inferBinaryName(Iterable<? extends File> path) {
+            String entryName = entry.getName();
+            return removeExtension(entryName).replace('/', '.');
+        }
+
+        @Override
+        public boolean isNameCompatible(String cn, JavaFileObject.Kind k) {
+            cn.getClass();
+            // null check
+            if (k == Kind.OTHER && getKind() != k) {
+                return false;
+            }
+            return name.equals(cn + k.extension);
+        }
+
+        @Override
         public boolean equals(Object other) {
             if (!(other instanceof ZipFileObject)) {
                 return false;
@@ -228,25 +250,6 @@
         public int hashCode() {
             return zarch.zdir.hashCode() + name.hashCode();
         }
-
-        public String getZipName() {
-            return zarch.zdir.getName();
-        }
-
-        public String getZipEntryName() {
-            return entry.getName();
-        }
-
-        public URI toUri() {
-            File zipFile = new File(getZipName());
-            return createJarUri(zipFile, entry.getName());
-        }
-
-        @Override
-        protected String inferBinaryName(Iterable<? extends File> path) {
-            String entryName = getZipEntryName();
-            return removeExtension(entryName).replace('/', '.');
-        }
     }
 
 }
--- a/langtools/src/share/classes/com/sun/tools/javac/file/ZipFileIndexArchive.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/file/ZipFileIndexArchive.java	Fri Oct 16 18:02:31 2009 -0700
@@ -123,88 +123,41 @@
             this.zipName = zipFileName;
         }
 
-        public InputStream openInputStream() throws IOException {
+        @Override
+        public URI toUri() {
+            return createJarUri(zipName, getPrefixedEntryName());
+        }
+
+        @Override
+        public String getName() {
+            return zipName + "(" + getPrefixedEntryName() + ")";
+        }
 
+        @Override
+        public String getShortName() {
+            return zipName.getName() + "(" + entry.getName() + ")";
+        }
+
+        @Override
+        public JavaFileObject.Kind getKind() {
+            return getKind(entry.getName());
+        }
+
+        @Override
+        public InputStream openInputStream() throws IOException {
             if (inputStream == null) {
-                inputStream = new ByteArrayInputStream(read());
+                assert entry != null; // see constructor
+                inputStream = new ByteArrayInputStream(zfIndex.read(entry));
             }
             return inputStream;
         }
 
         @Override
-        protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) {
-            return fileManager.getDecoder(fileManager.getEncodingName(), ignoreEncodingErrors);
-        }
-
         public OutputStream openOutputStream() throws IOException {
             throw new UnsupportedOperationException();
         }
 
-        public Writer openWriter() throws IOException {
-            throw new UnsupportedOperationException();
-        }
-
-        /** @deprecated see bug 6410637 */
-        @Deprecated
-        public String getName() {
-            return name;
-        }
-
-        public boolean isNameCompatible(String cn, JavaFileObject.Kind k) {
-            cn.getClass(); // null check
-            if (k == Kind.OTHER && getKind() != k)
-                return false;
-            return name.equals(cn + k.extension);
-        }
-
-        /** @deprecated see bug 6410637 */
-        @Deprecated
         @Override
-        public String getPath() {
-            return zipName + "(" + entry.getName() + ")";
-        }
-
-        public long getLastModified() {
-            return entry.getLastModified();
-        }
-
-        public boolean delete() {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        public boolean equals(Object other) {
-            if (!(other instanceof ZipFileIndexFileObject))
-                return false;
-            ZipFileIndexFileObject o = (ZipFileIndexFileObject) other;
-            return entry.equals(o.entry);
-        }
-
-        @Override
-        public int hashCode() {
-            return zipName.hashCode() + (name.hashCode() << 10);
-        }
-
-        public String getZipName() {
-            return zipName.getPath();
-        }
-
-        public String getZipEntryName() {
-            return entry.getName();
-        }
-
-        public URI toUri() {
-            if (zfIndex.symbolFilePrefix != null)
-                return createJarUri(zipName, zfIndex.symbolFilePrefix.path + entry.getName());
-            else
-                return createJarUri(zipName, entry.getName());
-        }
-
-        private byte[] read() throws IOException {
-            assert entry != null; // see constructor
-            return zfIndex.read(entry);
-        }
-
         public CharBuffer getCharContent(boolean ignoreEncodingErrors) throws IOException {
             CharBuffer cb = fileManager.getCachedContent(this);
             if (cb == null) {
@@ -228,8 +181,28 @@
         }
 
         @Override
+        public Writer openWriter() throws IOException {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public long getLastModified() {
+            return entry.getLastModified();
+        }
+
+        @Override
+        public boolean delete() {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) {
+            return fileManager.getDecoder(fileManager.getEncodingName(), ignoreEncodingErrors);
+        }
+
+        @Override
         protected String inferBinaryName(Iterable<? extends File> path) {
-            String entryName = getZipEntryName();
+            String entryName = entry.getName();
             if (zfIndex.symbolFilePrefix != null) {
                 String prefix = zfIndex.symbolFilePrefix.path;
                 if (entryName.startsWith(prefix))
@@ -237,6 +210,34 @@
             }
             return removeExtension(entryName).replace('/', '.');
         }
+
+        @Override
+        public boolean isNameCompatible(String cn, JavaFileObject.Kind k) {
+            cn.getClass(); // null check
+            if (k == Kind.OTHER && getKind() != k)
+                return false;
+            return name.equals(cn + k.extension);
+        }
+
+        @Override
+        public boolean equals(Object other) {
+            if (!(other instanceof ZipFileIndexFileObject))
+                return false;
+            ZipFileIndexFileObject o = (ZipFileIndexFileObject) other;
+            return entry.equals(o.entry);
+        }
+
+        @Override
+        public int hashCode() {
+            return zipName.hashCode() + (name.hashCode() << 10);
+        }
+
+        private String getPrefixedEntryName() {
+            if (zfIndex.symbolFilePrefix != null)
+                return zfIndex.symbolFilePrefix.path + entry.getName();
+            else
+                return entry.getName();
+        }
     }
 
 }
--- a/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Fri Oct 16 18:02:31 2009 -0700
@@ -2563,38 +2563,73 @@
             this.flatname = flatname;
         }
 
+        @Override
+        public URI toUri() {
+            try {
+                return new URI(null, name.toString(), null);
+            } catch (URISyntaxException e) {
+                throw new CannotCreateUriError(name.toString(), e);
+            }
+        }
+
+        @Override
+        public String getName() {
+            return name.toString();
+        }
+
+        @Override
+        public String getShortName() {
+            return getName();
+        }
+
+        @Override
+        public JavaFileObject.Kind getKind() {
+            return getKind(getName());
+        }
+
+        @Override
         public InputStream openInputStream() {
             throw new UnsupportedOperationException();
         }
 
+        @Override
         public OutputStream openOutputStream() {
             throw new UnsupportedOperationException();
         }
 
-        public Reader openReader() {
+        @Override
+        public CharBuffer getCharContent(boolean ignoreEncodingErrors) {
             throw new UnsupportedOperationException();
         }
 
+        @Override
+        public Reader openReader(boolean ignoreEncodingErrors) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
         public Writer openWriter() {
             throw new UnsupportedOperationException();
         }
 
-        /** @deprecated see bug 6410637 */
-        @Deprecated
-        public String getName() {
-            return name.toString();
-        }
-
+        @Override
         public long getLastModified() {
             throw new UnsupportedOperationException();
         }
 
+        @Override
         public boolean delete() {
             throw new UnsupportedOperationException();
         }
 
-        public CharBuffer getCharContent(boolean ignoreEncodingErrors) {
-            throw new UnsupportedOperationException();
+        @Override
+        protected String inferBinaryName(Iterable<? extends File> path) {
+            return flatname.toString();
+        }
+
+        @Override
+        public boolean isNameCompatible(String simpleName, JavaFileObject.Kind kind) {
+            return true; // fail-safe mode
         }
 
         @Override
@@ -2609,27 +2644,5 @@
         public int hashCode() {
             return name.hashCode();
         }
-
-        public boolean isNameCompatible(String simpleName, JavaFileObject.Kind kind) {
-            return true; // fail-safe mode
-        }
-
-        public URI toUri() {
-            try {
-                return new URI(null, name.toString(), null);
-            } catch (URISyntaxException e) {
-                throw new CannotCreateUriError(name.toString(), e);
-            }
-        }
-
-        @Override
-        public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        protected String inferBinaryName(Iterable<? extends File> path) {
-            return flatname.toString();
-        }
     }
 }
--- a/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Fri Oct 16 18:02:31 2009 -0700
@@ -36,6 +36,7 @@
 import com.sun.tools.javac.code.*;
 import com.sun.tools.javac.code.Symbol.*;
 import com.sun.tools.javac.code.Type.*;
+import com.sun.tools.javac.file.BaseFileObject;
 import com.sun.tools.javac.util.*;
 
 import static com.sun.tools.javac.code.BoundKind.*;
@@ -1685,13 +1686,8 @@
             // the last possible moment because the sourcefile may be used
             // elsewhere in error diagnostics. Fixes 4241573.
             //databuf.appendChar(c.pool.put(c.sourcefile));
-            String filename = c.sourcefile.toString();
-            int sepIdx = filename.lastIndexOf(File.separatorChar);
-            // Allow '/' as separator on all platforms, e.g., on Win32.
-            int slashIdx = filename.lastIndexOf('/');
-            if (slashIdx > sepIdx) sepIdx = slashIdx;
-            if (sepIdx >= 0) filename = filename.substring(sepIdx + 1);
-            databuf.appendChar(c.pool.put(names.fromString(filename)));
+            String simpleName = BaseFileObject.getSimpleName(c.sourcefile);
+            databuf.appendChar(c.pool.put(names.fromString(simpleName)));
             endAttr(alenIdx);
             acount++;
         }
--- a/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Fri Oct 16 18:02:31 2009 -0700
@@ -2236,7 +2236,7 @@
 
     /* AnnotationValue          = ConditionalExpression
      *                          | Annotation
-     *                          | "{" [ AnnotationValue { "," AnnotationValue } ] "}"
+     *                          | "{" [ AnnotationValue { "," AnnotationValue } ] [","] "}"
      */
     JCExpression annotationValue() {
         int pos;
@@ -2253,7 +2253,7 @@
                 buf.append(annotationValue());
                 while (S.token() == COMMA) {
                     S.nextToken();
-                    if (S.token() == RPAREN) break;
+                    if (S.token() == RBRACE) break;
                     buf.append(annotationValue());
                 }
             }
--- a/langtools/src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java	Fri Oct 16 18:02:31 2009 -0700
@@ -42,8 +42,8 @@
 import com.sun.tools.javac.code.Symbol;
 import com.sun.tools.javac.code.Type;
 import com.sun.tools.javac.code.Type.CapturedType;
-import com.sun.tools.javac.file.JavacFileManager;
 
+import com.sun.tools.javac.file.BaseFileObject;
 import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticType.*;
 
 /**
@@ -133,8 +133,15 @@
     }
 
     public String formatSource(JCDiagnostic d, boolean fullname, Locale l) {
-        assert (d.getSource() != null);
-        return fullname ? d.getSourceName() : d.getSource().getName();
+        JavaFileObject fo = d.getSource();
+        if (fo == null)
+            throw new IllegalArgumentException(); // d should have source set
+        if (fullname)
+            return fo.getName();
+        else if (fo instanceof BaseFileObject)
+            return ((BaseFileObject) fo).getShortName();
+        else
+            return BaseFileObject.getSimpleName(fo);
     }
 
     /**
@@ -182,7 +189,7 @@
             return printer.visit((Symbol)arg, l);
         }
         else if (arg instanceof JavaFileObject) {
-            return JavacFileManager.getJavacBaseFileName((JavaFileObject)arg);
+            return ((JavaFileObject)arg).getName();
         }
         else if (arg instanceof Formattable) {
             return ((Formattable)arg).toString(l, messages);
--- a/langtools/src/share/classes/com/sun/tools/javac/util/Constants.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/Constants.java	Fri Oct 16 18:02:31 2009 -0700
@@ -83,16 +83,28 @@
      */
     public static String format(Object value) {
         if (value instanceof Byte)      return formatByte((Byte) value);
+        if (value instanceof Short)     return formatShort((Short) value);
         if (value instanceof Long)      return formatLong((Long) value);
         if (value instanceof Float)     return formatFloat((Float) value);
         if (value instanceof Double)    return formatDouble((Double) value);
         if (value instanceof Character) return formatChar((Character) value);
         if (value instanceof String)    return formatString((String) value);
-        return value + "";
+        if (value instanceof Integer ||
+            value instanceof Boolean)   return value.toString();
+        else
+            throw new IllegalArgumentException("Argument is not a primitive type or a string; it " +
+                                               ((value == null) ?
+                                                "is a null value." :
+                                                "has class " +
+                                                value.getClass().getName()) + "." );
     }
 
     private static String formatByte(byte b) {
-        return String.format("0x%02x", b);
+        return String.format("(byte)0x%02x", b);
+    }
+
+    private static String formatShort(short s) {
+        return String.format("(short)%d", s);
     }
 
     private static String formatLong(long lng) {
--- a/langtools/src/share/classes/com/sun/tools/javac/util/Convert.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/Convert.java	Fri Oct 16 18:02:31 2009 -0700
@@ -239,9 +239,9 @@
         case '\"':  return "\\\"";
         case '\\':  return "\\\\";
         default:
-            return (ch > 127 || isPrintableAscii(ch))
+            return (isPrintableAscii(ch))
                 ? String.valueOf(ch)
-                : String.format("\\%03o", (int) ch);
+                : String.format("\\u%04x", (int) ch);
         }
     }
 
--- a/langtools/src/share/classes/com/sun/tools/javac/util/DiagnosticSource.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/DiagnosticSource.java	Fri Oct 16 18:02:31 2009 -0700
@@ -69,10 +69,6 @@
         return fileObject;
     }
 
-    public CharSequence getName()  {
-        return JavacFileManager.getJavacBaseFileName(fileObject);
-    }
-
     /** Return the one-based line number associated with a given pos
      * for the current source file.  Zero is returned if no line exists
      * for the given position.
--- a/langtools/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java	Fri Oct 16 18:02:31 2009 -0700
@@ -32,7 +32,6 @@
 import javax.tools.JavaFileObject;
 
 import com.sun.tools.javac.api.DiagnosticFormatter;
-import com.sun.tools.javac.file.JavacFileManager;
 import com.sun.tools.javac.tree.JCTree;
 
 import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticType.*;
@@ -354,15 +353,6 @@
     }
 
     /**
-     * Get the name of the source file referred to by this diagnostic.
-     * @return the name of the source referred to with this diagnostic, or null if none
-     */
-    public String getSourceName() {
-        JavaFileObject s = getSource();
-        return s == null ? null : JavacFileManager.getJavacFileName(s);
-    }
-
-    /**
      * Get the source referred to by this diagnostic.
      * @return the source referred to with this diagnostic, or null if none
      */
@@ -437,6 +427,7 @@
     /**
      * Return the standard presentation of this diagnostic.
      */
+    @Override
     public String toString() {
         return defaultFormatter.format(this,Locale.getDefault());
     }
--- a/langtools/src/share/classes/com/sun/tools/javac/util/Log.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/Log.java	Fri Oct 16 18:02:31 2009 -0700
@@ -33,7 +33,6 @@
 import javax.tools.DiagnosticListener;
 import javax.tools.JavaFileObject;
 
-import com.sun.tools.javac.file.JavacFileManager;
 import com.sun.tools.javac.tree.JCTree;
 import com.sun.tools.javac.api.DiagnosticFormatter;
 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
@@ -428,7 +427,7 @@
             JavaFileObject file = source.getFile();
             if (file != null)
                 printLines(errWriter,
-                           JavacFileManager.getJavacFileName(file) + ":" +
+                           file.getName() + ":" +
                            line + ": " + msg);
             printErrLine(pos, errWriter);
         }
--- a/langtools/src/share/classes/com/sun/tools/javac/util/RawDiagnosticFormatter.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/RawDiagnosticFormatter.java	Fri Oct 16 18:02:31 2009 -0700
@@ -30,6 +30,7 @@
 
 import com.sun.tools.javac.api.DiagnosticFormatter.Configuration.*;
 import com.sun.tools.javac.api.Formattable;
+import com.sun.tools.javac.file.BaseFileObject;
 import com.sun.tools.javac.util.AbstractDiagnosticFormatter.SimpleConfiguration;
 
 import static com.sun.tools.javac.api.DiagnosticFormatter.PositionKind.*;
@@ -109,6 +110,8 @@
         String s;
         if (arg instanceof Formattable)
             s = arg.toString();
+        else if (arg instanceof BaseFileObject)
+            s = ((BaseFileObject) arg).getShortName();
         else
             s = super.formatArgument(diag, arg, null);
         if (arg instanceof JCDiagnostic)
--- a/langtools/src/share/classes/com/sun/tools/javadoc/SourcePositionImpl.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/SourcePositionImpl.java	Fri Oct 16 18:02:31 2009 -0700
@@ -95,7 +95,7 @@
     public String toString() {
         // Backwards compatibility hack. ZipFileObjects use the format
         // zipfile(zipentry) but javadoc has been using zipfile/zipentry
-        String fn = filename.toString();
+        String fn = filename.getName();
         if (fn.endsWith(")")) {
             int paren = fn.lastIndexOf("(");
             if (paren != -1)
--- a/langtools/src/share/classes/com/sun/tools/javah/Gen.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javah/Gen.java	Fri Oct 16 18:02:31 2009 -0700
@@ -27,15 +27,32 @@
 
 import java.io.UnsupportedEncodingException;
 import java.io.ByteArrayOutputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
-import com.sun.javadoc.*;
-import java.io.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
 import java.util.Stack;
-import java.util.Vector;
-import java.util.Arrays;
+
+import javax.annotation.processing.ProcessingEnvironment;
 
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
+import javax.lang.model.util.ElementFilter;
+import javax.lang.model.util.Elements;
+import javax.lang.model.util.Types;
+
+import javax.tools.FileObject;
+import javax.tools.JavaFileManager;
+import javax.tools.JavaFileObject;
+import javax.tools.StandardLocation;
 
 /**
  * An abstraction for generating support files required by native methods.
@@ -43,31 +60,39 @@
  * original writing, this interface is rich enough to support JNI and the
  * old 1.0-style native method interface.
  *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems.
+ * If you write code that depends on this, you do so at your own
+ * risk.  This code and its internal interfaces are subject to change
+ * or deletion without notice.</b></p>
+ *
  * @author  Sucheta Dambalkar(Revised)
  */
-
-
 public abstract class Gen {
     protected String lineSep = System.getProperty("line.separator");
 
-    RootDoc root;
+    protected ProcessingEnvironment processingEnvironment;
+    protected Types types;
+    protected Elements elems;
+    protected Mangle mangler;
+    protected Util util;
+
+    protected Gen(Util util) {
+        this.util = util;
+    }
+
     /*
      * List of classes for which we must generate output.
      */
-    protected ClassDoc[] classes;
+    protected Set<TypeElement> classes;
     static private final boolean isWindows =
         System.getProperty("os.name").startsWith("Windows");
 
-    public Gen(RootDoc root){
-        this.root = root;
-    }
 
     /**
      * Override this abstract method, generating content for the named
      * class into the outputstream.
      */
-    protected abstract void write(OutputStream o, ClassDoc clazz)
-        throws ClassNotFoundException;
+    protected abstract void write(OutputStream o, TypeElement clazz) throws Util.Exit;
 
     /**
      * Override this method to provide a list of #include statements
@@ -78,31 +103,29 @@
     /*
      * Output location.
      */
-    protected String outDir;
-    protected String outFile;
+    protected JavaFileManager fileManager;
+    protected JavaFileObject outFile;
 
-    public void setOutDir(String outDir) {
-        /* Check important, otherwise concatenation of two null strings
-         * produces the "nullnull" String.
-         */
-        if (outDir != null) {
-            this.outDir = outDir + System.getProperty("file.separator");
-            File d = new File(outDir);
-            if (!d.exists())
-                if (!d.mkdirs())
-                    Util.error("cant.create.dir", d.toString());
-        }
+    public void setFileManager(JavaFileManager fm) {
+        fileManager = fm;
     }
 
-    public void setOutFile(String outFile) {
+    public void setOutFile(JavaFileObject outFile) {
         this.outFile = outFile;
     }
 
 
-    public void setClasses(ClassDoc[] classes) {
+    public void setClasses(Set<TypeElement> classes) {
         this.classes = classes;
     }
 
+    void setProcessingEnvironment(ProcessingEnvironment pEnv) {
+        processingEnvironment = pEnv;
+        elems = pEnv.getElementUtils();
+        types = pEnv.getTypeUtils();
+        mangler = new Mangle(elems, types);
+    }
+
     /*
      * Smartness with generated files.
      */
@@ -116,12 +139,11 @@
      * We explicitly need to write ASCII files because that is what C
      * compilers understand.
      */
-    protected PrintWriter wrapWriter(OutputStream o) {
+    protected PrintWriter wrapWriter(OutputStream o) throws Util.Exit {
         try {
-            return new
-            PrintWriter(new OutputStreamWriter(o, "ISO8859_1"), true);
+            return new PrintWriter(new OutputStreamWriter(o, "ISO8859_1"), true);
         } catch (UnsupportedEncodingException use) {
-            Util.bug("encoding.iso8859_1.not.found");
+            util.bug("encoding.iso8859_1.not.found");
             return null; /* dead code */
         }
     }
@@ -133,26 +155,25 @@
      * Buffer size chosen as an approximation from a single sampling of:
      *         expr `du -sk` / `ls *.h | wc -l`
      */
-    public void run() throws IOException, ClassNotFoundException {
+    public void run() throws IOException, ClassNotFoundException, Util.Exit {
         int i = 0;
         if (outFile != null) {
             /* Everything goes to one big file... */
             ByteArrayOutputStream bout = new ByteArrayOutputStream(8192);
             writeFileTop(bout); /* only once */
 
-            for (i = 0; i < classes.length; i++) {
-                write(bout, classes[i]);
+            for (TypeElement t: classes) {
+                write(bout, t);
             }
 
             writeIfChanged(bout.toByteArray(), outFile);
         } else {
             /* Each class goes to its own file... */
-            for (i = 0; i < classes.length; i++) {
+            for (TypeElement t: classes) {
                 ByteArrayOutputStream bout = new ByteArrayOutputStream(8192);
                 writeFileTop(bout);
-                ClassDoc clazz = classes[i];
-                write(bout, clazz);
-                writeIfChanged(bout.toByteArray(), getFileName(clazz.qualifiedName()));
+                write(bout, t);
+                writeIfChanged(bout.toByteArray(), getFileObject(t.getQualifiedName()));
             }
         }
     }
@@ -162,8 +183,7 @@
      * is done if either the file doesn't exist or if the contents are
      * different.
      */
-    private void writeIfChanged(byte[] b, String file) throws IOException {
-        File f = new File(file);
+    private void writeIfChanged(byte[] b, FileObject file) throws IOException {
         boolean mustWrite = false;
         String event = "[No need to update file ";
 
@@ -171,71 +191,80 @@
             mustWrite = true;
             event = "[Forcefully writing file ";
         } else {
-            if (!f.exists()) {
-                mustWrite = true;
-                event = "[Creating file ";
-            } else {
-                int l = (int)f.length();
-                if (b.length != l) {
+            InputStream in;
+            byte[] a;
+            try {
+                // regrettably, there's no API to get the length in bytes
+                // for a FileObject, so we can't short-circuit reading the
+                // file here
+                in = file.openInputStream();
+                a = readBytes(in);
+                if (!Arrays.equals(a, b)) {
                     mustWrite = true;
                     event = "[Overwriting file ";
-                } else {
-                    /* Lengths are equal, so read it. */
-                    byte[] a = new byte[l];
-                    FileInputStream in = new FileInputStream(f);
-                    if (in.read(a) != l) {
-                        in.close();
-                        /* This can't happen, we already checked the length. */
-                        Util.error("not.enough.bytes", Integer.toString(l),
-                                   f.toString());
-                    }
-                    in.close();
-                    while (--l >= 0) {
-                        if (a[l] != b[l]) {
-                            mustWrite = true;
-                            event = "[Overwriting file ";
-                        }
-                    }
+
                 }
+            } catch (FileNotFoundException e) {
+                mustWrite = true;
+                event = "[Creating file ";
             }
         }
-        if (Util.verbose)
-            Util.log(event + file + "]");
+
+        if (util.verbose)
+            util.log(event + file + "]");
+
         if (mustWrite) {
-            OutputStream out = new FileOutputStream(file);
+            OutputStream out = file.openOutputStream();
             out.write(b); /* No buffering, just one big write! */
             out.close();
         }
     }
 
-    protected String defineForStatic(ClassDoc c, FieldDoc f){
-
-        String cnamedoc = c.qualifiedName();
-        String fnamedoc = f.name();
+    protected byte[] readBytes(InputStream in) throws IOException {
+        try {
+            byte[] array = new byte[in.available() + 1];
+            int offset = 0;
+            int n;
+            while ((n = in.read(array, offset, array.length - offset)) != -1) {
+                offset += n;
+                if (offset == array.length)
+                    array = Arrays.copyOf(array, array.length * 2);
+            }
 
-        String cname = Mangle.mangle(cnamedoc, Mangle.Type.CLASS);
-        String fname = Mangle.mangle(fnamedoc, Mangle.Type.FIELDSTUB);
+            return Arrays.copyOf(array, offset);
+        } finally {
+            in.close();
+        }
+    }
 
-        if (!f.isStatic())
-            Util.bug("tried.to.define.non.static");
+    protected String defineForStatic(TypeElement c, VariableElement f)
+            throws Util.Exit {
+        CharSequence cnamedoc = c.getQualifiedName();
+        CharSequence fnamedoc = f.getSimpleName();
 
-        if (f.isFinal()) {
+        String cname = mangler.mangle(cnamedoc, Mangle.Type.CLASS);
+        String fname = mangler.mangle(fnamedoc, Mangle.Type.FIELDSTUB);
+
+        if (!f.getModifiers().contains(Modifier.STATIC))
+            util.bug("tried.to.define.non.static");
+
+        if (f.getModifiers().contains(Modifier.FINAL)) {
             Object value = null;
 
-            value = f.constantValue();
+            value = f.getConstantValue();
 
             if (value != null) { /* so it is a ConstantExpression */
                 String constString = null;
                 if ((value instanceof Integer)
                     || (value instanceof Byte)
-                    || (value instanceof Character)
-                    || (value instanceof Short)
-                    || (value instanceof Boolean)) {
-                    /* covers byte, boolean, char, short, int */
-                    if(value instanceof Boolean)
-                        constString = (value.toString() == "true") ? "1L" : "0L";
-                    else
-                        constString = value.toString() + "L";
+                    || (value instanceof Short)) {
+                    /* covers byte, short, int */
+                    constString = value.toString() + "L";
+                } else if (value instanceof Boolean) {
+                    constString = ((Boolean) value) ? "1L" : "0L";
+                } else if (value instanceof Character) {
+                    Character ch = (Character) value;
+                    constString = String.valueOf(((int) ch) & 0xffff) + "L";
                 } else if (value instanceof Long) {
                     // Visual C++ supports the i64 suffix, not LL.
                     if (isWindows)
@@ -294,24 +323,19 @@
     /*
      * File name and file preamble related operations.
      */
-    protected void writeFileTop(OutputStream o) {
+    protected void writeFileTop(OutputStream o) throws Util.Exit {
         PrintWriter pw = wrapWriter(o);
         pw.println("/* DO NOT EDIT THIS FILE - it is machine generated */" + lineSep +
                    getIncludes());
     }
 
-    protected String baseFileName(String clazz) {
-        StringBuffer f =
-            new StringBuffer(Mangle.mangle(clazz,
-                                           Mangle.Type.CLASS));
-        if (outDir != null) {
-            f.insert(0, outDir);
-        }
-        return f.toString();
+    protected String baseFileName(CharSequence className) {
+        return mangler.mangle(className, Mangle.Type.CLASS);
     }
 
-    protected String getFileName(String clazz) {
-        return baseFileName(clazz) + getFileSuffix();
+    protected FileObject getFileObject(CharSequence className) throws IOException {
+        String name = baseFileName(className) + getFileSuffix();
+        return fileManager.getFileForOutput(StandardLocation.SOURCE_OUTPUT, "", name, null);
     }
 
     protected String getFileSuffix() {
@@ -322,26 +346,39 @@
      * Including super classes' fields.
      */
 
-    FieldDoc[] getAllFields(ClassDoc subclazz)
-                throws ClassNotFoundException {
-        Vector<FieldDoc> fields = new Vector<FieldDoc>();
-        ClassDoc cd = null;
-        Stack<Object> s = new Stack<Object>();
+    List<VariableElement> getAllFields(TypeElement subclazz) {
+        List<VariableElement> fields = new ArrayList<VariableElement>();
+        TypeElement cd = null;
+        Stack<TypeElement> s = new Stack<TypeElement>();
 
         cd = subclazz;
         while (true) {
             s.push(cd);
-            ClassDoc c = cd.superclass();
+            TypeElement c = (TypeElement) (types.asElement(cd.getSuperclass()));
             if (c == null)
                 break;
             cd = c;
         }
 
         while (!s.empty()) {
-            cd = (ClassDoc)s.pop();
-            fields.addAll(Arrays.asList(cd.fields()));
+            cd = s.pop();
+            fields.addAll(ElementFilter.fieldsIn(cd.getEnclosedElements()));
         }
 
-        return fields.toArray(new FieldDoc[fields.size()]);
+        return fields;
+    }
+
+    // c.f. MethodDoc.signature
+    String signature(ExecutableElement e) {
+        StringBuffer sb = new StringBuffer("(");
+        String sep = "";
+        for (VariableElement p: e.getParameters()) {
+            sb.append(sep);
+            sb.append(types.erasure(p.asType()).toString());
+            sep = ",";
+        }
+        sb.append(")");
+        return sb.toString();
     }
 }
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javah/InternalError.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2007-2008 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.javah;
+
+/**
+ *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
+ *  you write code that depends on this, you do so at your own risk.
+ *  This code and its internal interfaces are subject to change or
+ *  deletion without notice.</b>
+ */
+public class InternalError extends Error {
+    private static final long serialVersionUID = 8411861562497165022L;
+    InternalError(String msg, Throwable cause) {
+        super("Internal error: " + msg);
+        initCause(cause);
+    }
+}
--- a/langtools/src/share/classes/com/sun/tools/javah/JNI.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javah/JNI.java	Fri Oct 16 18:02:31 2009 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2005 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2002-2008 Sun Microsystems, Inc.  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,95 +27,98 @@
 
 import java.io.OutputStream;
 import java.io.PrintWriter;
-import java.util.Vector;
-import java.util.Enumeration;
-import com.sun.javadoc.*;
+import java.util.ArrayList;
+import java.util.List;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.ArrayType;
+import javax.lang.model.type.TypeMirror;
+import javax.lang.model.util.ElementFilter;
 
 
 /**
  * Header file generator for JNI.
  *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems.
+ * If you write code that depends on this, you do so at your own
+ * risk.  This code and its internal interfaces are subject to change
+ * or deletion without notice.</b></p>
+ *
  * @author  Sucheta Dambalkar(Revised)
  */
-
 public class JNI extends Gen {
-
-    public JNI(RootDoc root){
-        super(root);
+    JNI(Util util) {
+        super(util);
     }
 
     public String getIncludes() {
         return "#include <jni.h>";
     }
 
-    public void write(OutputStream o, ClassDoc clazz)
-        throws ClassNotFoundException {
-
-        String cname = Mangle.mangle(clazz.qualifiedName(), Mangle.Type.CLASS);
+    public void write(OutputStream o, TypeElement clazz) throws Util.Exit {
+        String cname = mangler.mangle(clazz.getQualifiedName(), Mangle.Type.CLASS);
         PrintWriter pw = wrapWriter(o);
         pw.println(guardBegin(cname));
         pw.println(cppGuardBegin());
 
         /* Write statics. */
-        FieldDoc[] classfields = getAllFields(clazz);
+        List<VariableElement> classfields = getAllFields(clazz);
 
-        for (int i = 0; i < classfields.length; i++) {
-            if (!classfields[i].isStatic())
+        for (VariableElement v: classfields) {
+            if (!v.getModifiers().contains(Modifier.STATIC))
                 continue;
             String s = null;
-            s = defineForStatic(clazz, classfields[i]);
+            s = defineForStatic(clazz, v);
             if (s != null) {
                 pw.println(s);
             }
         }
 
         /* Write methods. */
-        MethodDoc[] classmethods = clazz.methods();
-        for (int i = 0; i < classmethods.length; i++) {
-            if(classmethods[i].isNative()){
-                MethodDoc md = classmethods[i];
-                Type mtr = classmethods[i].returnType();
-                String sig = md.signature();
-                TypeSignature newtypesig = new TypeSignature(root);
-                String methodName = md.name();
+        List<ExecutableElement> classmethods = ElementFilter.methodsIn(clazz.getEnclosedElements());
+        for (ExecutableElement md: classmethods) {
+            if(md.getModifiers().contains(Modifier.NATIVE)){
+                TypeMirror mtr = types.erasure(md.getReturnType());
+                String sig = signature(md);
+                TypeSignature newtypesig = new TypeSignature(elems);
+                CharSequence methodName = md.getSimpleName();
                 boolean longName = false;
-                for (int j = 0; j < classmethods.length; j++) {
-                    if ((classmethods[j] != md)
-                        && (methodName.equals(classmethods[j].name()))
-                        && (classmethods[j].isNative()))
+                for (ExecutableElement md2: classmethods) {
+                    if ((md2 != md)
+                        && (methodName.equals(md2.getSimpleName()))
+                        && (md2.getModifiers().contains(Modifier.NATIVE)))
                         longName = true;
 
                 }
                 pw.println("/*");
                 pw.println(" * Class:     " + cname);
                 pw.println(" * Method:    " +
-                           Mangle.mangle(methodName, Mangle.Type.FIELDSTUB));
+                           mangler.mangle(methodName, Mangle.Type.FIELDSTUB));
                 pw.println(" * Signature: " + newtypesig.getTypeSignature(sig, mtr));
                 pw.println(" */");
                 pw.println("JNIEXPORT " + jniType(mtr) +
                            " JNICALL " +
-                           Mangle.mangleMethod(md, root,clazz,
+                           mangler.mangleMethod(md, clazz,
                                                (longName) ?
                                                Mangle.Type.METHOD_JNI_LONG :
                                                Mangle.Type.METHOD_JNI_SHORT));
                 pw.print("  (JNIEnv *, ");
-                Parameter[] paramargs = md.parameters();
-                Type []args =new Type[ paramargs.length];
-                for(int p = 0; p < paramargs.length; p++){
-                    args[p] = paramargs[p].type();
+                List<? extends VariableElement> paramargs = md.getParameters();
+                List<TypeMirror> args = new ArrayList<TypeMirror>();
+                for (VariableElement p: paramargs) {
+                    args.add(types.erasure(p.asType()));
                 }
-                if (md.isStatic())
+                if (md.getModifiers().contains(Modifier.STATIC))
                     pw.print("jclass");
                 else
                     pw.print("jobject");
-                if (args.length > 0)
+
+                for (TypeMirror arg: args) {
                     pw.print(", ");
-
-                for (int j = 0; j < args.length; j++) {
-                    pw.print(jniType(args[j]));
-                    if (j != (args.length - 1)) {
-                        pw.print(", ");
-                    }
+                    pw.print(jniType(arg));
                 }
                 pw.println(");" + lineSep);
             }
@@ -125,42 +128,54 @@
     }
 
 
-    protected final String jniType(Type t){
+    protected final String jniType(TypeMirror t) throws Util.Exit {
+        TypeElement throwable = elems.getTypeElement("java.lang.Throwable");
+        TypeElement jClass = elems.getTypeElement("java.lang.Class");
+        TypeElement jString = elems.getTypeElement("java.lang.String");
+        Element tclassDoc = types.asElement(t);
 
-        String elmT = t.typeName();
-        ClassDoc throwable = root.classNamed("java.lang.Throwable");
-        ClassDoc jClass = root.classNamed("java.lang.Class");
-        ClassDoc tclassDoc = t.asClassDoc();
 
-        if((t.dimension()).indexOf("[]") != -1){
-            if((t.dimension().indexOf("[][]") != -1)
-               || (tclassDoc != null))  return "jobjectArray";
-            else if(elmT.equals("boolean"))return  "jbooleanArray";
-            else if(elmT.equals("byte"))return  "jbyteArray";
-            else if(elmT.equals("char"))return  "jcharArray";
-            else if(elmT.equals("short"))return  "jshortArray";
-            else if(elmT.equals("int"))return  "jintArray";
-            else if(elmT.equals("long"))return  "jlongArray";
-            else if(elmT.equals("float"))return  "jfloatArray";
-            else if(elmT.equals("double"))return  "jdoubleArray";
-        }else{
-            if(elmT.equals("void"))return  "void";
-            else if(elmT.equals("String"))return  "jstring";
-            else if(elmT.equals("boolean"))return  "jboolean";
-            else if(elmT.equals("byte"))return  "jbyte";
-            else if(elmT.equals("char"))return  "jchar";
-            else if(elmT.equals("short"))return  "jshort";
-            else if(elmT.equals("int"))return  "jint";
-            else if(elmT.equals("long"))return  "jlong";
-            else if(elmT.equals("float"))return  "jfloat";
-            else if(elmT.equals("double"))return  "jdouble";
-            else  if(tclassDoc  != null){
-                if(tclassDoc.subclassOf(throwable)) return "jthrowable";
-                else if(tclassDoc.subclassOf(jClass)) return "jclass";
-                else return "jobject";
+        switch (t.getKind()) {
+            case ARRAY: {
+                TypeMirror ct = ((ArrayType) t).getComponentType();
+                switch (ct.getKind()) {
+                    case BOOLEAN:  return "jbooleanArray";
+                    case BYTE:     return "jbyteArray";
+                    case CHAR:     return "jcharArray";
+                    case SHORT:    return "jshortArray";
+                    case INT:      return "jintArray";
+                    case LONG:     return "jlongArray";
+                    case FLOAT:    return "jfloatArray";
+                    case DOUBLE:   return "jdoubleArray";
+                    case ARRAY:
+                    case DECLARED: return "jobjectArray";
+                    default: throw new Error(ct.toString());
+                }
+            }
+
+            case VOID:     return "void";
+            case BOOLEAN:  return "jboolean";
+            case BYTE:     return "jbyte";
+            case CHAR:     return "jchar";
+            case SHORT:    return "jshort";
+            case INT:      return "jint";
+            case LONG:     return "jlong";
+            case FLOAT:    return "jfloat";
+            case DOUBLE:   return "jdouble";
+
+            case DECLARED: {
+                if (tclassDoc.equals(jString))
+                    return "jstring";
+                else if (types.isAssignable(t, throwable.asType()))
+                    return "jthrowable";
+                else if (types.isAssignable(t, jClass.asType()))
+                    return "jclass";
+                else
+                    return "jobject";
             }
         }
-        Util.bug("jni.unknown.type");
+
+        util.bug("jni.unknown.type");
         return null; /* dead code. */
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javah/JavahFileManager.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.javah;
+
+import java.io.PrintWriter;
+import java.nio.charset.Charset;
+import javax.tools.DiagnosticListener;
+import javax.tools.JavaFileObject;
+
+import com.sun.tools.javac.file.JavacFileManager;
+import com.sun.tools.javac.util.Context;
+
+/**
+ *  javah's implementation of JavaFileManager.
+ *
+ *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
+ *  you write code that depends on this, you do so at your own risk.
+ *  This code and its internal interfaces are subject to change or
+ *  deletion without notice.</b>
+ */
+class JavahFileManager extends JavacFileManager {
+    private JavahFileManager(Context context, Charset charset) {
+        super(context, true, charset);
+        setIgnoreSymbolFile(true);
+    }
+
+    static JavahFileManager create(final DiagnosticListener<? super JavaFileObject> dl, PrintWriter log) {
+        Context javac_context = new Context();
+
+        if (dl != null)
+            javac_context.put(DiagnosticListener.class, dl);
+        javac_context.put(com.sun.tools.javac.util.Log.outKey, log);
+
+        return new JavahFileManager(javac_context, null);
+    }
+
+    void setIgnoreSymbolFile(boolean b) {
+        ignoreSymbolFile = b;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javah/JavahTask.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,724 @@
+/*
+ * Copyright 2002-2009 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.javah;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+import java.util.Set;
+
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.Messager;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedSourceVersion;
+
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.ArrayType;
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.type.TypeMirror;
+import javax.lang.model.type.TypeVisitor;
+import javax.lang.model.util.ElementFilter;
+import javax.lang.model.util.SimpleTypeVisitor6;
+import javax.lang.model.util.Types;
+
+import javax.tools.Diagnostic;
+import javax.tools.DiagnosticListener;
+import javax.tools.JavaCompiler;
+import javax.tools.JavaCompiler.CompilationTask;
+import javax.tools.JavaFileManager;
+import javax.tools.JavaFileObject;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.StandardLocation;
+import javax.tools.ToolProvider;
+
+/**
+ * Javah generates support files for native methods.
+ * Parse commandline options & Invokes javadoc to execute those commands.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems.
+ * If you write code that depends on this, you do so at your own
+ * risk.  This code and its internal interfaces are subject to change
+ * or deletion without notice.</b></p>
+ *
+ * @author Sucheta Dambalkar
+ * @author Jonathan Gibbons
+ */
+public class JavahTask implements NativeHeaderTool.NativeHeaderTask {
+    public class BadArgs extends Exception {
+        private static final long serialVersionUID = 1479361270874789045L;
+        BadArgs(String key, Object... args) {
+            super(JavahTask.this.getMessage(key, args));
+            this.key = key;
+            this.args = args;
+        }
+
+        BadArgs showUsage(boolean b) {
+            showUsage = b;
+            return this;
+        }
+
+        final String key;
+        final Object[] args;
+        boolean showUsage;
+    }
+
+    static abstract class Option {
+        Option(boolean hasArg, String... aliases) {
+            this.hasArg = hasArg;
+            this.aliases = aliases;
+        }
+
+        boolean isHidden() {
+            return false;
+        }
+
+        boolean matches(String opt) {
+            for (String a: aliases) {
+                if (a.equals(opt))
+                    return true;
+            }
+            return false;
+        }
+
+        boolean ignoreRest() {
+            return false;
+        }
+
+        abstract void process(JavahTask task, String opt, String arg) throws BadArgs;
+
+        final boolean hasArg;
+        final String[] aliases;
+    }
+
+    static abstract class HiddenOption extends Option {
+        HiddenOption(boolean hasArg, String... aliases) {
+            super(hasArg, aliases);
+        }
+
+        @Override
+        boolean isHidden() {
+            return true;
+        }
+    }
+
+    static Option[] recognizedOptions = {
+        new Option(true, "-o") {
+            void process(JavahTask task, String opt, String arg) {
+                task.ofile = new File(arg);
+            }
+        },
+
+        new Option(true, "-d") {
+            void process(JavahTask task, String opt, String arg) {
+                task.odir = new File(arg);
+            }
+        },
+
+        new HiddenOption(true, "-td") {
+            void process(JavahTask task, String opt, String arg) {
+                 // ignored; for backwards compatibility
+            }
+        },
+
+        new HiddenOption(false, "-stubs") {
+            void process(JavahTask task, String opt, String arg) {
+                 // ignored; for backwards compatibility
+            }
+        },
+
+        new Option(false, "-v", "-verbose") {
+            void process(JavahTask task, String opt, String arg) {
+                task.verbose = true;
+            }
+        },
+
+        new Option(false, "-help", "--help", "-?") {
+            void process(JavahTask task, String opt, String arg) {
+                task.help = true;
+            }
+        },
+
+        new HiddenOption(false, "-trace") {
+            void process(JavahTask task, String opt, String arg) {
+                task.trace = true;
+            }
+        },
+
+        new Option(false, "-version") {
+            void process(JavahTask task, String opt, String arg) {
+                task.version = true;
+            }
+        },
+
+        new HiddenOption(false, "-fullversion") {
+            void process(JavahTask task, String opt, String arg) {
+                task.fullVersion = true;
+            }
+        },
+
+        new Option(false, "-jni") {
+            void process(JavahTask task, String opt, String arg) {
+                task.jni = true;
+            }
+        },
+
+        new Option(false, "-force") {
+            void process(JavahTask task, String opt, String arg) {
+                task.force = true;
+            }
+        },
+
+        new HiddenOption(false, "-Xnew") {
+            void process(JavahTask task, String opt, String arg) {
+                // we're already using the new javah
+            }
+        },
+
+        new HiddenOption(false, "-old") {
+            void process(JavahTask task, String opt, String arg) {
+                task.old = true;
+            }
+        },
+
+        new HiddenOption(false, "-llni", "-Xllni") {
+            void process(JavahTask task, String opt, String arg) {
+                task.llni = true;
+            }
+        },
+
+        new HiddenOption(false, "-llnidouble") {
+            void process(JavahTask task, String opt, String arg) {
+                task.llni = true;
+                task.doubleAlign = true;
+            }
+        },
+    };
+
+    JavahTask() {
+    }
+
+    JavahTask(Writer out,
+            JavaFileManager fileManager,
+            DiagnosticListener<? super JavaFileObject> diagnosticListener,
+            Iterable<String> options,
+            Iterable<String> classes) {
+        this();
+        this.log = getPrintWriterForWriter(out);
+        this.fileManager = fileManager;
+        this.diagnosticListener = diagnosticListener;
+
+        try {
+            handleOptions(options, false);
+        } catch (BadArgs e) {
+            throw new IllegalArgumentException(e.getMessage());
+        }
+
+        this.classes = new ArrayList<String>();
+        for (String classname: classes) {
+            classname.getClass(); // null-check
+            this.classes.add(classname);
+        }
+    }
+
+    public void setLocale(Locale locale) {
+        if (locale == null)
+            locale = Locale.getDefault();
+        task_locale = locale;
+    }
+
+    public void setLog(PrintWriter log) {
+        this.log = log;
+    }
+
+    public void setLog(OutputStream s) {
+        setLog(getPrintWriterForStream(s));
+    }
+
+    static PrintWriter getPrintWriterForStream(OutputStream s) {
+        return new PrintWriter(s, true);
+    }
+
+    static PrintWriter getPrintWriterForWriter(Writer w) {
+        if (w == null)
+            return getPrintWriterForStream(null);
+        else if (w instanceof PrintWriter)
+            return (PrintWriter) w;
+        else
+            return new PrintWriter(w, true);
+    }
+
+    public void setDiagnosticListener(DiagnosticListener<? super JavaFileObject> dl) {
+        diagnosticListener = dl;
+    }
+
+    public void setDiagnosticListener(OutputStream s) {
+        setDiagnosticListener(getDiagnosticListenerForStream(s));
+    }
+
+    private DiagnosticListener<JavaFileObject> getDiagnosticListenerForStream(OutputStream s) {
+        return getDiagnosticListenerForWriter(getPrintWriterForStream(s));
+    }
+
+    private DiagnosticListener<JavaFileObject> getDiagnosticListenerForWriter(Writer w) {
+        final PrintWriter pw = getPrintWriterForWriter(w);
+        return new DiagnosticListener<JavaFileObject> () {
+            public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
+                if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
+                    pw.print(getMessage("err.prefix"));
+                    pw.print(" ");
+                }
+                pw.println(diagnostic.getMessage(null));
+            }
+        };
+    }
+
+    int run(String[] args) {
+        try {
+            handleOptions(args);
+            boolean ok = run();
+            return ok ? 0 : 1;
+        } catch (BadArgs e) {
+            diagnosticListener.report(createDiagnostic(e.key, e.args));
+            return 1;
+        } catch (InternalError e) {
+            diagnosticListener.report(createDiagnostic("err.internal.error", e.getMessage()));
+            return 1;
+        } finally {
+            log.flush();
+        }
+    }
+
+    public void handleOptions(String[] args) throws BadArgs {
+        handleOptions(Arrays.asList(args), true);
+    }
+
+    private void handleOptions(Iterable<String> args, boolean allowClasses) throws BadArgs {
+        if (log == null) {
+            log = getPrintWriterForStream(System.out);
+            if (diagnosticListener == null)
+              diagnosticListener = getDiagnosticListenerForStream(System.err);
+        } else {
+            if (diagnosticListener == null)
+              diagnosticListener = getDiagnosticListenerForWriter(log);
+        }
+
+        if (fileManager == null)
+            fileManager = getDefaultFileManager(diagnosticListener, log);
+
+        Iterator<String> iter = args.iterator();
+        if (!iter.hasNext())
+            help = true;
+
+        while (iter.hasNext()) {
+            String arg = iter.next();
+            if (arg.startsWith("-"))
+                handleOption(arg, iter);
+            else if (allowClasses) {
+                if (classes == null)
+                    classes = new ArrayList<String>();
+                classes.add(arg);
+                while (iter.hasNext())
+                    classes.add(iter.next());
+            } else
+                throw new BadArgs("err.unknown.option", arg).showUsage(true);
+        }
+
+        if ((classes == null || classes.size() == 0) &&
+                !(help || version || fullVersion)) {
+            throw new BadArgs("err.no.classes.specified");
+        }
+
+        if (jni && llni)
+            throw new BadArgs("jni.llni.mixed");
+
+        if (odir != null && ofile != null)
+            throw new BadArgs("dir.file.mixed");
+    }
+
+    private void handleOption(String name, Iterator<String> rest) throws BadArgs {
+        for (Option o: recognizedOptions) {
+            if (o.matches(name)) {
+                if (o.hasArg) {
+                    if (rest.hasNext())
+                        o.process(this, name, rest.next());
+                    else
+                        throw new BadArgs("err.missing.arg", name).showUsage(true);
+                } else
+                    o.process(this, name, null);
+
+                if (o.ignoreRest()) {
+                    while (rest.hasNext())
+                        rest.next();
+                }
+                return;
+            }
+        }
+
+        if (fileManager.handleOption(name, rest))
+            return;
+
+        throw new BadArgs("err.unknown.option", name).showUsage(true);
+    }
+
+    public Boolean call() {
+        return run();
+    }
+
+    public boolean run() throws Util.Exit {
+
+        Util util = new Util(log, diagnosticListener);
+
+        if (help) {
+            showHelp();
+            return true;
+        }
+
+        if (version || fullVersion) {
+            showVersion(fullVersion);
+            return true;
+        }
+
+        util.verbose = verbose;
+
+        Gen g;
+
+        if (llni)
+            g = new LLNI(doubleAlign, util);
+        else {
+//            if (stubs)
+//                throw new BadArgs("jni.no.stubs");
+            g = new JNI(util);
+        }
+
+        if (ofile != null) {
+            if (!(fileManager instanceof StandardJavaFileManager)) {
+                diagnosticListener.report(createDiagnostic("err.cant.use.option.for.fm", "-o"));
+                return false;
+            }
+            Iterable<? extends JavaFileObject> iter =
+                    ((StandardJavaFileManager) fileManager).getJavaFileObjectsFromFiles(Collections.singleton(ofile));
+            JavaFileObject fo = iter.iterator().next();
+            g.setOutFile(fo);
+        } else {
+            if (odir != null) {
+                if (!(fileManager instanceof StandardJavaFileManager)) {
+                    diagnosticListener.report(createDiagnostic("err.cant.use.option.for.fm", "-d"));
+                    return false;
+                }
+
+                if (!odir.exists())
+                    if (!odir.mkdirs())
+                        util.error("cant.create.dir", odir.toString());
+                try {
+                    ((StandardJavaFileManager) fileManager).setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(odir));
+                } catch (IOException e) {
+                    Object msg = e.getLocalizedMessage();
+                    if (msg == null) {
+                        msg = e;
+                    }
+                    diagnosticListener.report(createDiagnostic("err.ioerror", odir, msg));
+                    return false;
+                }
+            }
+            g.setFileManager(fileManager);
+        }
+
+        /*
+         * Force set to false will turn off smarts about checking file
+         * content before writing.
+         */
+        g.setForce(force);
+
+        if (fileManager instanceof JavahFileManager)
+            ((JavahFileManager) fileManager).setIgnoreSymbolFile(true);
+
+        JavaCompiler c = ToolProvider.getSystemJavaCompiler();
+        List<String> opts = Arrays.asList("-proc:only");
+        CompilationTask t = c.getTask(log, fileManager, diagnosticListener, opts, internalize(classes), null);
+        JavahProcessor p = new JavahProcessor(g);
+        t.setProcessors(Collections.singleton(p));
+
+        boolean ok = t.call();
+        if (p.exit != null)
+            throw new Util.Exit(p.exit);
+        return ok;
+    }
+
+    private List<String> internalize(List<String> classes) {
+        List<String> l = new ArrayList<String>();
+        for (String c: classes) {
+            l.add(c.replace('$', '.'));
+        }
+        return l;
+    }
+
+    private List<File> pathToFiles(String path) {
+        List<File> files = new ArrayList<File>();
+        for (String f: path.split(File.pathSeparator)) {
+            if (f.length() > 0)
+                files.add(new File(f));
+        }
+        return files;
+    }
+
+    static StandardJavaFileManager getDefaultFileManager(final DiagnosticListener<? super JavaFileObject> dl, PrintWriter log) {
+        return JavahFileManager.create(dl, log);
+    }
+
+    private void showHelp() {
+        log.println(getMessage("main.usage", progname));
+        for (Option o: recognizedOptions) {
+            if (o.isHidden())
+                continue;
+            String name = o.aliases[0].substring(1); // there must always be at least one name
+            log.println(getMessage("main.opt." + name));
+        }
+        String[] fmOptions = { "-classpath", "-bootclasspath" };
+        for (String o: fmOptions) {
+            if (fileManager.isSupportedOption(o) == -1)
+                continue;
+            String name = o.substring(1);
+            log.println(getMessage("main.opt." + name));
+        }
+        log.println(getMessage("main.usage.foot"));
+    }
+
+    private void showVersion(boolean full) {
+        log.println(version(full ? "full" : "release"));
+    }
+
+    private static final String versionRBName = "com.sun.tools.javah.resources.version";
+    private static ResourceBundle versionRB;
+
+    private String version(String key) {
+        // key=version:  mm.nn.oo[-milestone]
+        // key=full:     mm.mm.oo[-milestone]-build
+        if (versionRB == null) {
+            try {
+                versionRB = ResourceBundle.getBundle(versionRBName);
+            } catch (MissingResourceException e) {
+                return getMessage("version.resource.missing", System.getProperty("java.version"));
+            }
+        }
+        try {
+            return versionRB.getString(key);
+        }
+        catch (MissingResourceException e) {
+            return getMessage("version.unknown", System.getProperty("java.version"));
+        }
+    }
+
+    private Diagnostic<JavaFileObject> createDiagnostic(final String key, final Object... args) {
+        return new Diagnostic<JavaFileObject>() {
+            public Kind getKind() {
+                return Diagnostic.Kind.ERROR;
+            }
+
+            public JavaFileObject getSource() {
+                return null;
+            }
+
+            public long getPosition() {
+                return Diagnostic.NOPOS;
+            }
+
+            public long getStartPosition() {
+                return Diagnostic.NOPOS;
+            }
+
+            public long getEndPosition() {
+                return Diagnostic.NOPOS;
+            }
+
+            public long getLineNumber() {
+                return Diagnostic.NOPOS;
+            }
+
+            public long getColumnNumber() {
+                return Diagnostic.NOPOS;
+            }
+
+            public String getCode() {
+                return key;
+            }
+
+            public String getMessage(Locale locale) {
+                return JavahTask.this.getMessage(locale, key, args);
+            }
+
+        };
+
+    }
+    private String getMessage(String key, Object... args) {
+        return getMessage(task_locale, key, args);
+    }
+
+    private String getMessage(Locale locale, String key, Object... args) {
+        if (bundles == null) {
+            // could make this a HashMap<Locale,SoftReference<ResourceBundle>>
+            // and for efficiency, keep a hard reference to the bundle for the task
+            // locale
+            bundles = new HashMap<Locale, ResourceBundle>();
+        }
+
+        if (locale == null)
+            locale = Locale.getDefault();
+
+        ResourceBundle b = bundles.get(locale);
+        if (b == null) {
+            try {
+                b = ResourceBundle.getBundle("com.sun.tools.javah.resources.l10n", locale);
+                bundles.put(locale, b);
+            } catch (MissingResourceException e) {
+                throw new InternalError("Cannot find javah resource bundle for locale " + locale, e);
+            }
+        }
+
+        try {
+            return MessageFormat.format(b.getString(key), args);
+        } catch (MissingResourceException e) {
+            return key;
+            //throw new InternalError(e, key);
+        }
+    }
+
+    File ofile;
+    File odir;
+    String bootcp;
+    String usercp;
+    List<String> classes;
+    boolean verbose;
+    boolean help;
+    boolean trace;
+    boolean version;
+    boolean fullVersion;
+    boolean jni;
+    boolean llni;
+    boolean doubleAlign;
+    boolean force;
+    boolean old;
+
+    PrintWriter log;
+    JavaFileManager fileManager;
+    DiagnosticListener<? super JavaFileObject> diagnosticListener;
+    Locale task_locale;
+    Map<Locale, ResourceBundle> bundles;
+
+    private static final String progname = "javah";
+
+    @SupportedAnnotationTypes("*")
+    @SupportedSourceVersion(SourceVersion.RELEASE_7)
+    class JavahProcessor extends AbstractProcessor {
+        JavahProcessor(Gen g) {
+            this.g = g;
+        }
+
+        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+            Messager messager  = processingEnv.getMessager();
+            Set<TypeElement> classes = getAllClasses(ElementFilter.typesIn(roundEnv.getRootElements()));
+            if (classes.size() > 0) {
+                checkMethodParameters(classes);
+                g.setProcessingEnvironment(processingEnv);
+                g.setClasses(classes);
+
+                try {
+                    g.run();
+                } catch (ClassNotFoundException cnfe) {
+                    messager.printMessage(Diagnostic.Kind.ERROR, getMessage("class.not.found", cnfe.getMessage()));
+                } catch (IOException ioe) {
+                    messager.printMessage(Diagnostic.Kind.ERROR, getMessage("io.exception", ioe.getMessage()));
+                } catch (Util.Exit e) {
+                    exit = e;
+                }
+            }
+            return true;
+        }
+
+        private Set<TypeElement> getAllClasses(Set<? extends TypeElement> classes) {
+            Set<TypeElement> allClasses = new LinkedHashSet<TypeElement>();
+            getAllClasses0(classes, allClasses);
+            return allClasses;
+        }
+
+        private void getAllClasses0(Iterable<? extends TypeElement> classes, Set<TypeElement> allClasses) {
+            for (TypeElement c: classes) {
+                allClasses.add(c);
+                getAllClasses0(ElementFilter.typesIn(c.getEnclosedElements()), allClasses);
+            }
+        }
+
+        // 4942232:
+        // check that classes exist for all the parameters of native methods
+        private void checkMethodParameters(Set<TypeElement> classes) {
+            Types types = processingEnv.getTypeUtils();
+            for (TypeElement te: classes) {
+                for (ExecutableElement ee: ElementFilter.methodsIn(te.getEnclosedElements())) {
+                    for (VariableElement ve: ee.getParameters()) {
+                        TypeMirror tm = ve.asType();
+                        checkMethodParametersVisitor.visit(tm, types);
+                    }
+                }
+            }
+        }
+
+        private TypeVisitor<Void,Types> checkMethodParametersVisitor =
+                new SimpleTypeVisitor6<Void,Types>() {
+            @Override
+            public Void visitArray(ArrayType t, Types types) {
+                visit(t.getComponentType(), types);
+                return null;
+            }
+            @Override
+            public Void visitDeclared(DeclaredType t, Types types) {
+                t.asElement().getKind(); // ensure class exists
+                for (TypeMirror st: types.directSupertypes(t))
+                    visit(st, types);
+                return null;
+            }
+        };
+
+        private Gen g;
+        private Util.Exit exit;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javah/JavahTool.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.javah;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.Locale;
+import java.util.Set;
+import javax.lang.model.SourceVersion;
+import javax.tools.DiagnosticListener;
+import javax.tools.JavaFileManager;
+import javax.tools.JavaFileObject;
+import javax.tools.StandardJavaFileManager;
+
+/*
+ * <p><b>This is NOT part of any API supported by Sun Microsystems.
+ * If you write code that depends on this, you do so at your own
+ * risk.  This code and its internal interfaces are subject to change
+ * or deletion without notice.</b></p>
+ */
+public class JavahTool implements NativeHeaderTool {
+
+    public NativeHeaderTask getTask(Writer out,
+            JavaFileManager fileManager,
+            DiagnosticListener<? super JavaFileObject> diagnosticListener,
+            Iterable<String> options,
+            Iterable<String> classes) {
+        return new JavahTask(out, fileManager, diagnosticListener, options, classes);
+    }
+
+    public StandardJavaFileManager getStandardFileManager(DiagnosticListener<? super JavaFileObject> diagnosticListener, Locale locale, Charset charset) {
+        return JavahTask.getDefaultFileManager(diagnosticListener, null);
+    }
+
+    public int run(InputStream in, OutputStream out, OutputStream err, String... arguments) {
+        JavahTask t = new JavahTask(
+                JavahTask.getPrintWriterForStream(out),
+                null,
+                null,
+                Arrays.asList(arguments),
+                null);
+        return (t.run() ? 0 : 1);
+    }
+
+    public Set<SourceVersion> getSourceVersions() {
+        return EnumSet.allOf(SourceVersion.class);
+    }
+
+    public int isSupportedOption(String option) {
+        JavahTask.Option[] options = JavahTask.recognizedOptions;
+        for (int i = 0; i < options.length; i++) {
+            if (options[i].matches(option))
+                return (options[i].hasArg ? 1 : 0);
+        }
+        return -1;
+    }
+}
--- a/langtools/src/share/classes/com/sun/tools/javah/LLNI.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javah/LLNI.java	Fri Oct 16 18:02:31 2009 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2005 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2002-2008 Sun Microsystems, Inc.  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,49 +26,65 @@
 
 package com.sun.tools.javah;
 
-import java.io.File;
 import java.io.OutputStream;
 import java.io.PrintWriter;
-import java.util.Hashtable;
-import com.sun.javadoc.*;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
 
- /*
-  * @author  Sucheta Dambalkar(Revised)
-  */
+import java.util.Set;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.Name;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.ArrayType;
+import javax.lang.model.type.PrimitiveType;
+import javax.lang.model.type.TypeKind;
+import javax.lang.model.type.TypeMirror;
+import javax.lang.model.type.TypeVisitor;
+import javax.lang.model.util.ElementFilter;
+import javax.lang.model.util.SimpleTypeVisitor6;
+
+/*
+ * <p><b>This is NOT part of any API supported by Sun Microsystems.
+ * If you write code that depends on this, you do so at your own
+ * risk.  This code and its internal interfaces are subject to change
+ * or deletion without notice.</b></p>
+ *
+ * @author  Sucheta Dambalkar(Revised)
+ */
 public class LLNI extends Gen {
 
-    protected final char  pathChar = File.separatorChar;
     protected final char  innerDelim = '$';     /* For inner classes */
-    protected Hashtable<Object, Object>   doneHandleTypes;
-    MemberDoc []fields;
-    MemberDoc [] methods;
+    protected Set<String>  doneHandleTypes;
+    List<VariableElement> fields;
+    List<ExecutableElement> methods;
     private boolean       doubleAlign;
     private int           padFieldNum = 0;
 
-
-    LLNI(boolean doubleAlign, RootDoc root) {
-        super(root);
+    LLNI(boolean doubleAlign, Util util) {
+        super(util);
         this.doubleAlign = doubleAlign;
     }
 
-
     protected String getIncludes() {
         return "";
     }
 
-    protected void write(OutputStream o, ClassDoc clazz)
-        throws ClassNotFoundException {
-        String cname     = mangleClassName(clazz.qualifiedName());
+    protected void write(OutputStream o, TypeElement clazz) throws Util.Exit {
+        String cname     = mangleClassName(clazz.getQualifiedName().toString());
         PrintWriter pw   = wrapWriter(o);
-        fields = clazz.fields();
-        methods = clazz.methods();
+        fields = ElementFilter.fieldsIn(clazz.getEnclosedElements());
+        methods = ElementFilter.methodsIn(clazz.getEnclosedElements());
         generateDeclsForClass(pw, clazz, cname);
+        // FIXME check if errors occurred on the PrintWriter and throw exception if so
     }
 
     protected void generateDeclsForClass(PrintWriter pw,
-                                         ClassDoc clazz, String cname)
-        throws ClassNotFoundException {
-        doneHandleTypes  = new Hashtable<Object, Object>();
+            TypeElement clazz, String cname) throws Util.Exit {
+        doneHandleTypes  = new HashSet<String>();
         /* The following handle types are predefined in "typedefs.h". Suppress
            inclusion in the output by generating them "into the blue" here. */
         genHandleType(null, "java.lang.Class");
@@ -79,7 +95,7 @@
         genHandleType(null, "java.lang.ThreadGroup");
         genHandleType(null, "java.lang.Throwable");
 
-        pw.println("/* LLNI Header for class " + clazz.qualifiedName() + " */" + lineSep);
+        pw.println("/* LLNI Header for class " + clazz.getQualifiedName() + " */" + lineSep);
         pw.println("#ifndef _Included_" + cname);
         pw.println("#define _Included_" + cname);
         pw.println("#include \"typedefs.h\"");
@@ -94,8 +110,8 @@
 
     protected void genHandleType(PrintWriter pw, String clazzname) {
         String cname = mangleClassName(clazzname);
-        if (!doneHandleTypes.containsKey(cname)) {
-            doneHandleTypes.put(cname, cname);
+        if (!doneHandleTypes.contains(cname)) {
+            doneHandleTypes.add(cname);
             if (pw != null) {
                 pw.println("#ifndef DEFINED_" + cname);
                 pw.println("    #define DEFINED_" + cname);
@@ -107,31 +123,29 @@
 
     protected String mangleClassName(String s) {
         return s.replace('.', '_')
-            .replace(pathChar, '_')
+            .replace('/', '_')
             .replace(innerDelim, '_');
     }
 
-    protected void forwardDecls(PrintWriter pw, ClassDoc clazz)
-        throws ClassNotFoundException {
-        ClassDoc clazzfield = null;
-
-        if (clazz.qualifiedName().equals("java.lang.Object"))
+    protected void forwardDecls(PrintWriter pw, TypeElement clazz) {
+        TypeElement object = elems.getTypeElement("java.lang.Object");
+        if (clazz.equals(object))
             return;
-        genHandleType(pw, clazz.qualifiedName());
-        ClassDoc superClass = clazz.superclass();
 
-        if(superClass != null){
-            String superClassName = superClass.qualifiedName();
+        genHandleType(pw, clazz.getQualifiedName().toString());
+        TypeElement superClass = (TypeElement) (types.asElement(clazz.getSuperclass()));
+
+        if (superClass != null) {
+            String superClassName = superClass.getQualifiedName().toString();
             forwardDecls(pw, superClass);
         }
 
-        for (int i = 0; i < fields.length; i++) {
-            FieldDoc field = (FieldDoc)fields[i];
+        for (VariableElement field: fields) {
 
-            if (!field.isStatic()) {
-                Type t = field.type();
-                String tname = t.qualifiedTypeName();
-                TypeSignature newTypeSig = new TypeSignature(root);
+            if (!field.getModifiers().contains(Modifier.STATIC)) {
+                TypeMirror t = types.erasure(field.asType());
+                TypeSignature newTypeSig = new TypeSignature(elems);
+                String tname = newTypeSig.qualifiedTypeName(t);
                 String sig = newTypeSig.getTypeSignature(tname);
 
                 if (sig.charAt(0) != '[')
@@ -139,13 +153,12 @@
             }
         }
 
-        for (int i = 0; i < methods.length; i++) {
-            MethodDoc method = (MethodDoc)methods[i];
+        for (ExecutableElement method: methods) {
 
-            if (method.isNative()) {
-                Type retType = method.returnType();
-                String typesig = method.signature();
-                TypeSignature newTypeSig = new TypeSignature(root);
+            if (method.getModifiers().contains(Modifier.NATIVE)) {
+                TypeMirror retType = types.erasure(method.getReturnType());
+                String typesig = signature(method);
+                TypeSignature newTypeSig = new TypeSignature(elems);
                 String sig = newTypeSig.getTypeSignature(typesig, retType);
 
                 if (sig.charAt(0) != '[')
@@ -173,10 +186,9 @@
     }
 
     protected void structSectionForClass(PrintWriter pw,
-                                         ClassDoc jclazz, String cname)
-        throws ClassNotFoundException {
+                                         TypeElement jclazz, String cname) {
 
-        String jname = jclazz.qualifiedName();
+        String jname = jclazz.getQualifiedName().toString();
 
         if (cname.equals("java_lang_Object")) {
             pw.println("/* struct java_lang_Object is defined in typedefs.h. */");
@@ -207,8 +219,8 @@
         public boolean bottomMost;
         public boolean printedOne = false;
 
-        FieldDefsRes(ClassDoc clazz, FieldDefsRes parent, boolean bottomMost) {
-            this.className = clazz.qualifiedName();
+        FieldDefsRes(TypeElement clazz, FieldDefsRes parent, boolean bottomMost) {
+            this.className = clazz.getQualifiedName().toString();
             this.parent = parent;
             this.bottomMost = bottomMost;
             int byteSize = 0;
@@ -218,9 +230,8 @@
     }
 
     /* Returns "true" iff added a field. */
-    private boolean doField(FieldDefsRes res, FieldDoc field,
-                            String cname, boolean padWord)
-        throws ClassNotFoundException {
+    private boolean doField(FieldDefsRes res, VariableElement field,
+                            String cname, boolean padWord) {
 
         String fieldDef = addStructMember(field, cname, padWord);
         if (fieldDef != null) {
@@ -242,16 +253,14 @@
         return false;
     }
 
-    private int doTwoWordFields(FieldDefsRes res, ClassDoc clazz,
-                                int offset, String cname, boolean padWord)
-        throws ClassNotFoundException {
+    private int doTwoWordFields(FieldDefsRes res, TypeElement clazz,
+                                int offset, String cname, boolean padWord) {
         boolean first = true;
-        FieldDoc[] fields = clazz.fields();
+        List<VariableElement> fields = ElementFilter.fieldsIn(clazz.getEnclosedElements());
 
-        for (int i = 0; i <fields.length; i++) {
-            FieldDoc field = fields[i];
-            String tc =field.type().typeName();
-            boolean twoWords = (tc.equals("long") || tc.equals("double"));
+        for (VariableElement field: fields) {
+            TypeKind tk = field.asType().getKind();
+            boolean twoWords = (tk == TypeKind.LONG || tk == TypeKind.DOUBLE);
             if (twoWords && doField(res, field, cname, first && padWord)) {
                 offset += 8; first = false;
             }
@@ -259,22 +268,21 @@
         return offset;
     }
 
-    protected String fieldDefs(ClassDoc clazz, String cname)
-        throws ClassNotFoundException {
+    String fieldDefs(TypeElement clazz, String cname) {
         FieldDefsRes res = fieldDefs(clazz, cname, true);
         return res.s;
     }
 
-    protected FieldDefsRes fieldDefs(ClassDoc clazz, String cname,
-                                     boolean bottomMost)
-        throws ClassNotFoundException {
+    FieldDefsRes fieldDefs(TypeElement clazz, String cname,
+                                     boolean bottomMost){
         FieldDefsRes res;
         int offset;
         boolean didTwoWordFields = false;
-        ClassDoc superclazz = clazz.superclass();
+
+        TypeElement superclazz = (TypeElement) types.asElement(clazz.getSuperclass());
 
         if (superclazz != null) {
-            String supername = superclazz.qualifiedName();
+            String supername = superclazz.getQualifiedName().toString();
             res = new FieldDefsRes(clazz,
                                    fieldDefs(superclazz, cname, false),
                                    bottomMost);
@@ -284,18 +292,17 @@
             offset = 0;
         }
 
-        FieldDoc[] fields = clazz.fields();
+        List<VariableElement> fields = ElementFilter.fieldsIn(clazz.getEnclosedElements());
 
-        for (int i = 0; i < fields.length; i++) {
-            FieldDoc field = fields[i];
+        for (VariableElement field: fields) {
 
             if (doubleAlign && !didTwoWordFields && (offset % 8) == 0) {
                 offset = doTwoWordFields(res, clazz, offset, cname, false);
                 didTwoWordFields = true;
             }
 
-            String tc = field.type().typeName();
-            boolean twoWords = (tc.equals("long") ||tc.equals("double"));
+            TypeKind tk = field.asType().getKind();
+            boolean twoWords = (tk == TypeKind.LONG || tk == TypeKind.DOUBLE);
 
             if (!doubleAlign || !twoWords) {
                 if (doField(res, field, cname, false)) offset += 4;
@@ -313,19 +320,19 @@
     }
 
     /* OVERRIDE: This method handles instance fields */
-    protected String addStructMember(FieldDoc member, String cname,
-                                     boolean padWord)
-        throws ClassNotFoundException {
+    protected String addStructMember(VariableElement member, String cname,
+                                     boolean padWord) {
         String res = null;
 
-        if (member.isStatic()) {
+        if (member.getModifiers().contains(Modifier.STATIC)) {
             res = addStaticStructMember(member, cname);
             //   if (res == null) /* JNI didn't handle it, print comment. */
             //  res = "    /* Inaccessible static: " + member + " */" + lineSep;
         } else {
+            TypeMirror mt = types.erasure(member.asType());
             if (padWord) res = "    java_int padWord" + padFieldNum++ + ";" + lineSep;
-            res = "    " + llniType(member.type(), false, false) + " " + llniFieldName(member);
-            if (isLongOrDouble(member.type())) res = res + "[2]";
+            res = "    " + llniType(mt, false, false) + " " + llniFieldName(member);
+            if (isLongOrDouble(mt)) res = res + "[2]";
             res = res + ";" + lineSep;
         }
         return res;
@@ -337,36 +344,42 @@
     /*
      * This method only handles static final fields.
      */
-    protected String addStaticStructMember(FieldDoc field, String cname)
-        throws ClassNotFoundException {
+    protected String addStaticStructMember(VariableElement field, String cname) {
         String res = null;
         Object exp = null;
 
-        if (!field.isStatic())
+        if (!field.getModifiers().contains(Modifier.STATIC))
             return res;
-        if (!field.isFinal())
+        if (!field.getModifiers().contains(Modifier.FINAL))
             return res;
 
-        exp = field.constantValue();
+        exp = field.getConstantValue();
 
         if (exp != null) {
             /* Constant. */
 
-            String     cn     = cname + "_" + field.name();
+            String     cn     = cname + "_" + field.getSimpleName();
             String     suffix = null;
             long           val = 0;
             /* Can only handle int, long, float, and double fields. */
-            if (exp instanceof Integer) {
+            if (exp instanceof Byte
+                || exp instanceof Short
+                || exp instanceof Integer) {
                 suffix = "L";
-                val = ((Integer)exp).intValue();
+                val = ((Number)exp).intValue();
             }
-            if (exp instanceof Long) {
+            else if (exp instanceof Long) {
                 // Visual C++ supports the i64 suffix, not LL
                 suffix = isWindows ? "i64" : "LL";
                 val = ((Long)exp).longValue();
             }
-            if (exp instanceof Float)  suffix = "f";
-            if (exp instanceof Double) suffix = "";
+            else if (exp instanceof Float)  suffix = "f";
+            else if (exp instanceof Double) suffix = "";
+            else if (exp instanceof Character) {
+                suffix = "L";
+                Character ch = (Character) exp;
+                val = ((int) ch) & 0xffff;
+            }
             if (suffix != null) {
                 // Some compilers will generate a spurious warning
                 // for the integer constants for Integer.MIN_VALUE
@@ -376,9 +389,12 @@
                     res = "    #undef  " + cn + lineSep
                         + "    #define " + cn
                         + " (" + (val + 1) + suffix + "-1)" + lineSep;
+                } else if (suffix.equals("L") || suffix.endsWith("LL")) {
+                    res = "    #undef  " + cn + lineSep
+                        + "    #define " + cn + " " + val + suffix + lineSep;
                 } else {
                     res = "    #undef  " + cn + lineSep
-                        + "    #define " + cn + " "+ exp.toString() + suffix + lineSep;
+                        + "    #define " + cn + " " + exp + suffix + lineSep;
                 }
             }
         }
@@ -386,8 +402,8 @@
     }
 
     protected void methodSectionForClass(PrintWriter pw,
-                                         ClassDoc clazz, String cname)
-        throws ClassNotFoundException {
+            TypeElement clazz, String cname)
+            throws Util.Exit {
         String methods = methodDecls(clazz, cname);
 
         if (methods.length() != 0) {
@@ -402,81 +418,77 @@
         }
     }
 
-    protected String methodDecls(ClassDoc clazz, String cname)
-        throws ClassNotFoundException {
+    protected String methodDecls(TypeElement clazz, String cname) throws Util.Exit {
 
         String res = "";
-        for (int i = 0; i < methods.length; i++) {
-            MethodDoc method = (MethodDoc)methods[i];
-            if (method.isNative())
+        for (ExecutableElement method: methods) {
+            if (method.getModifiers().contains(Modifier.NATIVE))
                 res = res + methodDecl(method, clazz, cname);
         }
         return res;
     }
 
-    protected String methodDecl(MethodDoc method,
-                                ClassDoc clazz, String cname)
-        throws ClassNotFoundException {
+    protected String methodDecl(ExecutableElement method,
+                                TypeElement clazz, String cname)
+    throws Util.Exit {
         String res = null;
 
-        Type retType = method.returnType();
-        String typesig = method.signature();
-        TypeSignature newTypeSig = new TypeSignature(root);
+        TypeMirror retType = types.erasure(method.getReturnType());
+        String typesig = signature(method);
+        TypeSignature newTypeSig = new TypeSignature(elems);
         String sig = newTypeSig.getTypeSignature(typesig, retType);
         boolean longName = needLongName(method, clazz);
 
         if (sig.charAt(0) != '(')
-            Util.error("invalid.method.signature", sig);
+            util.error("invalid.method.signature", sig);
 
 
         res = "JNIEXPORT " + jniType(retType) + " JNICALL" + lineSep + jniMethodName(method, cname, longName)
             + "(JNIEnv *, " + cRcvrDecl(method, cname);
-        Parameter[] params = method.parameters();
-        Type argTypes[] = new Type[params.length];
-        for(int p = 0; p <  params.length; p++){
-            argTypes[p] =  params[p].type();
+        List<? extends VariableElement> params = method.getParameters();
+        List<TypeMirror> argTypes = new ArrayList<TypeMirror>();
+        for (VariableElement p: params){
+            argTypes.add(types.erasure(p.asType()));
         }
 
         /* It would have been nice to include the argument names in the
            declaration, but there seems to be a bug in the "BinaryField"
            class, causing the getArguments() method to return "null" for
            most (non-constructor) methods. */
-        for (int i = 0; i < argTypes.length; i++)
-            res = res + ", " + jniType(argTypes[i]);
+        for (TypeMirror argType: argTypes)
+            res = res + ", " + jniType(argType);
         res = res + ");" + lineSep;
         return res;
     }
 
-    protected final boolean needLongName(MethodDoc method,
-                                         ClassDoc clazz)
-        throws ClassNotFoundException {
-        String methodName = method.name();
-        for (int i = 0; i < methods.length; i++) {
-            MethodDoc memberMethod = (MethodDoc) methods[i];
+    protected final boolean needLongName(ExecutableElement method,
+                                         TypeElement clazz) {
+        Name methodName = method.getSimpleName();
+        for (ExecutableElement memberMethod: methods) {
             if ((memberMethod != method) &&
-                memberMethod.isNative() && (methodName == memberMethod.name()))
+                memberMethod.getModifiers().contains(Modifier.NATIVE) &&
+                    (methodName.equals(memberMethod.getSimpleName())))
                 return true;
         }
         return false;
     }
 
-    protected final String jniMethodName(MethodDoc method, String cname,
+    protected final String jniMethodName(ExecutableElement method, String cname,
                                          boolean longName) {
-        String res = "Java_" + cname + "_" + method.name();
+        String res = "Java_" + cname + "_" + method.getSimpleName();
 
         if (longName) {
-            Type mType =  method.returnType();
-            Parameter[] params = method.parameters();
-            Type argTypes[] = new Type[params.length];
-            for(int p = 0; p <  params.length; p++){
-                argTypes[p] =  params[p].type();
+            TypeMirror mType =  types.erasure(method.getReturnType());
+            List<? extends VariableElement> params = method.getParameters();
+            List<TypeMirror> argTypes = new ArrayList<TypeMirror>();
+            for (VariableElement param: params) {
+                argTypes.add(types.erasure(param.asType()));
             }
 
             res = res + "__";
-            for (int i = 0; i < argTypes.length; i++){
-                Type t = argTypes[i];
-                String tname = t.typeName();
-                TypeSignature newTypeSig = new TypeSignature(root);
+            for (TypeMirror t: argTypes) {
+                String tname = t.toString();
+                TypeSignature newTypeSig = new TypeSignature(elems);
                 String sig = newTypeSig.getTypeSignature(tname);
                 res = res + nameToIdentifier(sig);
             }
@@ -484,88 +496,143 @@
         return res;
     }
 
-    protected final String jniType(Type t) {
-        String elmT =t.typeName();
-        if (t.dimension().indexOf("[]") != -1) {
-            if(elmT.equals("boolean"))return "jbooleanArray";
-            else if(elmT.equals("byte"))return "jbyteArray";
-            else if(elmT.equals("char"))return "jcharArray";
-            else if(elmT.equals("short"))return "jshortArray";
-            else if(elmT.equals("int"))return "jintArray";
-            else if(elmT.equals("long"))return "jlongArray";
-            else if(elmT.equals("float"))return "jfloatArray";
-            else if(elmT.equals("double"))return "jdoubleArray";
-            else if((t.dimension().indexOf("[][]") != -1) || (t.asClassDoc() != null))  return "jobjectArray";
-        } else {
-            if(elmT.equals("void"))return "void";
-            else if(elmT.equals("boolean"))return "jboolean";
-            else if(elmT.equals("byte"))return "jbyte";
-            else if(elmT.equals("char"))return "jchar";
-            else if(elmT.equals("short"))return "jshort";
-            else if(elmT.equals("int"))return "jint";
-            else if(elmT.equals("long"))return "jlong";
-            else if(elmT.equals("float"))return "jfloat";
-            else if(elmT.equals("double"))return "jdouble";
-            else if (t.asClassDoc() != null) {
-                if (elmT.equals("String"))
+    // copied from JNI.java
+    protected final String jniType(TypeMirror t) throws Util.Exit {
+        TypeElement throwable = elems.getTypeElement("java.lang.Throwable");
+        TypeElement jClass = elems.getTypeElement("java.lang.Class");
+        TypeElement jString = elems.getTypeElement("java.lang.String");
+        Element tclassDoc = types.asElement(t);
+
+        switch (t.getKind()) {
+            case ARRAY: {
+                TypeMirror ct = ((ArrayType) t).getComponentType();
+                switch (ct.getKind()) {
+                    case BOOLEAN:  return "jbooleanArray";
+                    case BYTE:     return "jbyteArray";
+                    case CHAR:     return "jcharArray";
+                    case SHORT:    return "jshortArray";
+                    case INT:      return "jintArray";
+                    case LONG:     return "jlongArray";
+                    case FLOAT:    return "jfloatArray";
+                    case DOUBLE:   return "jdoubleArray";
+                    case ARRAY:
+                    case DECLARED: return "jobjectArray";
+                    default: throw new Error(ct.toString());
+                }
+            }
+
+            case VOID:     return "void";
+            case BOOLEAN:  return "jboolean";
+            case BYTE:     return "jbyte";
+            case CHAR:     return "jchar";
+            case SHORT:    return "jshort";
+            case INT:      return "jint";
+            case LONG:     return "jlong";
+            case FLOAT:    return "jfloat";
+            case DOUBLE:   return "jdouble";
+
+            case DECLARED: {
+                if (tclassDoc.equals(jString))
                     return "jstring";
-                else if (t.asClassDoc().subclassOf(root.classNamed("java.lang.Class")))
+                else if (types.isAssignable(t, throwable.asType()))
+                    return "jthrowable";
+                else if (types.isAssignable(t, jClass.asType()))
                     return "jclass";
                 else
                     return "jobject";
             }
         }
-        Util.bug("jni.unknown.type");
+
+        util.bug("jni.unknown.type");
         return null; /* dead code. */
     }
 
-    protected String llniType(Type t, boolean handleize, boolean longDoubleOK) {
+    protected String llniType(TypeMirror t, boolean handleize, boolean longDoubleOK) {
         String res = null;
-        String elmt = t.typeName();
-        if (t.dimension().indexOf("[]") != -1) {
-            if((t.dimension().indexOf("[][]") != -1)
-               || (t.asClassDoc() != null)) res = "IArrayOfRef";
-            else if(elmt.equals("boolean")) res =  "IArrayOfBoolean";
-            else if(elmt.equals("byte")) res =  "IArrayOfByte";
-            else if(elmt.equals("char")) res =  "IArrayOfChar";
-            else if(elmt.equals("int")) res =  "IArrayOfInt";
-            else if(elmt.equals("long")) res =  "IArrayOfLong";
-            else if(elmt.equals("float")) res =  "IArrayOfFloat";
-            else if(elmt.equals("double")) res =  "IArrayOfDouble";
-            if (!handleize) res = "DEREFERENCED_" + res;
-        } else {
-            if(elmt.equals("void")) res =  "void";
-            else if( (elmt.equals("boolean")) || (elmt.equals("byte"))
-                     ||(elmt.equals("char")) || (elmt.equals("short"))
-                     || (elmt.equals("int")))   res = "java_int";
-            else   if(elmt.equals("long")) res = longDoubleOK
-                                               ? "java_long" : "val32 /* java_long */";
-            else   if(elmt.equals("float")) res =  "java_float";
-            else   if(elmt.equals("double")) res =  res = longDoubleOK
-                                                 ? "java_double" : "val32 /* java_double */";
-            else if(t.asClassDoc() != null) {
-                res = "I" +  mangleClassName(t.asClassDoc().qualifiedName());
+
+        switch (t.getKind()) {
+            case ARRAY: {
+                TypeMirror ct = ((ArrayType) t).getComponentType();
+                switch (ct.getKind()) {
+                    case BOOLEAN:  res = "IArrayOfBoolean"; break;
+                    case BYTE:     res = "IArrayOfByte";    break;
+                    case CHAR:     res = "IArrayOfChar";    break;
+                    case SHORT:    res = "IArrayOfShort";   break;
+                    case INT:      res = "IArrayOfInt";     break;
+                    case LONG:     res = "IArrayOfLong";    break;
+                    case FLOAT:    res = "IArrayOfFloat";   break;
+                    case DOUBLE:   res = "IArrayOfDouble";  break;
+                    case ARRAY:
+                    case DECLARED: res = "IArrayOfRef";     break;
+                    default: throw new Error(ct.getKind() + " " + ct);
+                }
                 if (!handleize) res = "DEREFERENCED_" + res;
+                break;
             }
+
+            case VOID:
+                res = "void";
+                break;
+
+            case BOOLEAN:
+            case BYTE:
+            case CHAR:
+            case SHORT:
+            case INT:
+                res = "java_int" ;
+                break;
+
+            case LONG:
+                res = longDoubleOK ? "java_long" : "val32 /* java_long */";
+                break;
+
+            case FLOAT:
+                res =  "java_float";
+                break;
+
+            case DOUBLE:
+                res = longDoubleOK ? "java_double" : "val32 /* java_double */";
+                break;
+
+            case DECLARED:
+                TypeElement e  = (TypeElement) types.asElement(t);
+                res = "I" +  mangleClassName(e.getQualifiedName().toString());
+                if (!handleize) res = "DEREFERENCED_" + res;
+                break;
+
+            default:
+                throw new Error(t.getKind() + " " + t); // FIXME
         }
+
         return res;
     }
 
-    protected final String cRcvrDecl(MemberDoc field, String cname) {
-        return (field.isStatic() ? "jclass" : "jobject");
+    protected final String cRcvrDecl(Element field, String cname) {
+        return (field.getModifiers().contains(Modifier.STATIC) ? "jclass" : "jobject");
     }
 
     protected String maskName(String s) {
         return "LLNI_mask(" + s + ")";
     }
 
-    protected String llniFieldName(MemberDoc field) {
-        return maskName(field.name());
+    protected String llniFieldName(VariableElement field) {
+        return maskName(field.getSimpleName().toString());
     }
 
-    protected final boolean isLongOrDouble(Type t) {
-        String tc = t.typeName();
-        return (tc.equals("long") || tc.equals("double"));
+    protected final boolean isLongOrDouble(TypeMirror t) {
+        TypeVisitor<Boolean,Void> v = new SimpleTypeVisitor6<Boolean,Void>() {
+            public Boolean defaultAction(TypeMirror t, Void p){
+                return false;
+            }
+            public Boolean visitArray(ArrayType t, Void p) {
+                return visit(t.getComponentType(), p);
+            }
+            public Boolean visitPrimitive(PrimitiveType t, Void p) {
+                TypeKind tk = t.getKind();
+                return (tk == TypeKind.LONG || tk == TypeKind.DOUBLE);
+            }
+        };
+        return v.visit(t, null);
     }
 
     /* Do unicode to ansi C identifier conversion.
@@ -602,3 +669,4 @@
             return false;
     }
 }
+
--- a/langtools/src/share/classes/com/sun/tools/javah/Main.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javah/Main.java	Fri Oct 16 18:02:31 2009 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2003 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2007-2008 Sun Microsystems, Inc.  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,134 +23,39 @@
  * have any questions.
  */
 
-
 package com.sun.tools.javah;
 
-
-import java.io.*;
+import java.io.PrintWriter;
 
 /**
- * Javah generates support files for native methods.
- * Parse commandline options & Invokes javadoc to execute those commands.
+ *  Main entry point.
  *
- * @author Sucheta Dambalkar
+ *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
+ *  you write code that depends on this, you do so at your own risk.
+ *  This code and its internal interfaces are subject to change or
+ *  deletion without notice.</b>
  */
-public class Main{
-    /*
-     * Parse arguments given for javah to give proper error messages.
+public class Main {
+    /**
+     * Main entry point for the launcher.
+     * Note: This method calls System.exit.
+     * @param args command line arguments
      */
-    public static void main(String[] args){
-
-        if (args.length == 0) {
-            Util.usage(1);
-        }
-        for ( int i = 0; i < args.length; i++) {
-            if (args[i].equals("-o")) {
-                i++;
-                if(i >= args.length){
-                    Util.usage(1);
-                }else if(args[i].charAt(0) == '-'){
-                    Util.error("no.outputfile.specified");
-                }else if((i+1) >= args.length){
-                    Util.error("no.classes.specified");
-                }
-            } else if (args[i].equals("-d")) {
-                i++;
-                if(i >= args.length){
-                    Util.usage(1);
-                }else if(args[i].charAt(0) == '-')  {
-                    Util.error("no.outputdir.specified");
-                }else if((i+1) >= args.length){
-                    Util.error("no.classes.specified");
-                }
-            } else if (args[i].equals("-td")) {
-                /* Ignored.  Generate tmp files to memory. */
-                i++;
-                if (i == args.length)
-                    Util.usage(1);
-            } else if (args[i].equals("-stubs")) {
-                if((i+1) >= args.length){
-                    Util.error("no.classes.specified");
-                }
-            } else if (args[i].equals("-v") || args[i].equals("-verbose")) {
-                if((i+1) >= args.length){
-                    Util.error("no.classes.specified");
-                }
-                args[i] = "-verbose";
-            } else if ((args[i].equals("-help")) || (args[i].equals("--help"))
-                       || (args[i].equals("-?")) || (args[i].equals("-h"))) {
-                Util.usage(0);
-            } else if (args[i].equals("-trace")) {
-                System.err.println(Util.getText("tracing.not.supported"));
-            } else if (args[i].equals("-version")) {
-                if((i+1) >= args.length){
-                    Util.version();
-                }
-            } else if (args[i].equals("-jni")) {
-                if((i+1) >= args.length){
-                    Util.error("no.classes.specified");
-                }
-            } else if (args[i].equals("-force")) {
-                if((i+1) >= args.length){
-                    Util.error("no.classes.specified");
-                }
-            } else if (args[i].equals("-Xnew")) {
-                // we're already using the new javah
-            } else if (args[i].equals("-old")) {
-                System.err.println(Util.getText("old.not.supported"));
-                Util.usage(1);
-            } else if (args[i].equals("-Xllni")) {
-                if((i+1) >= args.length){
-                    Util.error("no.classes.specified");
-                }
-            } else if (args[i].equals("-llni")) {
-                if((i+1) >= args.length){
-                    Util.error("no.classes.specified");
-                }
-            } else if (args[i].equals("-llniDouble")) {
-                if((i+1) >= args.length){
-                    Util.error("no.classes.specified");
-                }
-            } else if (args[i].equals("-classpath")) {
-                i++;
-                if(i >= args.length){
-                    Util.usage(1);
-                }else if(args[i].charAt(0) == '-') {
-                    Util.error("no.classpath.specified");
-                }else if((i+1) >= args.length){
-                    Util.error("no.classes.specified");
-                }
-            } else if (args[i].equals("-bootclasspath")) {
-                i++;
-                if(i >= args.length){
-                    Util.usage(1);
-                }else if(args[i].charAt(0) == '-'){
-                    Util.error("no.bootclasspath.specified");
-                }else if((i+1) >= args.length){
-                    Util.error("no.classes.specified");
-                }
-            } else if (args[i].charAt(0) == '-') {
-                Util.error("unknown.option", args[i], null, true);
-
-            } else {
-                //break; /* The rest must be classes. */
-            }
-        }
-
-        /* Invoke javadoc */
-
-        String[] javadocargs = new String[args.length + 2];
-        int i = 0;
-
-        for(; i < args.length; i++) {
-            javadocargs[i] = args[i];
-        }
-
-        javadocargs[i] = "-private";
-        i++;
-        javadocargs[i] = "-Xclasses";
-
-        int rc = com.sun.tools.javadoc.Main.execute("javadoc", "com.sun.tools.javah.MainDoclet", javadocargs);
+    public static void main(String[] args) {
+        JavahTask t = new JavahTask();
+        int rc = t.run(args);
         System.exit(rc);
     }
+
+    /**
+     * Entry point that does <i>not</i> call System.exit.
+     * @param args command line arguments
+     * @param out output stream
+     * @return an exit code. 0 means success, non-zero means an error occurred.
+     */
+    public static int run(String[] args, PrintWriter out) {
+        JavahTask t = new JavahTask();
+        t.setLog(out);
+        return t.run(args);
+    }
 }
--- a/langtools/src/share/classes/com/sun/tools/javah/MainDoclet.java	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,218 +0,0 @@
-/*
- * Copyright 2002-2003 Sun Microsystems, Inc.  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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Sun designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Sun in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- */
-
-
-package com.sun.tools.javah;
-
-import com.sun.javadoc.*;
-import java.io.*;
-
-/**
- * A doclet to parse and execute commandline options.
- *
- * @author Sucheta Dambalkar(using code from old javap)
- */
-public class MainDoclet{
-
-    public static  String  odir        = null;
-    public static  String  ofile       = null;
-    public static  boolean stubs       = false;
-    public static  boolean jni         = false;
-    public static  boolean llni        = false;
-    public static  boolean doubleAlign = false;
-    public static  boolean force       = false;
-    public static  String  genclass    = null;
-
-
-    /**
-     * Entry point.
-     */
-    public static boolean start(RootDoc root) {
-
-        int j = 0;
-        int k = 0;
-        /**
-         * Command line options.
-         */
-        String [][] cmdoptions = root.options();
-        /**
-         * Classes specified on command line.
-         */
-        ClassDoc[] classes = root.classes();
-        /**
-         * Generator used by javah.  Default is JNI.
-         */
-        Gen g = new JNI(root);
-
-        validateOptions(cmdoptions);
-
-        /*
-         * Select native interface.
-         */
-        if (jni && llni)  Util.error("jni.llni.mixed");
-
-        if (llni)
-            g = new LLNI(doubleAlign, root);
-
-        if (g instanceof JNI && stubs)  Util.error("jni.no.stubs");
-
-        /*
-         * Arrange for output destination.
-         */
-        if (odir != null && ofile != null)
-            Util.error("dir.file.mixed");
-
-        if (odir != null)
-            g.setOutDir(odir);
-
-        if (ofile != null)
-            g.setOutFile(ofile);
-
-        /*
-         * Force set to false will turn off smarts about checking file
-         * content before writing.
-         */
-        g.setForce(force);
-
-        /*
-         * Grab the rest of argv[] ... this must be the classes.
-         */
-        if (classes.length == 0){
-            Util.error("no.classes.specified");
-        }
-        /*
-         * Set classes.
-         */
-        g.setClasses(classes);
-
-        try {
-            g.run();
-        } catch (ClassNotFoundException cnfe) {
-            Util.error("class.not.found", cnfe.getMessage());
-        } catch (IOException ioe) {
-            Util.error("io.exception", ioe.getMessage());
-        }
-
-        return true;
-    }
-
-    /**
-     * Required doclet method.
-     */
-    public static int optionLength(String option) {
-        if (option.equals("-o")) {
-            return 2;
-        } else if(option.equals("-d")){
-            return 2;
-        } else if (option.equals("-td")) {
-            return 1;
-        } else if (option.equals("-stubs")) {
-            return 1;
-        } else if(option.equals("-help")){
-            return 1;
-        } else if(option.equals("--help")){
-            return 1;
-        } else if(option.equals("-?")){
-            return 1;
-        } else if(option.equals("-h")){
-            return 1;
-        } else if(option.equals("-trace")){
-            return 1;
-        } else if(option.equals("-version")) {
-            return 1;
-        } else if(option.equals("-jni")){
-            return 1;
-        } else if(option.equals("-force")){
-            return 1;
-        } else if(option.equals("-Xllni")){
-            return 1;
-        } else if(option.equals("-llni")){
-            return 1;
-        } else if(option.equals("-llniDouble")){
-            return 1;
-        } else return 0;
-    }
-
-    /**
-     * Parse the command line options.
-     */
-    public static void validateOptions(String cmdoptions[][]) {
-        /* Default values for options, overridden by user options. */
-        String bootcp = System.getProperty("sun.boot.class.path");
-        String  usercp = System.getProperty("env.class.path");
-
-        for(int p = 0; p < cmdoptions.length; p++){
-
-            if (cmdoptions[p][0].equals("-o")) {
-                ofile = cmdoptions[p][1];
-            } else if(cmdoptions[p][0].equals("-d")){
-                odir = cmdoptions[p][1];
-            } else if (cmdoptions[p][0].equals("-td")) {
-                if (p ==cmdoptions.length)
-                    Util.usage(1);
-            } else if (cmdoptions[p][0].equals("-stubs")) {
-                stubs = true;
-            } else if (cmdoptions[p][0].equals("-verbose")) {
-                Util.verbose = true;
-            } else if((cmdoptions[p][0].equals("-help"))
-                      || (cmdoptions[p][0].equals("--help"))
-                      || (cmdoptions[p][0].equals("-?"))
-                      || (cmdoptions[p][0].equals("-h"))) {
-                Util.usage(0);
-            } else if (cmdoptions[p][0].equals("-trace")) {
-                System.err.println(Util.getText("tracing.not.supported"));
-            } else if (cmdoptions[p][0].equals("-version")) {
-                Util.version();
-            } else if (cmdoptions[p][0].equals("-jni")) {
-                jni = true;
-            } else if (cmdoptions[p][0].equals("-force")) {
-                force = true;
-            } else if (cmdoptions[p][0].equals("-Xllni")) {
-                llni = true;
-            } else if (cmdoptions[p][0].equals("-llni")) {
-                llni = true;
-            } else if (cmdoptions[p][0].equals("-llniDouble")) {
-                llni = true; doubleAlign = true;
-            } else if (cmdoptions[p][0].equals("-classpath")) {
-                usercp = cmdoptions[p][1];
-            } else if (cmdoptions[p][0].equals("-bootclasspath")) {
-                bootcp = cmdoptions[p][1];
-            } else if((cmdoptions[p][0].charAt(0) == '-')
-                      && (!cmdoptions[p][0].equals("-private"))){
-                Util.error("unknown.option", cmdoptions[p][0], null, true);
-            } else {
-                break; /* The rest must be classes. */
-            }
-        }
-
-
-        if (Util.verbose) {
-                System.err.println("[ Search Path: "
-                                    + bootcp
-                                    + System.getProperty("file.separator")
-                                    + usercp + " ]");
-        }
-    }
-}
--- a/langtools/src/share/classes/com/sun/tools/javah/Mangle.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javah/Mangle.java	Fri Oct 16 18:02:31 2009 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2002-2008 Sun Microsystems, Inc.  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,22 +26,30 @@
 
 package com.sun.tools.javah;
 
-import com.sun.javadoc.*;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
+import javax.lang.model.util.Elements;
+import javax.lang.model.util.Types;
 
 /**
  * A utility for mangling java identifiers into C names.  Should make
  * this more fine grained and distribute the functionality to the
  * generators.
  *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems.
+ * If you write code that depends on this, you do so at your own
+ * risk.  This code and its internal interfaces are subject to change
+ * or deletion without notice.</b></p>
+ *
  * @author  Sucheta Dambalkar(Revised)
  */
-class Mangle {
+public class Mangle {
 
     public static class Type {
-
         public static final int CLASS            = 1;
         public static final int FIELDSTUB        = 2;
-        public static final int FIELD        = 3;
+        public static final int FIELD            = 3;
         public static final int JNI              = 4;
         public static final int SIGNATURE        = 5;
         public static final int METHOD_JDK_1     = 6;
@@ -49,8 +57,15 @@
         public static final int METHOD_JNI_LONG  = 8;
     };
 
+    private Elements elems;
+    private Types types;
 
-    public static final String mangle(String name, int mtype) {
+    Mangle(Elements elems, Types types) {
+        this.elems = elems;
+        this.types = types;
+    }
+
+    public final String mangle(CharSequence name, int mtype) {
         StringBuffer result = new StringBuffer(100);
         int length = name.length();
 
@@ -98,15 +113,15 @@
         return result.toString();
     }
 
-    public static String mangleMethod(MethodDoc method, RootDoc root, ClassDoc clazz,
+    public String mangleMethod(ExecutableElement method, TypeElement clazz,
                                       int mtype) {
         StringBuffer result = new StringBuffer(100);
         result.append("Java_");
 
         if (mtype == Mangle.Type.METHOD_JDK_1) {
-            result.append(mangle(clazz.qualifiedName(), Mangle.Type.CLASS));
+            result.append(mangle(clazz.getQualifiedName(), Mangle.Type.CLASS));
             result.append('_');
-            result.append(mangle(method.name(),
+            result.append(mangle(method.getSimpleName(),
                                  Mangle.Type.FIELD));
             result.append("_stub");
             return result.toString();
@@ -115,13 +130,13 @@
         /* JNI */
         result.append(mangle(getInnerQualifiedName(clazz), Mangle.Type.JNI));
         result.append('_');
-        result.append(mangle(method.name(),
+        result.append(mangle(method.getSimpleName(),
                              Mangle.Type.JNI));
         if (mtype == Mangle.Type.METHOD_JNI_LONG) {
             result.append("__");
-            String typesig = method.signature();
-            TypeSignature newTypeSig = new TypeSignature(root);
-            String sig = newTypeSig.getTypeSignature(typesig,  method.returnType());
+            String typesig = signature(method);
+            TypeSignature newTypeSig = new TypeSignature(elems);
+            String sig = newTypeSig.getTypeSignature(typesig,  method.getReturnType());
             sig = sig.substring(1);
             sig = sig.substring(0, sig.lastIndexOf(')'));
             sig = sig.replace('/', '.');
@@ -131,15 +146,11 @@
         return result.toString();
     }
     //where
-        private static String getInnerQualifiedName(ClassDoc clazz) {
-            ClassDoc encl = clazz.containingClass();
-            if (encl == null)
-                return clazz.qualifiedName();
-            else
-                return getInnerQualifiedName(encl) + '$' + clazz.simpleTypeName();
+        private String getInnerQualifiedName(TypeElement clazz) {
+            return elems.getBinaryName(clazz).toString();
         }
 
-    public static final String mangleChar(char ch) {
+    public final String mangleChar(char ch) {
         String s = Integer.toHexString(ch);
         int nzeros = 5 - s.length();
         char[] result = new char[6];
@@ -151,6 +162,19 @@
         return new String(result);
     }
 
+    // Warning: duplicated in Gen
+    private String signature(ExecutableElement e) {
+        StringBuffer sb = new StringBuffer();
+        String sep = "(";
+        for (VariableElement p: e.getParameters()) {
+            sb.append(sep);
+            sb.append(types.erasure(p.asType()).toString());
+            sep = ",";
+        }
+        sb.append(")");
+        return sb.toString();
+    }
+
     /* Warning: Intentional ASCII operation. */
     private static final boolean isalnum(char ch) {
         return ch <= 0x7f && /* quick test */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javah/NativeHeaderTool.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2005-2006 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.javah; //javax.tools;
+
+import java.io.Writer;
+import java.nio.charset.Charset;
+import java.util.Locale;
+import java.util.concurrent.Callable;
+import javax.tools.DiagnosticListener;
+import javax.tools.JavaFileManager;
+import javax.tools.JavaFileObject;
+import javax.tools.OptionChecker;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.Tool;
+
+/**
+ * This class is intended to be put in javax.tools.
+ *
+ * @see DiagnosticListener
+ * @see Diagnostic
+ * @see JavaFileManager
+ * @since 1.7
+ *
+ *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
+ *  you write code that depends on this, you do so at your own risk.
+ *  This code and its internal interfaces are subject to change or
+ *  deletion without notice.</b>
+ */
+public interface NativeHeaderTool extends Tool, OptionChecker {
+
+    /**
+     * Creates a future for a native header task with the given
+     * components and arguments.  The task might not have
+     * completed as described in the NativeHeaderTask interface.
+     *
+     * <p>If a file manager is provided, it must be able to handle all
+     * locations defined in {@link StandardLocation}.
+     *
+     * @param out a Writer for additional output from the task;
+     * use {@code System.err} if {@code null}
+     * @param fileManager a file manager; if {@code null} use the
+     * task's standard filemanager
+     * @param diagnosticListener a diagnostic listener; if {@code
+     * null} use the compiler's default method for reporting
+     * diagnostics
+     * @param options task options, {@code null} means no options
+     * @param classes class names for which native headers should be generated
+     * @return an object representing the task to be done
+     * @throws RuntimeException if an unrecoverable error
+     * occurred in a user supplied component.  The
+     * {@linkplain Throwable#getCause() cause} will be the error in
+     * user code.
+     * @throws IllegalArgumentException if any of the given
+     * compilation units are of other kind than
+     * {@linkplain JavaFileObject.Kind#SOURCE source}
+     */
+    NativeHeaderTask getTask(Writer out,
+                            JavaFileManager fileManager,
+                            DiagnosticListener<? super JavaFileObject> diagnosticListener,
+                            Iterable<String> options,
+                            Iterable<String> classes);
+
+    /**
+     * Gets a new instance of the standard file manager implementation
+     * for this tool.  The file manager will use the given diagnostic
+     * listener for producing any non-fatal diagnostics.  Fatal errors
+     * will be signalled with the appropriate exceptions.
+     *
+     * <p>The standard file manager will be automatically reopened if
+     * it is accessed after calls to {@code flush} or {@code close}.
+     * The standard file manager must be usable with other tools.
+     *
+     * @param diagnosticListener a diagnostic listener for non-fatal
+     * diagnostics; if {@code null} use the tool's default method
+     * for reporting diagnostics
+     * @param locale the locale to apply when formatting diagnostics;
+     * {@code null} means the {@linkplain Locale#getDefault() default locale}.
+     * @param charset the character set used for decoding bytes; if
+     * {@code null} use the platform default
+     * @return the standard file manager
+     */
+    StandardJavaFileManager getStandardFileManager(
+        DiagnosticListener<? super JavaFileObject> diagnosticListener,
+        Locale locale,
+        Charset charset);
+
+    /**
+     * Interface representing a future for a native header task.  The
+     * task has not yet started.  To start the task, call
+     * the {@linkplain #call call} method.
+     *
+     * <p>Before calling the call method, additional aspects of the
+     * task can be configured, for example, by calling the
+     * {@linkplain #setLocale setLocale} method.
+     */
+    interface NativeHeaderTask extends Callable<Boolean> {
+
+        /**
+         * Set the locale to be applied when formatting diagnostics and
+         * other localized data.
+         *
+         * @param locale the locale to apply; {@code null} means apply no
+         * locale
+         * @throws IllegalStateException if the task has started
+         */
+        void setLocale(Locale locale);
+
+        /**
+         * Performs this native header task.  The task may only
+         * be performed once.  Subsequent calls to this method throw
+         * IllegalStateException.
+         *
+         * @return true if and only all the files were processed without errors;
+         * false otherwise
+         *
+         * @throws RuntimeException if an unrecoverable error occurred
+         * in a user-supplied component.  The
+         * {@linkplain Throwable#getCause() cause} will be the error
+         * in user code.
+         * @throws IllegalStateException if called more than once
+         */
+        Boolean call();
+    }
+}
--- a/langtools/src/share/classes/com/sun/tools/javah/TypeSignature.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javah/TypeSignature.java	Fri Oct 16 18:02:31 2009 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2003 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2002-2008 Sun Microsystems, Inc.  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,19 +26,34 @@
 
 package com.sun.tools.javah;
 
-import com.sun.javadoc.*;
-import java.io.*;
 import java.util.*;
+import javax.lang.model.element.Name;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.type.ArrayType;
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.type.NoType;
+import javax.lang.model.type.PrimitiveType;
+import javax.lang.model.type.TypeKind;
+import javax.lang.model.type.TypeMirror;
+import javax.lang.model.type.TypeVariable;
+import javax.lang.model.type.TypeVisitor;
+import javax.lang.model.util.Elements;
+import javax.lang.model.util.SimpleTypeVisitor6;
 
 /**
  * Returns internal type signature.
  *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems.
+ * If you write code that depends on this, you do so at your own
+ * risk.  This code and its internal interfaces are subject to change
+ * or deletion without notice.</b></p>
+ *
  * @author Sucheta Dambalkar
  */
 
 public class TypeSignature{
 
-    RootDoc root  = null;
+    Elements elems;
 
     /* Signature Characters */
 
@@ -56,8 +71,8 @@
 
 
 
-    public TypeSignature(RootDoc root){
-        this.root = root;
+    public TypeSignature(Elements elems){
+        this.elems = elems;
     }
 
     /*
@@ -70,16 +85,15 @@
     /*
      * Returns the type signature of a method according to JVM specs
      */
-    public String getTypeSignature(String javasignature, Type returnType){
-
+    public String getTypeSignature(String javasignature, TypeMirror returnType){
         String signature = null; //Java type signature.
         String typeSignature = null; //Internal type signature.
-        Vector<Object> params = new Vector<Object>(); //List of parameters.
+        List<String> params = new ArrayList<String>(); //List of parameters.
         String paramsig = null; //Java parameter signature.
         String paramJVMSig = null; //Internal parameter signature.
         String returnSig = null; //Java return type signature.
         String returnJVMType = null; //Internal return type signature.
-        String dimension = null; //Array dimension.
+        int dimensions = 0; //Array dimension.
 
         int startIndex = -1;
         int endIndex = -1;
@@ -87,28 +101,27 @@
         int i = 0;
 
         // Gets the actual java signature without parentheses.
-        if(javasignature != null){
+        if (javasignature != null) {
             startIndex = javasignature.indexOf("(");
             endIndex = javasignature.indexOf(")");
         }
 
-        if(((startIndex != -1) && (endIndex != -1))
-           &&(startIndex+1 < javasignature.length())
-           &&(endIndex < javasignature.length())) {
-
+        if (((startIndex != -1) && (endIndex != -1))
+            &&(startIndex+1 < javasignature.length())
+            &&(endIndex < javasignature.length())) {
             signature = javasignature.substring(startIndex+1, endIndex);
         }
 
         // Separates parameters.
-        if(signature != null){
-            if(signature.indexOf(",") != -1){
+        if (signature != null) {
+            if (signature.indexOf(",") != -1) {
                 st = new StringTokenizer(signature, ",");
-                if(st != null){
+                if (st != null) {
                     while (st.hasMoreTokens()) {
                         params.add(st.nextToken());
                     }
                 }
-            }else {
+            } else {
                 params.add(signature);
             }
         }
@@ -117,10 +130,10 @@
         typeSignature = "(";
 
         // Gets indivisual internal parameter signature.
-        while(params.isEmpty() != true){
-            paramsig =((String)params.remove(i)).trim();
+        while (params.isEmpty() != true) {
+            paramsig = params.remove(i).trim();
             paramJVMSig  = getParamJVMSignature(paramsig);
-            if(paramJVMSig != null){
+            if (paramJVMSig != null) {
                 typeSignature += paramJVMSig;
             }
         }
@@ -130,36 +143,30 @@
         // Get internal return type signature.
 
         returnJVMType = "";
-        if(returnType != null){
-            dimension = returnType.dimension();
+        if (returnType != null) {
+            dimensions = dimensions(returnType);
         }
 
-        if(dimension != null){
-
-            //Gets array dimension of return type.
-            while(dimension.indexOf("[]") != -1){
-                returnJVMType += "[";
-                int stindex = dimension.indexOf("]") + 1;
-                if(stindex <= dimension.length()){
-                    dimension = dimension.substring(stindex);
-                }else dimension = "";
-            }
+        //Gets array dimension of return type.
+        while (dimensions-- > 0) {
+            returnJVMType += "[";
         }
-        if(returnType != null){
-            returnSig = returnType.qualifiedTypeName();
+        if (returnType != null) {
+            returnSig = qualifiedTypeName(returnType);
             returnJVMType += getComponentType(returnSig);
-        }else {
+        } else {
             System.out.println("Invalid return type.");
         }
 
         typeSignature += returnJVMType;
+
         return typeSignature;
     }
 
     /*
      * Returns internal signature of a parameter.
      */
-    private String getParamJVMSignature(String paramsig){
+    private String getParamJVMSignature(String paramsig) {
         String paramJVMSig = "";
         String componentType ="";
 
@@ -206,12 +213,13 @@
             else if(componentType.equals("double"))  JVMSig += SIG_DOUBLE ;
             else {
                 if(!componentType.equals("")){
-                    ClassDoc classNameDoc = root.classNamed(componentType);
+                    TypeElement classNameDoc = elems.getTypeElement(componentType);
 
                     if(classNameDoc == null){
-                        System.out.println("Invalid class type");
+                        System.out.println("Invalid class type for " + componentType);
+                        new Exception().printStackTrace();
                     }else {
-                        String classname = classNameDoc.qualifiedName();
+                        String classname = classNameDoc.getQualifiedName().toString();
                         String newclassname = classname.replace('.', '/');
                         JVMSig += "L";
                         JVMSig += newclassname;
@@ -222,4 +230,43 @@
         }
         return JVMSig;
     }
+
+    int dimensions(TypeMirror t) {
+        if (t.getKind() != TypeKind.ARRAY)
+            return 0;
+        return 1 + dimensions(((ArrayType) t).getComponentType());
+    }
+
+
+    String qualifiedTypeName(TypeMirror type) {
+        TypeVisitor<Name, Void> v = new SimpleTypeVisitor6<Name, Void>() {
+            @Override
+            public Name visitArray(ArrayType t, Void p) {
+                return t.getComponentType().accept(this, p);
+            }
+
+            @Override
+            public Name visitDeclared(DeclaredType t, Void p) {
+                return ((TypeElement) t.asElement()).getQualifiedName();
+            }
+
+            @Override
+            public Name visitPrimitive(PrimitiveType t, Void p) {
+                return elems.getName(t.toString());
+            }
+
+            @Override
+            public Name visitNoType(NoType t, Void p) {
+                if (t.getKind() == TypeKind.VOID)
+                    return elems.getName("void");
+                return defaultAction(t, p);
+            }
+
+            @Override
+            public Name visitTypeVariable(TypeVariable t, Void p) {
+                return t.getUpperBound().accept(this, p);
+            }
+        };
+        return v.visit(type).toString();
+    }
 }
--- a/langtools/src/share/classes/com/sun/tools/javah/Util.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javah/Util.java	Fri Oct 16 18:02:31 2009 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2004 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2002-2008 Sun Microsystems, Inc.  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,12 +26,15 @@
 
 package com.sun.tools.javah;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
+import java.io.PrintWriter;
+import java.text.MessageFormat;
+import java.util.Locale;
 import java.util.ResourceBundle;
-import java.text.MessageFormat;
 import java.util.MissingResourceException;
+import javax.tools.Diagnostic;
+import javax.tools.Diagnostic.Kind;
+import javax.tools.DiagnosticListener;
+import javax.tools.JavaFileObject;
 
 /**
  * Messages, verbose and error handling support.
@@ -41,42 +44,70 @@
  *      bug   -- Bug has occurred in javah
  *      fatal -- We can't even find resources, so bail fast, don't localize
  *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems.
+ * If you write code that depends on this, you do so at your own
+ * risk.  This code and its internal interfaces are subject to change
+ * or deletion without notice.</b></p>
  */
 public class Util {
+    /** Exit is used to replace the use of System.exit in the original javah.
+     */
+    public static class Exit extends Error {
+        private static final long serialVersionUID = 430820978114067221L;
+        Exit(int exitValue) {
+            this(exitValue, null);
+        }
+
+        Exit(int exitValue, Throwable cause) {
+            super(cause);
+            this.exitValue = exitValue;
+            this.cause = cause;
+        }
+
+        Exit(Exit e) {
+            this(e.exitValue, e.cause);
+        }
+
+        public final int exitValue;
+        public final Throwable cause;
+    }
 
     /*
      * Help for verbosity.
      */
-    public static boolean verbose = false;
+    public boolean verbose = false;
+
+    public PrintWriter log;
+    public DiagnosticListener<? super JavaFileObject> dl;
 
-    public static void log(String s) {
-        System.out.println(s);
+    Util(PrintWriter log, DiagnosticListener<? super JavaFileObject> dl) {
+        this.log = log;
+        this.dl = dl;
+    }
+
+    public void log(String s) {
+        log.println(s);
     }
 
 
     /*
      * Help for loading localized messages.
      */
-    private static ResourceBundle m;
+    private ResourceBundle m;
 
-    private static void initMessages() {
+    private void initMessages() throws Exit {
         try {
-            m=ResourceBundle.getBundle("com.sun.tools.javah.resources.l10n");
+            m = ResourceBundle.getBundle("com.sun.tools.javah.resources.l10n");
         } catch (MissingResourceException mre) {
             fatal("Error loading resources.  Please file a bug report.", mre);
         }
     }
 
-    public static String getText(String key) {
-        return getText(key, null, null);
-    }
-
-    private static String getText(String key, String a1, String a2){
+    private String getText(String key, Object... args) throws Exit {
         if (m == null)
             initMessages();
         try {
-            return MessageFormat.format(m.getString(key),
-                                        new Object[] { a1, a2 });
+            return MessageFormat.format(m.getString(key), args);
         } catch (MissingResourceException e) {
             fatal("Key " + key + " not found in resources.", e);
         }
@@ -86,107 +117,74 @@
     /*
      * Usage message.
      */
-    public static void usage(int exitValue) {
-        if (exitValue == 0) {
-            System.out.println(getText("usage"));
-        } else {
-            System.err.println(getText("usage"));
-        }
-        System.exit(exitValue);
+    public void usage() throws Exit {
+        log.println(getText("usage"));
     }
 
-    public static void version() {
-        System.out.println(getText("javah.version",
+    public void version() throws Exit {
+        log.println(getText("javah.version",
                                    System.getProperty("java.version"), null));
-        System.exit(0);
     }
 
     /*
      * Failure modes.
      */
-    public static void bug(String key) {
+    public void bug(String key) throws Exit {
         bug(key, null);
     }
 
-    public static void bug(String key, Exception e) {
-        if (e != null)
-            e.printStackTrace();
-        System.err.println(getText(key));
-        System.err.println(getText("bug.report"));
-        System.exit(11);
-    }
-
-    public static void error(String key) {
-        error(key, null);
+    public void bug(String key, Exception e) throws Exit {
+        dl.report(createDiagnostic(Diagnostic.Kind.ERROR, key));
+        dl.report(createDiagnostic(Diagnostic.Kind.NOTE, "bug.report"));
+        throw new Exit(11, e);
     }
 
-    public static void error(String key, String a1) {
-        error(key, a1, null);
-    }
-
-    public static void error(String key, String a1, String a2) {
-        error(key, a1, a2, false);
+    public void error(String key, Object... args) throws Exit {
+        dl.report(createDiagnostic(Diagnostic.Kind.ERROR, key, args));
+        throw new Exit(15);
     }
 
-    public static void error(String key, String a1, String a2,
-                             boolean showUsage) {
-        System.err.println("Error: " + getText(key, a1, a2));
-        if (showUsage)
-            usage(15);
-        System.exit(15);
-    }
-
-
-    private static void fatal(String msg) {
+    private void fatal(String msg) throws Exit {
         fatal(msg, null);
     }
 
-    private static void fatal(String msg, Exception e) {
-        if (e != null) {
-            e.printStackTrace();
-        }
-        System.err.println(msg);
-        System.exit(10);
+    private void fatal(String msg, Exception e) throws Exit {
+        dl.report(createDiagnostic(Diagnostic.Kind.ERROR, "", msg));
+        throw new Exit(10, e);
     }
 
-    /*
-     * Support for platform specific things in javah, such as pragma
-     * directives, exported symbols etc.
-     */
-    static private ResourceBundle platform = null;
-
-    /*
-     * Set when platform has been initialized.
-     */
-    static private boolean platformInit = false;
-
-    static String getPlatformString(String key) {
-        if (!platformInit) {
-            initPlatform();
-            platformInit = true;
-        }
-        if (platform == null)
-            return null;
-        try {
-            return platform.getString(key);
-        } catch (MissingResourceException mre) {
-            return null;
-        }
-    }
-
-    private static void initPlatform() {
-        String os = System.getProperty("os.name");
-        if (os.startsWith("Windows")) {
-            os = "win32";
-        } else if (os.indexOf("Linux") >= 0) {
-            os = "Linux";
-        }
-        String arch = System.getProperty("os.arch");
-        String resname = "com.sun.tools.javah.resources." + os + "_" + arch;
-        try {
-            platform=ResourceBundle.getBundle(resname);
-        } catch (MissingResourceException mre) {
-            // fatal("Error loading resources.  Please file a bug report.", mre);
-        }
+    private Diagnostic<JavaFileObject> createDiagnostic(
+            final Diagnostic.Kind kind, final String code, final Object... args) {
+        return new Diagnostic<JavaFileObject>() {
+            public String getCode() {
+                return code;
+            }
+            public long getColumnNumber() {
+                return Diagnostic.NOPOS;
+            }
+            public long getEndPosition() {
+                return Diagnostic.NOPOS;
+            }
+            public Kind getKind() {
+                return kind;
+            }
+            public long getLineNumber() {
+                return Diagnostic.NOPOS;
+            }
+            public String getMessage(Locale locale) {
+                if (code.length() == 0)
+                    return (String) args[0];
+                return getText(code, args); // FIXME locale
+            }
+            public long getPosition() {
+                return Diagnostic.NOPOS;
+            }
+            public JavaFileObject getSource() {
+                return null;
+            }
+            public long getStartPosition() {
+                return Diagnostic.NOPOS;
+            }
+        };
     }
 }
--- a/langtools/src/share/classes/com/sun/tools/javah/resources/Linux_ppc.properties	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-#
-# Copyright 2000 Sun Microsystems, Inc.  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
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.  Sun designates this
-# particular file as subject to the "Classpath" exception as provided
-# by Sun in the LICENSE file that accompanied this code.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
-# CA 95054 USA or visit www.sun.com if you need additional information or
-# have any questions.
-# 
-
-pack.pragma.start=\#pragma pack(4)\n
-pack.pragma.end=\#pragma pack()\n
--- a/langtools/src/share/classes/com/sun/tools/javah/resources/Linux_sparc.properties	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-#
-# Copyright 2000 Sun Microsystems, Inc.  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
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.  Sun designates this
-# particular file as subject to the "Classpath" exception as provided
-# by Sun in the LICENSE file that accompanied this code.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
-# CA 95054 USA or visit www.sun.com if you need additional information or
-# have any questions.
-# 
-
-pack.pragma.start=\#pragma pack(4)\n
-pack.pragma.end=\#pragma pack()\n
--- a/langtools/src/share/classes/com/sun/tools/javah/resources/SunOS_sparc.properties	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-#
-# Copyright 1998 Sun Microsystems, Inc.  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
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.  Sun designates this
-# particular file as subject to the "Classpath" exception as provided
-# by Sun in the LICENSE file that accompanied this code.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
-# CA 95054 USA or visit www.sun.com if you need additional information or
-# have any questions.
-# 
-
-pack.pragma.start=\#pragma pack(4)\n
-pack.pragma.end=\#pragma pack()\n
--- a/langtools/src/share/classes/com/sun/tools/javah/resources/SunOS_sparcv9.properties	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-#
-# Copyright 2001 Sun Microsystems, Inc.  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
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.  Sun designates this
-# particular file as subject to the "Classpath" exception as provided
-# by Sun in the LICENSE file that accompanied this code.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
-# CA 95054 USA or visit www.sun.com if you need additional information or
-# have any questions.
-# 
-
-pack.pragma.start=\#pragma pack(4)\n
-pack.pragma.end=\#pragma pack()\n
--- a/langtools/src/share/classes/com/sun/tools/javah/resources/l10n.properties	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javah/resources/l10n.properties	Fri Oct 16 18:02:31 2009 -0700
@@ -21,47 +21,47 @@
 # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 # CA 95054 USA or visit www.sun.com if you need additional information or
 # have any questions.
-# 
+#
 
 #
 # User errors, command line errors.
 #
 cant.create.dir=\
-	The directory {0} could not be create for output.
+        The directory {0} could not be create for output.
 at.args.cant.read=\
-	Can''t read command line arguments from file {1}.
+        Can''t read command line arguments from file {1}.
 at.args.io.exception=\
-	The following I/O problem was encountered when processing an @ \
+        The following I/O problem was encountered when processing an @ \
         argument on the command line: {0}.
 old.jni.mixed=\
-	Can''t mix options -jni and -old.  Try -help.
+        Can''t mix options -jni and -old.  Try -help.
 old.llni.mixed=\
-	Can''t mix options -old and -llni.  Try -help.
+        Can''t mix options -old and -llni.  Try -help.
 old.not.supported=\
-	Option -old not supported by this version of javah.
+        Option -old not supported by this version of javah.
 invalid.method.signature=\
-	Invalid method signature: {0}
+        Invalid method signature: {0}
 jni.llni.mixed=\
-	Can''t mix options -jni and -llni.  Try -help.
+        Can''t mix options -jni and -llni.  Try -help.
 jni.no.stubs=\
-	JNI does not require stubs, please refer to the JNI documentation.
+        JNI does not require stubs, please refer to the JNI documentation.
 dir.file.mixed=\
-	Can''t mix options -d and -o.  Try -help.
+        Can''t mix options -d and -o.  Try -help.
 no.classes.specified=\
-	No classes were specified on the command line.  Try -help.
+        No classes were specified on the command line.  Try -help.
 no.outputfile.specified=\
-	No outputfile was specified on the command line.  Try -help.
+        No outputfile was specified on the command line.  Try -help.
 no.outputdir.specified=\
-	No output directory was specified on the command line.  Try -help.
+        No output directory was specified on the command line.  Try -help.
 no.classpath.specified=\
-	No classpath was specified on the command line.  Try -help.
+        No classpath was specified on the command line.  Try -help.
 no.bootclasspath.specified=\
-	No bootclasspath was specified on the command line.  Try -help.
+        No bootclasspath was specified on the command line.  Try -help.
 unknown.option=\
-	{0} is an illegal argument\n
+        {0} is an illegal argument\n
 tracing.not.supported=\
-	Warning: Tracing is no longer supported.  Instead, use\
-	-verbose:jni option of the virtual machine.
+        Warning: Tracing is no longer supported.  Instead, use\
+        -verbose:jni option of the virtual machine.
 
 #
 # Usage message.
@@ -79,11 +79,37 @@
 -jni                  Generate JNI-style header file (default)\n\t\
 -version              Print version information\n\t\
 -verbose              Enable verbose output\n\t\
--force		      Always write output files\n\
+-force                Always write output files\n\
 \n\
 <classes> are specified with their fully qualified names (for\n\
 instance, java.lang.Object).\n
 
+main.usage=\
+Usage: \n\
+\  javah [options] <classes>\n\
+where [options] include:
+main.opt.o=\
+\  -o <file>                Output file (only one of -d or -o may be used)
+main.opt.d=\
+\  -d <dir>                 Output directory
+main.opt.v=\
+\  -v  -verbose             Enable verbose output
+main.opt.help=\
+\  -h  --help  -?           Print this message
+main.opt.version=\
+\  -version                 Print version information
+main.opt.jni=\
+\  -jni                     Generate JNI-style header file (default)
+main.opt.force=\
+\  -force                   Always write output files
+main.opt.classpath=\
+\  -classpath <path>        Path from which to load classes
+main.opt.bootclasspath=\
+\  -bootclasspath <path>    Path from which to load bootstrap classes
+main.usage.foot=\
+<classes> are specified with their fully qualified names\n\
+(for example, java.lang.Object).
+
 #
 # Version string.
 #
@@ -93,26 +119,35 @@
 # These should have better diagnostics.
 #
 super.class.not.found=\
-	A required super class {0} could not be found.
+        A required super class {0} could not be found.
 class.not.found=\
-	Class {0} could not be found.
+        Class {0} could not be found.
 io.exception=\
-	Can''t recover from an I/O error with the following message: \
-	{0}.
+        Can''t recover from an I/O error with the following message: \
+        {0}.
 
 #
 # Problems in the guts of javah.
 #
 encoding.iso8859_1.not.found=\
-	ISO8859_1 converter was not found for output.  This is \
+        ISO8859_1 converter was not found for output.  This is \
         probably due to an error in the installation installation.
 tried.to.define.non.static=\
-	Tried to generate #define for non-static field.
+        Tried to generate #define for non-static field.
 jni.unknown.type=\
-	An unknown type encountered (JNI).
+        An unknown type encountered (JNI).
 unknown.array.type=\
-	An unknown array type encountered when generating old style headers.
+        An unknown array type encountered when generating old style headers.
 unknown.type.for.field=\
-	An unknown type encountered when generating old style headers.
+        An unknown type encountered when generating old style headers.
 unknown.type.in.method.signature=\
-	An unknown type eccountered when generating old style stubs.
+        An unknown type eccountered when generating old style stubs.
+
+
+err.prefix=Error:
+err.cant.use.option.for.fm=Can't use {0} option with given file manager
+err.internal.error=Internal error: {0}
+err.ioerror=IO error: {0}
+err.missing.arg=value missing for {0}
+err.no.classes.specified=no classes specified
+err.unknown.option=unknown option: {0}
--- a/langtools/src/share/classes/com/sun/tools/javah/resources/win32_x86.properties	Fri Oct 16 09:32:29 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-#
-# Copyright 1998 Sun Microsystems, Inc.  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
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.  Sun designates this
-# particular file as subject to the "Classpath" exception as provided
-# by Sun in the LICENSE file that accompanied this code.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
-# CA 95054 USA or visit www.sun.com if you need additional information or
-# have any questions.
-# 
-
-dll.export=__declspec(dllexport)
-pack.pragma.start=\#pragma pack(4)\n
-pack.pragma.end=\#pragma pack()\n
--- a/langtools/src/share/classes/com/sun/tools/javap/DisassemblerTool.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javap/DisassemblerTool.java	Fri Oct 16 18:02:31 2009 -0700
@@ -42,7 +42,7 @@
  * @see DiagnosticListener
  * @see Diagnostic
  * @see JavaFileManager
- * @since 1.6
+ * @since 1.7
  *
  *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
  *  you write code that depends on this, you do so at your own risk.
--- a/langtools/src/share/classes/javax/tools/SimpleJavaFileObject.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/src/share/classes/javax/tools/SimpleJavaFileObject.java	Fri Oct 16 18:02:31 2009 -0700
@@ -27,7 +27,6 @@
 
 import java.io.*;
 import java.net.URI;
-import java.net.URISyntaxException;
 import java.nio.CharBuffer;
 import javax.lang.model.element.Modifier;
 import javax.lang.model.element.NestingKind;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/4241573/T4241573.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,225 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4241573
+ * @summary SourceFile attribute includes full path
+ */
+
+import com.sun.tools.classfile.Attribute;
+import com.sun.tools.classfile.ClassFile;
+import com.sun.tools.classfile.SourceFile_attribute;
+import java.io.*;
+import java.util.*;
+import java.util.jar.*;
+
+public class T4241573 {
+    public static void main(String... args) throws Exception {
+        new T4241573().run();
+    }
+
+    public void run() throws Exception {
+        // Selection of files to be compiled
+        File absJar = createJar(new File("abs.jar").getAbsoluteFile(), "j.A");
+        File relJar = createJar(new File("rel.jar"), "j.R");
+        File absDir = createDir(new File("abs.dir").getAbsoluteFile(), "d.A");
+        File relDir = createDir(new File("rel.dir"), "d.R");
+        File absTestFile = writeFile(new File("AbsTest.java").getAbsoluteFile(), "class AbsTest { class Inner { } }");
+        File relTestFile = writeFile(new File("RelTest.java"), "class RelTest { class Inner { } }");
+        File relTest2File = writeFile(new File("p/RelTest2.java"), "package p; class RelTest2 { class Inner { } }");
+        // This next class references other classes that will be found on the source path
+        // and which will therefore need to be compiled as well.
+        File mainFile = writeFile(new File("Main.java"),
+                "class Main { j.A ja; j.R jr; d.A da; d.R dr; }" +
+                "");
+
+        String sourcePath = createPath(absJar, relJar, absDir, relDir);
+        File outDir = new File("classes");
+        outDir.mkdirs();
+
+        String[] args = {
+            "-sourcepath", sourcePath,
+            "-d", outDir.getPath(),
+            absTestFile.getPath(),
+            relTestFile.getPath(),
+            relTest2File.getPath(),
+            mainFile.getPath(),
+        };
+        System.err.println("compile: " + Arrays.asList(args));
+        StringWriter sw = new StringWriter();
+        PrintWriter pw = new PrintWriter(sw);
+        int rc = com.sun.tools.javac.Main.compile(args, pw);
+        pw.close();
+        if (rc != 0) {
+            System.err.println(sw.toString());
+            throw new Exception("unexpected exit from javac: " + rc);
+        }
+
+        Set<File> expect = getFiles(outDir,
+            "d/A.class",        "d/A$Inner.class",
+            "d/R.class",        "d/R$Inner.class",
+            "j/A.class",        "j/A$Inner.class",
+            "j/R.class",        "j/R$Inner.class",
+            "AbsTest.class",    "AbsTest$Inner.class",
+            "RelTest.class",    "RelTest$Inner.class",
+            "p/RelTest2.class", "p/RelTest2$Inner.class",
+            "Main.class" );
+
+        Set<File> found = findFiles(outDir);
+
+        if (!found.equals(expect)) {
+            if (found.containsAll(expect))
+                throw new Exception("unexpected files found: " + diff(found, expect));
+            else if (expect.containsAll(found))
+                throw new Exception("expected files not found: " + diff(expect, found));
+        }
+
+        for (File f: found)
+            verifySourceFileAttribute(f);
+
+        if (errors > 0)
+            throw new Exception(errors + " errors occurred");
+    }
+
+    /** Check the SourceFileAttribute is the simple name of the original source file. */
+    void verifySourceFileAttribute(File f) {
+        System.err.println("verify: " + f);
+        try {
+            ClassFile cf = ClassFile.read(f);
+            SourceFile_attribute sfa = (SourceFile_attribute) cf.getAttribute(Attribute.SourceFile);
+            String found = sfa.getSourceFile(cf.constant_pool);
+            String expect = f.getName().replaceAll("([$.].*)?\\.class", ".java");
+            if (!expect.equals(found)) {
+                error("bad value found: " + found + ", expected: " + expect);
+            }
+        } catch (Exception e) {
+            error("error reading " + f +": " + e);
+        }
+    }
+
+    /** Create a directory containing one or more files. */
+    File createDir(File dir, String... entries) throws Exception {
+        if (!dir.mkdirs())
+            throw new Exception("cannot create directories " + dir);
+        for (String e: entries) {
+            writeFile(new File(dir, getPathForEntry(e)), getBodyForEntry(e));
+        }
+        return dir;
+    }
+
+    /** Create a jar file containing one or more entries. */
+    File createJar(File jar, String... entries) throws IOException {
+        OutputStream out = new FileOutputStream(jar);
+        try {
+            JarOutputStream jos = new JarOutputStream(out);
+            for (String e: entries) {
+                jos.putNextEntry(new JarEntry(getPathForEntry(e)));
+                jos.write(getBodyForEntry(e).getBytes());
+            }
+            jos.close();
+        } finally {
+            out.close();
+        }
+        return jar;
+    }
+
+    /** Return the path for an entry given to createDir or createJar. */
+    String getPathForEntry(String e) {
+        return e.replace(".", File.separator) + ".java";
+    }
+
+    /** Return the body text for an entry given to createDir or createJar. */
+    String getBodyForEntry(String e) {
+        int sep = e.lastIndexOf(".");
+        String pkgName = e.substring(0, sep);
+        String className = e.substring(sep + 1);
+        return "package " + pkgName + "; public class " + className + "{ class Inner { } }";
+    }
+
+    /** Write a file containing the given string. Parent directories are
+     * created as needed. */
+    File writeFile(File f, String s) throws IOException {
+        if (f.getParentFile() != null)
+            f.getParentFile().mkdirs();
+        FileWriter out = new FileWriter(f);
+        try {
+            out.write(s);
+        } finally {
+            out.close();
+        }
+        return f;
+    }
+
+    /** Create a path value from a list of directories and jar files. */
+    String createPath(File... files) {
+        StringBuilder sb = new StringBuilder();
+        for (File f: files) {
+            if (sb.length() > 0)
+                sb.append(File.pathSeparatorChar);
+            sb.append(f.getPath());
+        }
+        return sb.toString();
+    }
+
+    /** Create a set of files from a base directory and a set of relative paths. */
+    Set<File> getFiles(File dir, String... paths) {
+        Set<File> files = new LinkedHashSet<File>();
+        for (String p: paths)
+            files.add(new File(dir, p));
+        return files;
+    }
+
+    /** Find all the files in a directory and its subdirectories. */
+    Set<File> findFiles(File dir) {
+        Set<File> files = new LinkedHashSet<File>();
+        findFiles(dir, files);
+        return files;
+    }
+    // where
+    void findFiles(File dir, Set<File> files) {
+        for (File f: dir.listFiles()) {
+            if (f.isDirectory())
+                findFiles(f, files);
+            else
+                files.add(f);
+        }
+    }
+
+    /** Return the difference of two sets, a - b. */
+    <T> Set<T> diff(Set<T> a, Set<T> b) {
+        if (b.isEmpty())
+            return a;
+        Set<T> result = new LinkedHashSet<T>(a);
+        result.removeAll(b);
+        return result;
+    }
+
+    /** Report an error. */
+    void error(String msg) {
+        System.err.println(msg);
+        errors++;
+    }
+
+    int errors;
+}
--- a/langtools/test/tools/javac/6589361/T6589361.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/test/tools/javac/6589361/T6589361.java	Fri Oct 16 18:02:31 2009 -0700
@@ -25,7 +25,7 @@
             for (JavaFileObject file : files) {
                 // Note: Zip/Jar entry names use '/', not File.separator, but just to be sure,
                 // we normalize the filename as well.
-                if (file.toString().replace(File.separatorChar, '/').contains("java/lang/Object.class")) {
+                if (file.getName().replace(File.separatorChar, '/').contains("java/lang/Object.class")) {
                     String str = fm.inferBinaryName(StandardLocation.CLASS_PATH, file);
                     if (!str.equals("java.lang.Object")) {
                         throw new AssertionError("Error in JavacFileManager.inferBinaryName method!");
--- a/langtools/test/tools/javac/Diagnostics/6769027/T6769027.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/test/tools/javac/Diagnostics/6769027/T6769027.java	Fri Oct 16 18:02:31 2009 -0700
@@ -261,7 +261,7 @@
 
     enum PositionKind {
         NOPOS(Position.NOPOS, "- ", "error: "),
-        POS(5, "/Test.java:1:6: ", "myfo:/Test.java:1: ");
+        POS(5, "Test.java:1:6: ", "/Test.java:1: ");
 
         int pos;
         String rawOutput;
--- a/langtools/test/tools/javac/T6705935.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/test/tools/javac/T6705935.java	Fri Oct 16 18:02:31 2009 -0700
@@ -48,7 +48,7 @@
                                         "java.lang",
                                         Collections.singleton(JavaFileObject.Kind.CLASS),
                                         false)) {
-            String p = ((BaseFileObject)fo).getPath();
+            String p = fo.getName();
             int bra = p.indexOf("(");
             int ket = p.indexOf(")");
             //System.err.println(bra + "," + ket + "," + p.length());
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/pos/TrailingComma.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6337964
+ * @summary javac incorrectly disallows trailing comma in annotation arrays
+ * @author darcy
+ * @compile TrailingComma.java
+ */
+
+import java.lang.annotation.*;
+
+@interface TestAnnotation {
+    SuppressWarnings[] value() default {@SuppressWarnings({"",})};
+}
+
+
+@TestAnnotation({@SuppressWarnings(),
+                 @SuppressWarnings({"Beware the ides of March.",}),
+                 @SuppressWarnings({"Look both ways", "Before Crossing",}), })
+public class TrailingComma {
+}
--- a/langtools/test/tools/javac/api/6411310/T6411310.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/test/tools/javac/api/6411310/T6411310.java	Fri Oct 16 18:02:31 2009 -0700
@@ -37,7 +37,7 @@
 import static javax.tools.StandardLocation.CLASS_PATH;
 import static javax.tools.JavaFileObject.Kind.CLASS;
 
-// Limited test while we wait for 6419926
+// Limited test while we wait for 6419926: 6419926 is now closed
 
 public class T6411310 extends ToolTester {
 
@@ -45,8 +45,11 @@
         JavaFileObject file = fm.getJavaFileForInput(PLATFORM_CLASS_PATH,
                                                      "java.lang.Object",
                                                      CLASS);
-        if (!file.getName().equals("Object.class"))
+        String fileName = file.getName();
+        if (!fileName.matches(".*java/lang/Object.class\\)?")) {
+            System.err.println(fileName);
             throw new AssertionError(file);
+        }
     }
 
     public static void main(String... args) throws IOException {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/api/6411310/Test.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,254 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6410367 6411310
+ * @summary FileObject should support user-friendly names via getName()
+ */
+
+import java.io.*;
+import java.util.*;
+import java.util.jar.*;
+import java.util.zip.*;
+import javax.tools.*;
+
+import com.sun.tools.javac.file.JavacFileManager;
+import com.sun.tools.javac.util.Context;
+import com.sun.tools.javac.util.Options;
+
+// Test FileObject.getName returned from JavacFileManager and its support classes.
+
+public class Test {
+    public static void main(String... args) throws Exception {
+        new Test().run();
+    }
+
+    Set<String> foundClasses = new TreeSet<String>();
+    Set<String> foundJars = new TreeSet<String>();
+
+    void run() throws Exception {
+        File rt_jar = findRtJar();
+
+        // names for entries to be created in directories and jar files
+        String[] entries = { "p/A.java", "p/A.class", "p/resources/A-1.html" };
+
+        // test various combinations of directories and jar files, intended to
+        // cover all sources of file objects within JavacFileManager's support classes
+
+        test(createFileManager(), createDir("dir", entries), "p", entries);
+        test(createFileManager(), createDir("a b/dir", entries), "p", entries);
+
+        for (boolean useJavaUtilZip: new boolean[] { false, true }) {
+            test(createFileManager(useJavaUtilZip), createJar("jar", entries), "p", entries);
+            test(createFileManager(useJavaUtilZip), createJar("jar jar", entries), "p", entries);
+
+            for (boolean useSymbolFile: new boolean[] { false, true }) {
+                test(createFileManager(useJavaUtilZip, useSymbolFile), rt_jar, "java.lang.ref", null);
+            }
+        }
+
+        if (errors > 0)
+            throw new Exception(errors + " errors found");
+
+        // Verify that we hit all the impl classes we intended
+        checkCoverage("classes", foundClasses,
+                "RegularFileObject", "SymbolFileObject", "ZipFileIndexFileObject", "ZipFileObject");
+
+        // Verify that we hit the jar files we intended, specifically ct.sym as well as rt.jar
+        checkCoverage("jar files", foundJars,
+                "ct.sym", "jar", "jar jar", "rt.jar");
+    }
+
+    // use a new file manager for each test
+    void test(StandardJavaFileManager fm, File f, String pkg, String[] entries) throws Exception {
+        System.err.println("Test " + f);
+        try {
+            if (f.isDirectory()) {
+                for (File dir: new File[] { f, f.getAbsoluteFile() }) {
+                    for (String e: entries) {
+                        JavaFileObject fo = fm.getJavaFileObjects(new File(dir, e)).iterator().next();
+                        test(fo, dir, e);
+                    }
+                }
+            }
+
+            fm.setLocation(StandardLocation.CLASS_PATH, Collections.singleton(f));
+            fm.setLocation(StandardLocation.SOURCE_PATH, Collections.singleton(f.getAbsoluteFile()));
+            for (StandardLocation l: EnumSet.of(StandardLocation.CLASS_PATH, StandardLocation.SOURCE_PATH)) {
+                for (JavaFileObject fo: fm.list(l, pkg, EnumSet.allOf(JavaFileObject.Kind.class), true)) {
+                    // we could use fm.getLocation but the following guarantees we preserve the original filename
+                    File dir = (l == StandardLocation.CLASS_PATH ? f : f.getAbsoluteFile());
+                    char sep = (dir.isDirectory() ? File.separatorChar : '/');
+                    String b = fm.inferBinaryName(l, fo);
+                    String e = fo.getKind().extension;
+                    test(fo, dir, b.replace('.', sep) + e);
+                }
+            }
+        } finally {
+            fm.close();
+        }
+    }
+
+    void test(JavaFileObject fo, File dir, String p) {
+        System.err.println("Test: " + fo);
+        String expect = dir.isDirectory() ? new File(dir, p).getPath() : (dir.getPath() + "(" + p + ")");
+        String found = fo.getName();
+        // if ct.sym is found, replace it with the equivalent rt.jar
+        String found2 = found.replaceAll("lib([\\\\/])ct.sym\\(META-INF/sym/rt.jar/", "jre$1lib$1rt.jar(");
+        if (!expect.equals(found2)) {
+            System.err.println("expected: " + expect);
+            System.err.println("   found: " + found);
+            if (!found.equals(found2))
+                System.err.println("  found2: " + found2);
+            error("Failed: " + fo);
+        }
+
+        // record the file object class name for coverage checks later
+        foundClasses.add(fo.getClass().getSimpleName());
+
+        if (found.contains("(")) {
+            // record access to the jar file for coverage checks later
+            foundJars.add(new File(found.substring(0, found.indexOf("("))).getName());
+        }
+    }
+
+    void checkCoverage(String label, Set<String> found, String... expect) throws Exception {
+        Set<String> e = new TreeSet<String>(Arrays.asList(expect));
+        if (!found.equals(e)) {
+            e.removeAll(found);
+            throw new Exception("expected " + label + " not used: " + e);
+        }
+    }
+
+    JavacFileManager createFileManager() {
+        return createFileManager(false, false);
+    }
+
+    JavacFileManager createFileManager(boolean useJavaUtilZip) {
+        return createFileManager(useJavaUtilZip, false);
+    }
+
+    JavacFileManager createFileManager(boolean useJavaUtilZip, boolean useSymbolFile) {
+        // javac should really not be using system properties like this
+        // -- it should really be using (hidden) options -- but until then
+        // take care to leave system properties as we find them, so as not
+        // to adversely affect other tests that might follow.
+        String prev = System.getProperty("useJavaUtilZip");
+        boolean resetProperties = false;
+        try {
+            if (useJavaUtilZip) {
+                System.setProperty("useJavaUtilZip", "true");
+                resetProperties = true;
+            } else if (System.getProperty("useJavaUtilZip") != null) {
+                System.getProperties().remove("useJavaUtilZip");
+                resetProperties = true;
+            }
+
+            Context c = new Context();
+            if (!useSymbolFile) {
+                Options options = Options.instance(c);
+                options.put("ignore.symbol.file", "true");
+            }
+
+            return new JavacFileManager(c, false, null);
+        } finally {
+            if (resetProperties) {
+                if (prev == null) {
+                    System.getProperties().remove("useJavaUtilZip");
+                } else {
+                    System.setProperty("useJavaUtilZip", prev);
+                }
+            }
+        }
+    }
+
+    File createDir(String name, String... entries) throws Exception {
+        File dir = new File(name);
+        if (!dir.mkdirs())
+            throw new Exception("cannot create directories " + dir);
+        for (String e: entries) {
+            writeFile(new File(dir, e), e);
+        }
+        return dir;
+    }
+
+    File createJar(String name, String... entries) throws IOException {
+        File jar = new File(name);
+        OutputStream out = new FileOutputStream(jar);
+        try {
+            JarOutputStream jos = new JarOutputStream(out);
+            for (String e: entries) {
+                jos.putNextEntry(new ZipEntry(e));
+                jos.write(e.getBytes());
+            }
+            jos.close();
+        } finally {
+            out.close();
+        }
+        return jar;
+    }
+
+    File findRtJar() throws Exception {
+        File java_home = new File(System.getProperty("java.home"));
+        if (java_home.getName().equals("jre"))
+            java_home = java_home.getParentFile();
+        File rt_jar = new File(new File(new File(java_home, "jre"), "lib"), "rt.jar");
+        if (!rt_jar.exists())
+            throw new Exception("can't find rt.jar");
+        return rt_jar;
+    }
+
+    byte[] read(InputStream in) throws IOException {
+        byte[] data = new byte[1024];
+        int offset = 0;
+        try {
+            int n;
+            while ((n = in.read(data, offset, data.length - offset)) != -1) {
+                offset += n;
+                if (offset == data.length)
+                    data = Arrays.copyOf(data, 2 * data.length);
+            }
+        } finally {
+            in.close();
+        }
+        return Arrays.copyOf(data, offset);
+    }
+
+    void writeFile(File f, String s) throws IOException {
+        f.getParentFile().mkdirs();
+        FileWriter out = new FileWriter(f);
+        try {
+            out.write(s);
+        } finally {
+            out.close();
+        }
+    }
+
+    void error(String msg) {
+        System.err.println(msg);
+        errors++;
+    }
+
+    int errors;
+}
--- a/langtools/test/tools/javac/api/6733837/T6733837.java	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/test/tools/javac/api/6733837/T6733837.java	Fri Oct 16 18:02:31 2009 -0700
@@ -46,14 +46,10 @@
     }
 
     public void exec() {
-        JavaFileObject sfo = new SimpleJavaFileObject(URI.create(""),Kind.SOURCE) {
+        JavaFileObject sfo = new SimpleJavaFileObject(URI.create("myfo:/Test.java"),Kind.SOURCE) {
             public CharSequence getCharContent(boolean ignoreEncodingErrors) {
                 return "\tclass ErroneousWithTab";
             }
-            @Override
-            public String getName() {
-                return "RELATIVEPATH";
-            }
         };
         StringWriter sw = new StringWriter();
         PrintWriter out = new PrintWriter(sw);
@@ -66,7 +62,7 @@
             throw new Error("Compiler threw an exception");
         }
         System.err.println(sw.toString());
-        if (sw.toString().contains("RELATIVEPATH"))
+        if (!sw.toString().contains("/Test.java"))
             throw new Error("Bad source name in diagnostic");
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/processing/model/util/elements/Foo.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,29 @@
+
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * Dummy type to compile.
+ */
+public class Foo {
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/processing/model/util/elements/TestGetConstantExpression.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6471577 6517779
+ * @summary Test Elements.getConstantExpression
+ * @author  Joseph D. Darcy
+ * @build TestGetConstantExpression
+ * @compile -processor TestGetConstantExpression Foo.java
+ */
+
+import java.util.Set;
+import javax.annotation.processing.*;
+import javax.lang.model.SourceVersion;
+import static javax.lang.model.SourceVersion.*;
+import javax.lang.model.element.*;
+import javax.lang.model.util.*;
+import static javax.lang.model.util.ElementFilter.*;
+import static javax.tools.Diagnostic.Kind.*;
+import static javax.tools.StandardLocation.*;
+import java.io.*;
+
+/**
+ * Test basic workings of Elements.getConstantExpression.
+ */
+@SupportedAnnotationTypes("*")
+public class TestGetConstantExpression extends AbstractProcessor {
+    private Elements eltUtils;
+    private Filer filer;
+    private int round = 1;
+
+    /**
+     * Check expected behavior on classes and packages.
+     */
+    public boolean process(Set<? extends TypeElement> annotations,
+                           RoundEnvironment roundEnv) {
+        int errors = 0;
+        boolean processingOver = roundEnv.processingOver();
+
+        if (!processingOver && round == 1) {
+            errors += expectIllegalArgumentException(null);
+            errors += expectIllegalArgumentException(this);
+
+            // Generate source code with various constant values and
+            // make sure it compiles.
+
+            try {
+                PrintWriter pw = new PrintWriter(filer.createSourceFile("ConstantTest").openWriter());
+                try {
+                    Boolean[]   booleans = {true, false};
+                    Byte[]      bytes    = {Byte.MIN_VALUE,    -1,  0, 1,  Byte.MAX_VALUE};
+                    Short[]     shorts   = {Short.MIN_VALUE,   -1,  0, 1,  Short.MAX_VALUE};
+                    Integer[]   ints     = {Integer.MIN_VALUE, -1,  0, 1,  Integer.MAX_VALUE};
+                    Long[]      longs    = {Long.MIN_VALUE,    -1L, 0L,1L, Long.MAX_VALUE};
+                    Character[] chars    = {Character.MIN_VALUE, ' ', '\t', 'a', 'b', 'c', '~', Character.MAX_VALUE};
+                    Float[]     floats   = {Float.NaN,  Float.NEGATIVE_INFINITY,  -1.0f, -0.0f, 0.0f, 1.0f, Float.POSITIVE_INFINITY};
+                    Double[]    doubles  = {Double.NaN, Double.NEGATIVE_INFINITY, -1.0,  -0.0,  0.0,  1.0,  Double.POSITIVE_INFINITY};
+
+                    pw.println("class ConstantTest {");
+                    pw.println(String.format("  private static boolean[] booleans = {%s};",
+                                             printConstants(booleans)));
+                    pw.println(String.format("  private static byte[] bytes = {%s};",
+                                             printConstants(bytes)));
+                    pw.println(String.format("  private static short[] shorts = {%s};",
+                                             printConstants(shorts)));
+                    pw.println(String.format("  private static int[] ints = {%s};",
+                                             printConstants(ints)));
+                    pw.println(String.format("  private static long[] longs = {%s};",
+                                             printConstants(longs)));
+                    pw.println(String.format("  private static char[] chars = {%s};",
+                                             printConstants(chars)));
+                    pw.println(String.format("  private static float[] floats = {%s};",
+                                             printConstants(floats)));
+                    pw.println(String.format("  private static double[] doubles = {%s};",
+                                             printConstants(doubles)));
+                    pw.println("}");
+                } finally {
+                    pw.close();
+                }
+            } catch(IOException io) {
+                throw new RuntimeException(io);
+            }
+            round++;
+        } else if (processingOver) {
+            if (errors > 0) {
+                throw new RuntimeException();
+            }
+        }
+        return true;
+    }
+
+    String printConstants(Object[] constants) {
+        StringBuilder sb = new StringBuilder();
+
+        for(Object o : constants) {
+            sb.append(eltUtils.getConstantExpression(o));
+            sb.append(", ");
+        }
+        return sb.toString();
+    }
+
+    int expectIllegalArgumentException(Object o) {
+        String s = "";
+        try {
+            s = eltUtils.getConstantExpression(o);
+            System.err.println("Unexpected string returned: " + s);
+            return 1;
+        } catch (IllegalArgumentException iae) {
+            return 0;
+        }
+    }
+
+    public SourceVersion getSupportedSourceVersion() {
+        return SourceVersion.latest();
+    }
+
+    public void init(ProcessingEnvironment processingEnv) {
+        super.init(processingEnv);
+        eltUtils = processingEnv.getElementUtils();
+        filer    = processingEnv.getFiler();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javah/6572945/T6572945.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,239 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6572945
+ * @summary rewrite javah as an annotation processor, instead of as a doclet
+ * @build TestClass1 TestClass2 TestClass3
+ * @run main T6572945
+ */
+
+import java.io.*;
+import java.util.*;
+import com.sun.tools.javah.Main;
+
+public class T6572945
+{
+    static File testSrc = new File(System.getProperty("test.src", "."));
+    static File testClasses = new File(System.getProperty("test.classes", "."));
+    static boolean isWindows = System.getProperty("os.name").startsWith("Windows");
+
+    public static void main(String... args)
+        throws IOException, InterruptedException
+    {
+        boolean ok = new T6572945().run(args);
+        if (!ok)
+            throw new Error("Test Failed");
+    }
+
+    public boolean run(String[] args)
+        throws IOException, InterruptedException
+    {
+        if (args.length == 1)
+            jdk = new File(args[0]);
+
+        test("-o", "jni.file.1",  "-jni", "TestClass1");
+        test("-o", "jni.file.2",  "-jni", "TestClass1", "TestClass2");
+        test("-d", "jni.dir.1",   "-jni", "TestClass1", "TestClass2");
+        test("-o", "jni.file.3",  "-jni", "TestClass3");
+
+        // The following tests are disabled because llni support has been
+        // discontinued, and because bugs in old javah means that character
+        // for character testing against output from old javah does not work.
+        // In fact, the LLNI impl in new javah is actually better than the
+        // impl in old javah because of a couple of significant bug fixes.
+
+//        test("-o", "llni.file.1", "-llni", "TestClass1");
+//        test("-o", "llni.file.2", "-llni", "TestClass1", "TestClass2");
+//        test("-d", "llni.dir.1",  "-llni", "TestClass1", "TestClass2");
+//        test("-o", "llni.file.3", "-llni", "TestClass3");
+
+        return (errors == 0);
+    }
+
+    void test(String... args)
+        throws IOException, InterruptedException
+    {
+        String[] cp_args = new String[args.length + 2];
+        cp_args[0] = "-classpath";
+        cp_args[1] = testClasses.getPath();
+        System.arraycopy(args, 0, cp_args, 2, args.length);
+
+        if (jdk != null)
+            init(cp_args);
+
+        File out = null;
+        for (int i = 0; i < args.length; i++) {
+            if (args[i].equals("-o")) {
+                out = new File(args[++i]);
+                break;
+            } else if (args[i].equals("-d")) {
+                out = new File(args[++i]);
+                out.mkdirs();
+                break;
+            }
+        }
+
+        try {
+            System.out.println("test: " + Arrays.asList(cp_args));
+
+//            // Uncomment and use the following lines to execute javah via the
+//            // command line -- for example, to run old javah and set up the golden files
+//            List<String> cmd = new ArrayList<String>();
+//            File javaHome = new File(System.getProperty("java.home"));
+//            if (javaHome.getName().equals("jre"))
+//                javaHome = javaHome.getParentFile();
+//            File javah = new File(new File(javaHome, "bin"), "javah");
+//            cmd.add(javah.getPath());
+//            cmd.addAll(Arrays.asList(cp_args));
+//            ProcessBuilder pb = new ProcessBuilder(cmd);
+//            pb.redirectErrorStream(true);
+//            pb.start();
+//            Process p = pb.start();
+//            String line;
+//            BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
+//            while ((line = in.readLine()) != null)
+//                System.err.println(line);
+//            in.close();
+//            int rc = p.waitFor();
+
+            // Use new javah
+            PrintWriter err = new PrintWriter(System.err, true);
+            int rc = Main.run(cp_args, err);
+
+            if (rc != 0) {
+                error("javah failed: rc=" + rc);
+                return;
+            }
+
+            // The golden files use the LL suffix for long constants, which
+            // is used on Linux and Solaris.   On Windows, the suffix is i64,
+            // so compare will update the golden files on the fly before the
+            // final comparison.
+            compare(new File(new File(testSrc, "gold"), out.getName()), out);
+        } catch (Throwable t) {
+            t.printStackTrace();
+            error("javah threw exception");
+        }
+    }
+
+    void init(String[] args) throws IOException, InterruptedException {
+        String[] cmdArgs = new String[args.length + 1];
+        cmdArgs[0] = new File(new File(jdk, "bin"), "javah").getPath();
+        System.arraycopy(args, 0, cmdArgs, 1, args.length);
+
+        System.out.println("init: " + Arrays.asList(cmdArgs));
+
+        ProcessBuilder pb = new ProcessBuilder(cmdArgs);
+        pb.directory(new File(testSrc, "gold"));
+        pb.redirectErrorStream(true);
+        Process p = pb.start();
+        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
+        String line;
+        while ((line = in.readLine()) != null)
+            System.out.println("javah: " + line);
+        int rc = p.waitFor();
+        if (rc != 0)
+            error("javah: exit code " + rc);
+    }
+
+    /** Compare two directories.
+     *  @param f1 The golden directory
+     *  @param f2 The directory to be compared
+     */
+    void compare(File f1, File f2) {
+        compare(f1, f2, null);
+    }
+
+    /** Compare two files or directories
+     *  @param f1 The golden directory
+     *  @param f2 The directory to be compared
+     *  @param p An optional path identifying a file within the two directories
+     */
+    void compare(File f1, File f2, String p) {
+        File f1p = (p == null ? f1 : new File(f1, p));
+        File f2p = (p == null ? f2 : new File(f2, p));
+        System.out.println("compare " + f1p + " " + f2p);
+        if (f1p.isDirectory() && f2p.isDirectory()) {
+            Set<String> children = new HashSet<String>();
+            children.addAll(Arrays.asList(f1p.list()));
+            children.addAll(Arrays.asList(f2p.list()));
+            for (String c: children) {
+                compare(f1, f2, new File(p, c).getPath()); // null-safe for p
+            }
+        }
+        else if (f1p.isFile() && f2p.isFile()) {
+            String s1 = read(f1p);
+            if (isWindows) {
+                // f1/s1 is the golden file
+                // on Windows, long constants use the i64 suffix, not LL
+                s1 = s1.replaceAll("( [0-9]+)LL\n", "$1i64\n");
+            }
+            String s2 = read(f2p);
+            if (!s1.equals(s2)) {
+                System.out.println("File: " + f1p + "\n" + s1);
+                System.out.println("File: " + f2p + "\n" + s2);
+                error("Files differ: " + f1p + " " + f2p);
+            }
+        }
+        else if (f1p.exists() && !f2p.exists())
+            error("Only in " + f1 + ": " + p);
+        else if (f2p.exists() && !f1p.exists())
+            error("Only in " + f2 + ": " + p);
+        else
+            error("Files differ: " + f1p + " " + f2p);
+    }
+
+    private String read(File f) {
+        try {
+            BufferedReader in = new BufferedReader(new FileReader(f));
+            try {
+                StringBuilder sb = new StringBuilder((int) f.length());
+                String line;
+                while ((line = in.readLine()) != null) {
+                    sb.append(line);
+                    sb.append("\n");
+                }
+                return sb.toString();
+            } finally {
+                try {
+                    in.close();
+                } catch (IOException e) {
+                }
+            }
+        } catch (IOException e) {
+            error("error reading " + f + ": " + e);
+            return "";
+        }
+    }
+
+
+    private void error(String msg) {
+        System.out.println(msg);
+        errors++;
+    }
+
+    private int errors;
+    private File jdk;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javah/6572945/TestClass1.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,475 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+import java.util.List;
+
+public class TestClass1 {
+    // simple types
+    byte b;
+    short s;
+    int i;
+    long l;
+    float f;
+    double d;
+    Object o;
+    String t;
+    List<String> g;
+
+    // constants
+    static final byte bc = 0;
+    static final short sc = 0;
+    static final int ic = 0;
+    static final long lc = 0;
+    static final float fc = 0;
+    static final double dc = 0;
+    static final Object oc = null;
+    static final String tc = "";
+    static final List<String> gc = null;
+
+    // simple arrays
+    byte[] ba;
+    short[] sa; // not handled corrected by javah v6
+    int[] ia;
+    long[] la;
+    float[] fa;
+    double[] da;
+    Object[] oa;
+    String[] ta;
+    List<String>[] ga;
+
+    // multidimensional arrays
+    byte[][] baa;
+    short[][] saa;
+    int[][] iaa;
+    long[][] laa;
+    float[][] faa;
+    double[][] daa;
+    Object[][] oaa;
+    String[][] taa;
+    List<String>[] gaa;
+
+    // simple Java methods
+    byte bm() { return 0; }
+    short sm() { return 0; }
+    int im() { return 0; }
+    long lm() { return 0; }
+    float fm() { return 0; }
+    double dm() { return 0; }
+    Object om() { return null; }
+    String tm() { return ""; }
+    List<String> gm() { return null; }
+    void vm() { }
+    byte[] bam() { return null; }
+    short[] sam() { return null; }
+    int[] iam() { return null; }
+    long[] lam() { return null; }
+    float[] fam() { return null; }
+    double[] dam() { return null; }
+    Object[] oam() { return null; }
+    String[] tam() { return null; }
+    List<String>[] gam() { return null; }
+    byte[][] baam() { return null; }
+    short[][] saam() { return null; }
+    int[][] iaam() { return null; }
+    long[][] laam() { return null; }
+    float[][] faam() { return null; }
+    double[][] daam() { return null; }
+    Object[][] oaam() { return null; }
+    String[][] taam() { return null; }
+    List<String>[] gaam() { return null; }
+
+    // simple native methods
+    native byte bmn();
+    native short smn();
+    native int imn();
+    native long lmn();
+    native float fmn();
+    native double dmn();
+    native Object omn();
+    native String tmn();
+    native List<String> gmn();
+    native void vmn();
+    native byte[] bamn();
+    native short[] samn();
+    native int[] iamn();
+    native long[] lamn();
+    native float[] famn();
+    native double[] damn();
+    native Object[] oamn();
+    native String[] tamn();
+    native List<String>[] gamn();
+    native byte[][] baamn();
+    native short[][] saamn();
+    native int[][] iaamn();
+    native long[][] laamn();
+    native float[][] faamn();
+    native double[][] daamn();
+    native Object[][] oaamn();
+    native String[][] taamn();
+    native List<String>[] gaamn();
+
+    // overloaded Java methods
+    byte bm1() { return 0; }
+    short sm1() { return 0; }
+    int im1() { return 0; }
+    long lm1() { return 0; }
+    float fm1() { return 0; }
+    double dm1() { return 0; }
+    Object om1() { return null; }
+    String tm1() { return ""; }
+    List<String> gm1() { return null; }
+    void vm1() { }
+
+    byte bm2(int i) { return 0; }
+    short sm2(int i) { return 0; }
+    int im2(int i) { return 0; }
+    long lm2(int i) { return 0; }
+    float fm2(int i) { return 0; }
+    double dm2(int i) { return 0; }
+    Object om2(int i) { return null; }
+    String tm2(int i) { return ""; }
+    List<String> gm2(int i) { return null; }
+    void vm2(int i) { }
+
+    // overloaded native methods
+    native byte bmn1();
+    native short smn1();
+    native int imn1();
+    native long lmn1();
+    native float fmn1();
+    native double dmn1();
+    native Object omn1();
+    native String tmn1();
+    native List<String> gmn1();
+    native void vmn1();
+
+    native byte bmn2(int i);
+    native short smn2(int i);
+    native int imn2(int i);
+    native long lmn2(int i);
+    native float fmn2(int i);
+    native double dmn2(int i);
+    native Object omn2(int i);
+    native String tmn2(int i);
+    native List<String> gmn2(int i);
+    native void vmn2(int i);
+
+    // arg types for Java methods
+    void mb(byte b) { }
+    void ms(short s) { }
+    void mi(int i) { }
+    void ml(long l) { }
+    void mf(float f) { }
+    void md(double d) { }
+    void mo(Object o) { }
+    void mt(String t) { }
+    void mg(List<String> g) { }
+
+    // arg types for native methods
+    native void mbn(byte b);
+    native void msn(short s);
+    native void min(int i);
+    native void mln(long l);
+    native void mfn(float f);
+    native void mdn(double d);
+    native void mon(Object o);
+    native void mtn(String t);
+    native void mgn(List<String> g);
+
+    static class Inner1 {
+        // simple types
+        byte b;
+        short s;
+        int i;
+        long l;
+        float f;
+        double d;
+        Object o;
+        String t;
+        List<String> g;
+
+        // constants
+        static final byte bc = 0;
+        static final short sc = 0;
+        static final int ic = 0;
+        static final long lc = 0;
+        static final float fc = 0;
+        static final double dc = 0;
+        static final Object oc = null;
+        static final String tc = "";
+        static final List<String> gc = null;
+
+        // simple arrays
+        byte[] ba;
+        // short[] sa; // not handled corrected by javah v6
+        int[] ia;
+        long[] la;
+        float[] fa;
+        double[] da;
+        Object[] oa;
+        String[] ta;
+        List<String>[] ga;
+
+        // multidimensional arrays
+        byte[][] baa;
+        short[][] saa;
+        int[][] iaa;
+        long[][] laa;
+        float[][] faa;
+        double[][] daa;
+        Object[][] oaa;
+        String[][] taa;
+        List<String>[] gaa;
+
+        // simple Java methods
+        byte bm() { return 0; }
+        short sm() { return 0; }
+        int im() { return 0; }
+        long lm() { return 0; }
+        float fm() { return 0; }
+        double dm() { return 0; }
+        Object om() { return null; }
+        String tm() { return ""; }
+        List<String> gm() { return null; }
+        void vm() { }
+
+        // simple native methods
+        native byte bmn();
+        native short smn();
+        native int imn();
+        native long lmn();
+        native float fmn();
+        native double dmn();
+        native Object omn();
+        native String tmn();
+        native List<String> gmn();
+        native void vmn();
+
+        // overloaded Java methods
+        byte bm1() { return 0; }
+        short sm1() { return 0; }
+        int im1() { return 0; }
+        long lm1() { return 0; }
+        float fm1() { return 0; }
+        double dm1() { return 0; }
+        Object om1() { return null; }
+        String tm1() { return ""; }
+        List<String> gm1() { return null; }
+        void vm1() { }
+
+        byte bm2(int i) { return 0; }
+        short sm2(int i) { return 0; }
+        int im2(int i) { return 0; }
+        long lm2(int i) { return 0; }
+        float fm2(int i) { return 0; }
+        double dm2(int i) { return 0; }
+        Object om2(int i) { return null; }
+        String tm2(int i) { return ""; }
+        List<String> gm2(int i) { return null; }
+        void vm2(int i) { }
+
+        // overloaded native methods
+        native byte bmn1();
+        native short smn1();
+        native int imn1();
+        native long lmn1();
+        native float fmn1();
+        native double dmn1();
+        native Object omn1();
+        native String tmn1();
+        native List<String> gmn1();
+        native void vmn1();
+
+        native byte bmn2(int i);
+        native short smn2(int i);
+        native int imn2(int i);
+        native long lmn2(int i);
+        native float fmn2(int i);
+        native double dmn2(int i);
+        native Object omn2(int i);
+        native String tmn2(int i);
+        native List<String> gmn2(int i);
+        native void vmn2(int i);
+
+        // arg types for Java methods
+        void mb(byte b) { }
+        void ms(short s) { }
+        void mi(int i) { }
+        void ml(long l) { }
+        void mf(float f) { }
+        void md(double d) { }
+        void mo(Object o) { }
+        void mt(String t) { }
+        void mg(List<String> g) { }
+
+        // arg types for native methods
+        native void mbn(byte b);
+        native void msn(short s);
+        native void min(int i);
+        native void mln(long l);
+        native void mfn(float f);
+        native void mdn(double d);
+        native void mon(Object o);
+        native void mtn(String t);
+        native void mgn(List<String> g);
+    }
+
+    class Inner2 {
+        // simple types
+        byte b;
+        short s;
+        int i;
+        long l;
+        float f;
+        double d;
+        Object o;
+        String t;
+        List<String> g;
+
+        // constants
+        static final byte bc = 0;
+        static final short sc = 0;
+        static final int ic = 0;
+        static final long lc = 0;
+        static final float fc = 0;
+        static final double dc = 0;
+        //static final Object oc = null;
+        static final String tc = "";
+        //static final List<String> gc = null;
+
+        // simple arrays
+        byte[] ba;
+        // short[] sa; // not handled corrected by javah v6
+        int[] ia;
+        long[] la;
+        float[] fa;
+        double[] da;
+        Object[] oa;
+        String[] ta;
+        List<String>[] ga;
+
+        // multidimensional arrays
+        byte[][] baa;
+        short[][] saa;
+        int[][] iaa;
+        long[][] laa;
+        float[][] faa;
+        double[][] daa;
+        Object[][] oaa;
+        String[][] taa;
+        List<String>[] gaa;
+
+        // simple Java methods
+        byte bm() { return 0; }
+        short sm() { return 0; }
+        int im() { return 0; }
+        long lm() { return 0; }
+        float fm() { return 0; }
+        double dm() { return 0; }
+        Object om() { return null; }
+        String tm() { return ""; }
+        List<String> gm() { return null; }
+        void vm() { }
+
+        // simple native methods
+        native byte bmn();
+        native short smn();
+        native int imn();
+        native long lmn();
+        native float fmn();
+        native double dmn();
+        native Object omn();
+        native String tmn();
+        native List<String> gmn();
+        native void vmn();
+
+        // overloaded Java methods
+        byte bm1() { return 0; }
+        short sm1() { return 0; }
+        int im1() { return 0; }
+        long lm1() { return 0; }
+        float fm1() { return 0; }
+        double dm1() { return 0; }
+        Object om1() { return null; }
+        String tm1() { return ""; }
+        List<String> gm1() { return null; }
+        void vm1() { }
+
+        byte bm2(int i) { return 0; }
+        short sm2(int i) { return 0; }
+        int im2(int i) { return 0; }
+        long lm2(int i) { return 0; }
+        float fm2(int i) { return 0; }
+        double dm2(int i) { return 0; }
+        Object om2(int i) { return null; }
+        String tm2(int i) { return ""; }
+        List<String> gm2(int i) { return null; }
+        void vm2(int i) { }
+
+        // overloaded native methods
+        native byte bmn1();
+        native short smn1();
+        native int imn1();
+        native long lmn1();
+        native float fmn1();
+        native double dmn1();
+        native Object omn1();
+        native String tmn1();
+        native List<String> gmn1();
+        native void vmn1();
+
+        native byte bmn2(int i);
+        native short smn2(int i);
+        native int imn2(int i);
+        native long lmn2(int i);
+        native float fmn2(int i);
+        native double dmn2(int i);
+        native Object omn2(int i);
+        native String tmn2(int i);
+        native List<String> gmn2(int i);
+        native void vmn2(int i);
+
+        // arg types for Java methods
+        void mb(byte b) { }
+        void ms(short s) { }
+        void mi(int i) { }
+        void ml(long l) { }
+        void mf(float f) { }
+        void md(double d) { }
+        void mo(Object o) { }
+        void mt(String t) { }
+        void mg(List<String> g) { }
+
+        // arg types for native methods
+        native void mbn(byte b);
+        native void msn(short s);
+        native void min(int i);
+        native void mln(long l);
+        native void mfn(float f);
+        native void mdn(double d);
+        native void mon(Object o);
+        native void mtn(String t);
+        native void mgn(List<String> g);
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javah/6572945/TestClass2.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+public class TestClass2 {
+    byte b;
+    short s;
+    int i;
+    long l;
+    float f;
+    double d;
+    Object o;
+    String t;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javah/6572945/TestClass3.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+public class TestClass3 {
+    public int tc3;
+
+    public class Inner1 {
+        public int tc3i1;
+
+        public class Inner1A {
+            public int tc3i1i1a;
+        }
+
+        public class Inner1B {
+            public int tc3i1i1b;
+        }
+    }
+
+    public class Inner2 {
+        public int tc321;
+
+        public class Inner2A {
+            public int tc3i2i2a;
+        }
+
+        public class Inner2B {
+            public int tc3i2i2b;
+        }
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javah/6572945/gold/jni.dir.1/TestClass1.h	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,481 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class TestClass1 */
+
+#ifndef _Included_TestClass1
+#define _Included_TestClass1
+#ifdef __cplusplus
+extern "C" {
+#endif
+#undef TestClass1_bc
+#define TestClass1_bc 0L
+#undef TestClass1_sc
+#define TestClass1_sc 0L
+#undef TestClass1_ic
+#define TestClass1_ic 0L
+#undef TestClass1_lc
+#define TestClass1_lc 0LL
+#undef TestClass1_fc
+#define TestClass1_fc 0.0f
+#undef TestClass1_dc
+#define TestClass1_dc 0.0
+/*
+ * Class:     TestClass1
+ * Method:    bmn
+ * Signature: ()B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_bmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    smn
+ * Signature: ()S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_smn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    imn
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_imn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    lmn
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_lmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    fmn
+ * Signature: ()F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_fmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    dmn
+ * Signature: ()D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_dmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    omn
+ * Signature: ()Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_omn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    tmn
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_tmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    gmn
+ * Signature: ()Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_gmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    vmn
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_vmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    bamn
+ * Signature: ()[B
+ */
+JNIEXPORT jbyteArray JNICALL Java_TestClass1_bamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    samn
+ * Signature: ()[S
+ */
+JNIEXPORT jshortArray JNICALL Java_TestClass1_samn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    iamn
+ * Signature: ()[I
+ */
+JNIEXPORT jintArray JNICALL Java_TestClass1_iamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    lamn
+ * Signature: ()[J
+ */
+JNIEXPORT jlongArray JNICALL Java_TestClass1_lamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    famn
+ * Signature: ()[F
+ */
+JNIEXPORT jfloatArray JNICALL Java_TestClass1_famn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    damn
+ * Signature: ()[D
+ */
+JNIEXPORT jdoubleArray JNICALL Java_TestClass1_damn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    oamn
+ * Signature: ()[Ljava/lang/Object;
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_oamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    tamn
+ * Signature: ()[Ljava/lang/String;
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_tamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    gamn
+ * Signature: ()[Ljava/util/List;
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_gamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    baamn
+ * Signature: ()[[B
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_baamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    saamn
+ * Signature: ()[[S
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_saamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    iaamn
+ * Signature: ()[[I
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_iaamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    laamn
+ * Signature: ()[[J
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_laamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    faamn
+ * Signature: ()[[F
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_faamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    daamn
+ * Signature: ()[[D
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_daamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    oaamn
+ * Signature: ()[[Ljava/lang/Object;
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_oaamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    taamn
+ * Signature: ()[[Ljava/lang/String;
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_taamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    gaamn
+ * Signature: ()[Ljava/util/List;
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_gaamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    bmn1
+ * Signature: ()B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_bmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    smn1
+ * Signature: ()S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_smn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    imn1
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_imn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    lmn1
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_lmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    fmn1
+ * Signature: ()F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_fmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    dmn1
+ * Signature: ()D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_dmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    omn1
+ * Signature: ()Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_omn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    tmn1
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_tmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    gmn1
+ * Signature: ()Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_gmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    vmn1
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_vmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    bmn2
+ * Signature: (I)B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_bmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    smn2
+ * Signature: (I)S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_smn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    imn2
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_imn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    lmn2
+ * Signature: (I)J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_lmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    fmn2
+ * Signature: (I)F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_fmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    dmn2
+ * Signature: (I)D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_dmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    omn2
+ * Signature: (I)Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_omn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    tmn2
+ * Signature: (I)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_tmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    gmn2
+ * Signature: (I)Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_gmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    vmn2
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_vmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    mbn
+ * Signature: (B)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_mbn
+  (JNIEnv *, jobject, jbyte);
+
+/*
+ * Class:     TestClass1
+ * Method:    msn
+ * Signature: (S)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_msn
+  (JNIEnv *, jobject, jshort);
+
+/*
+ * Class:     TestClass1
+ * Method:    min
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_min
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    mln
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_mln
+  (JNIEnv *, jobject, jlong);
+
+/*
+ * Class:     TestClass1
+ * Method:    mfn
+ * Signature: (F)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_mfn
+  (JNIEnv *, jobject, jfloat);
+
+/*
+ * Class:     TestClass1
+ * Method:    mdn
+ * Signature: (D)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_mdn
+  (JNIEnv *, jobject, jdouble);
+
+/*
+ * Class:     TestClass1
+ * Method:    mon
+ * Signature: (Ljava/lang/Object;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_mon
+  (JNIEnv *, jobject, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    mtn
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_mtn
+  (JNIEnv *, jobject, jstring);
+
+/*
+ * Class:     TestClass1
+ * Method:    mgn
+ * Signature: (Ljava/util/List;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_mgn
+  (JNIEnv *, jobject, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javah/6572945/gold/jni.dir.1/TestClass1_Inner1.h	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,337 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class TestClass1_Inner1 */
+
+#ifndef _Included_TestClass1_Inner1
+#define _Included_TestClass1_Inner1
+#ifdef __cplusplus
+extern "C" {
+#endif
+#undef TestClass1_Inner1_bc
+#define TestClass1_Inner1_bc 0L
+#undef TestClass1_Inner1_sc
+#define TestClass1_Inner1_sc 0L
+#undef TestClass1_Inner1_ic
+#define TestClass1_Inner1_ic 0L
+#undef TestClass1_Inner1_lc
+#define TestClass1_Inner1_lc 0LL
+#undef TestClass1_Inner1_fc
+#define TestClass1_Inner1_fc 0.0f
+#undef TestClass1_Inner1_dc
+#define TestClass1_Inner1_dc 0.0
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    bmn
+ * Signature: ()B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_00024Inner1_bmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    smn
+ * Signature: ()S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_00024Inner1_smn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    imn
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_00024Inner1_imn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    lmn
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_00024Inner1_lmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    fmn
+ * Signature: ()F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_00024Inner1_fmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    dmn
+ * Signature: ()D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_00024Inner1_dmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    omn
+ * Signature: ()Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner1_omn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    tmn
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_00024Inner1_tmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    gmn
+ * Signature: ()Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner1_gmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    vmn
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_vmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    bmn1
+ * Signature: ()B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_00024Inner1_bmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    smn1
+ * Signature: ()S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_00024Inner1_smn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    imn1
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_00024Inner1_imn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    lmn1
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_00024Inner1_lmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    fmn1
+ * Signature: ()F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_00024Inner1_fmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    dmn1
+ * Signature: ()D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_00024Inner1_dmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    omn1
+ * Signature: ()Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner1_omn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    tmn1
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_00024Inner1_tmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    gmn1
+ * Signature: ()Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner1_gmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    vmn1
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_vmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    bmn2
+ * Signature: (I)B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_00024Inner1_bmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    smn2
+ * Signature: (I)S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_00024Inner1_smn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    imn2
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_00024Inner1_imn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    lmn2
+ * Signature: (I)J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_00024Inner1_lmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    fmn2
+ * Signature: (I)F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_00024Inner1_fmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    dmn2
+ * Signature: (I)D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_00024Inner1_dmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    omn2
+ * Signature: (I)Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner1_omn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    tmn2
+ * Signature: (I)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_00024Inner1_tmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    gmn2
+ * Signature: (I)Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner1_gmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    vmn2
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_vmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    mbn
+ * Signature: (B)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_mbn
+  (JNIEnv *, jobject, jbyte);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    msn
+ * Signature: (S)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_msn
+  (JNIEnv *, jobject, jshort);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    min
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_min
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    mln
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_mln
+  (JNIEnv *, jobject, jlong);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    mfn
+ * Signature: (F)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_mfn
+  (JNIEnv *, jobject, jfloat);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    mdn
+ * Signature: (D)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_mdn
+  (JNIEnv *, jobject, jdouble);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    mon
+ * Signature: (Ljava/lang/Object;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_mon
+  (JNIEnv *, jobject, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    mtn
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_mtn
+  (JNIEnv *, jobject, jstring);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    mgn
+ * Signature: (Ljava/util/List;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_mgn
+  (JNIEnv *, jobject, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javah/6572945/gold/jni.dir.1/TestClass1_Inner2.h	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,337 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class TestClass1_Inner2 */
+
+#ifndef _Included_TestClass1_Inner2
+#define _Included_TestClass1_Inner2
+#ifdef __cplusplus
+extern "C" {
+#endif
+#undef TestClass1_Inner2_bc
+#define TestClass1_Inner2_bc 0L
+#undef TestClass1_Inner2_sc
+#define TestClass1_Inner2_sc 0L
+#undef TestClass1_Inner2_ic
+#define TestClass1_Inner2_ic 0L
+#undef TestClass1_Inner2_lc
+#define TestClass1_Inner2_lc 0LL
+#undef TestClass1_Inner2_fc
+#define TestClass1_Inner2_fc 0.0f
+#undef TestClass1_Inner2_dc
+#define TestClass1_Inner2_dc 0.0
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    bmn
+ * Signature: ()B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_00024Inner2_bmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    smn
+ * Signature: ()S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_00024Inner2_smn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    imn
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_00024Inner2_imn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    lmn
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_00024Inner2_lmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    fmn
+ * Signature: ()F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_00024Inner2_fmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    dmn
+ * Signature: ()D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_00024Inner2_dmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    omn
+ * Signature: ()Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner2_omn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    tmn
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_00024Inner2_tmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    gmn
+ * Signature: ()Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner2_gmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    vmn
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_vmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    bmn1
+ * Signature: ()B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_00024Inner2_bmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    smn1
+ * Signature: ()S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_00024Inner2_smn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    imn1
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_00024Inner2_imn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    lmn1
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_00024Inner2_lmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    fmn1
+ * Signature: ()F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_00024Inner2_fmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    dmn1
+ * Signature: ()D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_00024Inner2_dmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    omn1
+ * Signature: ()Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner2_omn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    tmn1
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_00024Inner2_tmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    gmn1
+ * Signature: ()Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner2_gmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    vmn1
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_vmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    bmn2
+ * Signature: (I)B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_00024Inner2_bmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    smn2
+ * Signature: (I)S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_00024Inner2_smn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    imn2
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_00024Inner2_imn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    lmn2
+ * Signature: (I)J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_00024Inner2_lmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    fmn2
+ * Signature: (I)F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_00024Inner2_fmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    dmn2
+ * Signature: (I)D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_00024Inner2_dmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    omn2
+ * Signature: (I)Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner2_omn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    tmn2
+ * Signature: (I)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_00024Inner2_tmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    gmn2
+ * Signature: (I)Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner2_gmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    vmn2
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_vmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    mbn
+ * Signature: (B)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_mbn
+  (JNIEnv *, jobject, jbyte);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    msn
+ * Signature: (S)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_msn
+  (JNIEnv *, jobject, jshort);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    min
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_min
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    mln
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_mln
+  (JNIEnv *, jobject, jlong);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    mfn
+ * Signature: (F)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_mfn
+  (JNIEnv *, jobject, jfloat);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    mdn
+ * Signature: (D)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_mdn
+  (JNIEnv *, jobject, jdouble);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    mon
+ * Signature: (Ljava/lang/Object;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_mon
+  (JNIEnv *, jobject, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    mtn
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_mtn
+  (JNIEnv *, jobject, jstring);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    mgn
+ * Signature: (Ljava/util/List;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_mgn
+  (JNIEnv *, jobject, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javah/6572945/gold/jni.dir.1/TestClass2.h	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,13 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class TestClass2 */
+
+#ifndef _Included_TestClass2
+#define _Included_TestClass2
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifdef __cplusplus
+}
+#endif
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javah/6572945/gold/jni.file.1	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,1151 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class TestClass1 */
+
+#ifndef _Included_TestClass1
+#define _Included_TestClass1
+#ifdef __cplusplus
+extern "C" {
+#endif
+#undef TestClass1_bc
+#define TestClass1_bc 0L
+#undef TestClass1_sc
+#define TestClass1_sc 0L
+#undef TestClass1_ic
+#define TestClass1_ic 0L
+#undef TestClass1_lc
+#define TestClass1_lc 0LL
+#undef TestClass1_fc
+#define TestClass1_fc 0.0f
+#undef TestClass1_dc
+#define TestClass1_dc 0.0
+/*
+ * Class:     TestClass1
+ * Method:    bmn
+ * Signature: ()B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_bmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    smn
+ * Signature: ()S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_smn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    imn
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_imn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    lmn
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_lmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    fmn
+ * Signature: ()F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_fmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    dmn
+ * Signature: ()D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_dmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    omn
+ * Signature: ()Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_omn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    tmn
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_tmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    gmn
+ * Signature: ()Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_gmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    vmn
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_vmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    bamn
+ * Signature: ()[B
+ */
+JNIEXPORT jbyteArray JNICALL Java_TestClass1_bamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    samn
+ * Signature: ()[S
+ */
+JNIEXPORT jshortArray JNICALL Java_TestClass1_samn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    iamn
+ * Signature: ()[I
+ */
+JNIEXPORT jintArray JNICALL Java_TestClass1_iamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    lamn
+ * Signature: ()[J
+ */
+JNIEXPORT jlongArray JNICALL Java_TestClass1_lamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    famn
+ * Signature: ()[F
+ */
+JNIEXPORT jfloatArray JNICALL Java_TestClass1_famn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    damn
+ * Signature: ()[D
+ */
+JNIEXPORT jdoubleArray JNICALL Java_TestClass1_damn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    oamn
+ * Signature: ()[Ljava/lang/Object;
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_oamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    tamn
+ * Signature: ()[Ljava/lang/String;
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_tamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    gamn
+ * Signature: ()[Ljava/util/List;
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_gamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    baamn
+ * Signature: ()[[B
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_baamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    saamn
+ * Signature: ()[[S
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_saamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    iaamn
+ * Signature: ()[[I
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_iaamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    laamn
+ * Signature: ()[[J
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_laamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    faamn
+ * Signature: ()[[F
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_faamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    daamn
+ * Signature: ()[[D
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_daamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    oaamn
+ * Signature: ()[[Ljava/lang/Object;
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_oaamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    taamn
+ * Signature: ()[[Ljava/lang/String;
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_taamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    gaamn
+ * Signature: ()[Ljava/util/List;
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_gaamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    bmn1
+ * Signature: ()B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_bmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    smn1
+ * Signature: ()S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_smn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    imn1
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_imn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    lmn1
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_lmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    fmn1
+ * Signature: ()F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_fmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    dmn1
+ * Signature: ()D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_dmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    omn1
+ * Signature: ()Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_omn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    tmn1
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_tmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    gmn1
+ * Signature: ()Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_gmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    vmn1
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_vmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    bmn2
+ * Signature: (I)B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_bmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    smn2
+ * Signature: (I)S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_smn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    imn2
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_imn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    lmn2
+ * Signature: (I)J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_lmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    fmn2
+ * Signature: (I)F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_fmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    dmn2
+ * Signature: (I)D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_dmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    omn2
+ * Signature: (I)Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_omn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    tmn2
+ * Signature: (I)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_tmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    gmn2
+ * Signature: (I)Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_gmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    vmn2
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_vmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    mbn
+ * Signature: (B)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_mbn
+  (JNIEnv *, jobject, jbyte);
+
+/*
+ * Class:     TestClass1
+ * Method:    msn
+ * Signature: (S)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_msn
+  (JNIEnv *, jobject, jshort);
+
+/*
+ * Class:     TestClass1
+ * Method:    min
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_min
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    mln
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_mln
+  (JNIEnv *, jobject, jlong);
+
+/*
+ * Class:     TestClass1
+ * Method:    mfn
+ * Signature: (F)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_mfn
+  (JNIEnv *, jobject, jfloat);
+
+/*
+ * Class:     TestClass1
+ * Method:    mdn
+ * Signature: (D)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_mdn
+  (JNIEnv *, jobject, jdouble);
+
+/*
+ * Class:     TestClass1
+ * Method:    mon
+ * Signature: (Ljava/lang/Object;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_mon
+  (JNIEnv *, jobject, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    mtn
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_mtn
+  (JNIEnv *, jobject, jstring);
+
+/*
+ * Class:     TestClass1
+ * Method:    mgn
+ * Signature: (Ljava/util/List;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_mgn
+  (JNIEnv *, jobject, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
+/* Header for class TestClass1_Inner2 */
+
+#ifndef _Included_TestClass1_Inner2
+#define _Included_TestClass1_Inner2
+#ifdef __cplusplus
+extern "C" {
+#endif
+#undef TestClass1_Inner2_bc
+#define TestClass1_Inner2_bc 0L
+#undef TestClass1_Inner2_sc
+#define TestClass1_Inner2_sc 0L
+#undef TestClass1_Inner2_ic
+#define TestClass1_Inner2_ic 0L
+#undef TestClass1_Inner2_lc
+#define TestClass1_Inner2_lc 0LL
+#undef TestClass1_Inner2_fc
+#define TestClass1_Inner2_fc 0.0f
+#undef TestClass1_Inner2_dc
+#define TestClass1_Inner2_dc 0.0
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    bmn
+ * Signature: ()B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_00024Inner2_bmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    smn
+ * Signature: ()S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_00024Inner2_smn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    imn
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_00024Inner2_imn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    lmn
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_00024Inner2_lmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    fmn
+ * Signature: ()F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_00024Inner2_fmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    dmn
+ * Signature: ()D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_00024Inner2_dmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    omn
+ * Signature: ()Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner2_omn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    tmn
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_00024Inner2_tmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    gmn
+ * Signature: ()Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner2_gmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    vmn
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_vmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    bmn1
+ * Signature: ()B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_00024Inner2_bmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    smn1
+ * Signature: ()S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_00024Inner2_smn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    imn1
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_00024Inner2_imn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    lmn1
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_00024Inner2_lmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    fmn1
+ * Signature: ()F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_00024Inner2_fmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    dmn1
+ * Signature: ()D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_00024Inner2_dmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    omn1
+ * Signature: ()Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner2_omn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    tmn1
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_00024Inner2_tmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    gmn1
+ * Signature: ()Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner2_gmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    vmn1
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_vmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    bmn2
+ * Signature: (I)B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_00024Inner2_bmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    smn2
+ * Signature: (I)S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_00024Inner2_smn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    imn2
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_00024Inner2_imn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    lmn2
+ * Signature: (I)J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_00024Inner2_lmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    fmn2
+ * Signature: (I)F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_00024Inner2_fmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    dmn2
+ * Signature: (I)D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_00024Inner2_dmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    omn2
+ * Signature: (I)Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner2_omn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    tmn2
+ * Signature: (I)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_00024Inner2_tmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    gmn2
+ * Signature: (I)Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner2_gmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    vmn2
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_vmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    mbn
+ * Signature: (B)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_mbn
+  (JNIEnv *, jobject, jbyte);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    msn
+ * Signature: (S)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_msn
+  (JNIEnv *, jobject, jshort);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    min
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_min
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    mln
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_mln
+  (JNIEnv *, jobject, jlong);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    mfn
+ * Signature: (F)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_mfn
+  (JNIEnv *, jobject, jfloat);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    mdn
+ * Signature: (D)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_mdn
+  (JNIEnv *, jobject, jdouble);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    mon
+ * Signature: (Ljava/lang/Object;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_mon
+  (JNIEnv *, jobject, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    mtn
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_mtn
+  (JNIEnv *, jobject, jstring);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    mgn
+ * Signature: (Ljava/util/List;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_mgn
+  (JNIEnv *, jobject, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
+/* Header for class TestClass1_Inner1 */
+
+#ifndef _Included_TestClass1_Inner1
+#define _Included_TestClass1_Inner1
+#ifdef __cplusplus
+extern "C" {
+#endif
+#undef TestClass1_Inner1_bc
+#define TestClass1_Inner1_bc 0L
+#undef TestClass1_Inner1_sc
+#define TestClass1_Inner1_sc 0L
+#undef TestClass1_Inner1_ic
+#define TestClass1_Inner1_ic 0L
+#undef TestClass1_Inner1_lc
+#define TestClass1_Inner1_lc 0LL
+#undef TestClass1_Inner1_fc
+#define TestClass1_Inner1_fc 0.0f
+#undef TestClass1_Inner1_dc
+#define TestClass1_Inner1_dc 0.0
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    bmn
+ * Signature: ()B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_00024Inner1_bmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    smn
+ * Signature: ()S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_00024Inner1_smn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    imn
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_00024Inner1_imn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    lmn
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_00024Inner1_lmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    fmn
+ * Signature: ()F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_00024Inner1_fmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    dmn
+ * Signature: ()D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_00024Inner1_dmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    omn
+ * Signature: ()Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner1_omn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    tmn
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_00024Inner1_tmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    gmn
+ * Signature: ()Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner1_gmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    vmn
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_vmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    bmn1
+ * Signature: ()B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_00024Inner1_bmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    smn1
+ * Signature: ()S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_00024Inner1_smn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    imn1
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_00024Inner1_imn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    lmn1
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_00024Inner1_lmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    fmn1
+ * Signature: ()F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_00024Inner1_fmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    dmn1
+ * Signature: ()D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_00024Inner1_dmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    omn1
+ * Signature: ()Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner1_omn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    tmn1
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_00024Inner1_tmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    gmn1
+ * Signature: ()Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner1_gmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    vmn1
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_vmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    bmn2
+ * Signature: (I)B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_00024Inner1_bmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    smn2
+ * Signature: (I)S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_00024Inner1_smn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    imn2
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_00024Inner1_imn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    lmn2
+ * Signature: (I)J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_00024Inner1_lmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    fmn2
+ * Signature: (I)F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_00024Inner1_fmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    dmn2
+ * Signature: (I)D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_00024Inner1_dmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    omn2
+ * Signature: (I)Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner1_omn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    tmn2
+ * Signature: (I)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_00024Inner1_tmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    gmn2
+ * Signature: (I)Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner1_gmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    vmn2
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_vmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    mbn
+ * Signature: (B)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_mbn
+  (JNIEnv *, jobject, jbyte);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    msn
+ * Signature: (S)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_msn
+  (JNIEnv *, jobject, jshort);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    min
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_min
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    mln
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_mln
+  (JNIEnv *, jobject, jlong);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    mfn
+ * Signature: (F)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_mfn
+  (JNIEnv *, jobject, jfloat);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    mdn
+ * Signature: (D)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_mdn
+  (JNIEnv *, jobject, jdouble);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    mon
+ * Signature: (Ljava/lang/Object;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_mon
+  (JNIEnv *, jobject, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    mtn
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_mtn
+  (JNIEnv *, jobject, jstring);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    mgn
+ * Signature: (Ljava/util/List;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_mgn
+  (JNIEnv *, jobject, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javah/6572945/gold/jni.file.2	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,1162 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class TestClass1 */
+
+#ifndef _Included_TestClass1
+#define _Included_TestClass1
+#ifdef __cplusplus
+extern "C" {
+#endif
+#undef TestClass1_bc
+#define TestClass1_bc 0L
+#undef TestClass1_sc
+#define TestClass1_sc 0L
+#undef TestClass1_ic
+#define TestClass1_ic 0L
+#undef TestClass1_lc
+#define TestClass1_lc 0LL
+#undef TestClass1_fc
+#define TestClass1_fc 0.0f
+#undef TestClass1_dc
+#define TestClass1_dc 0.0
+/*
+ * Class:     TestClass1
+ * Method:    bmn
+ * Signature: ()B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_bmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    smn
+ * Signature: ()S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_smn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    imn
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_imn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    lmn
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_lmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    fmn
+ * Signature: ()F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_fmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    dmn
+ * Signature: ()D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_dmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    omn
+ * Signature: ()Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_omn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    tmn
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_tmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    gmn
+ * Signature: ()Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_gmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    vmn
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_vmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    bamn
+ * Signature: ()[B
+ */
+JNIEXPORT jbyteArray JNICALL Java_TestClass1_bamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    samn
+ * Signature: ()[S
+ */
+JNIEXPORT jshortArray JNICALL Java_TestClass1_samn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    iamn
+ * Signature: ()[I
+ */
+JNIEXPORT jintArray JNICALL Java_TestClass1_iamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    lamn
+ * Signature: ()[J
+ */
+JNIEXPORT jlongArray JNICALL Java_TestClass1_lamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    famn
+ * Signature: ()[F
+ */
+JNIEXPORT jfloatArray JNICALL Java_TestClass1_famn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    damn
+ * Signature: ()[D
+ */
+JNIEXPORT jdoubleArray JNICALL Java_TestClass1_damn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    oamn
+ * Signature: ()[Ljava/lang/Object;
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_oamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    tamn
+ * Signature: ()[Ljava/lang/String;
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_tamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    gamn
+ * Signature: ()[Ljava/util/List;
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_gamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    baamn
+ * Signature: ()[[B
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_baamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    saamn
+ * Signature: ()[[S
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_saamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    iaamn
+ * Signature: ()[[I
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_iaamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    laamn
+ * Signature: ()[[J
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_laamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    faamn
+ * Signature: ()[[F
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_faamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    daamn
+ * Signature: ()[[D
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_daamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    oaamn
+ * Signature: ()[[Ljava/lang/Object;
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_oaamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    taamn
+ * Signature: ()[[Ljava/lang/String;
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_taamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    gaamn
+ * Signature: ()[Ljava/util/List;
+ */
+JNIEXPORT jobjectArray JNICALL Java_TestClass1_gaamn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    bmn1
+ * Signature: ()B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_bmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    smn1
+ * Signature: ()S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_smn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    imn1
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_imn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    lmn1
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_lmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    fmn1
+ * Signature: ()F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_fmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    dmn1
+ * Signature: ()D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_dmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    omn1
+ * Signature: ()Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_omn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    tmn1
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_tmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    gmn1
+ * Signature: ()Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_gmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    vmn1
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_vmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    bmn2
+ * Signature: (I)B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_bmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    smn2
+ * Signature: (I)S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_smn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    imn2
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_imn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    lmn2
+ * Signature: (I)J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_lmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    fmn2
+ * Signature: (I)F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_fmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    dmn2
+ * Signature: (I)D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_dmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    omn2
+ * Signature: (I)Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_omn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    tmn2
+ * Signature: (I)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_tmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    gmn2
+ * Signature: (I)Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_gmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    vmn2
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_vmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    mbn
+ * Signature: (B)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_mbn
+  (JNIEnv *, jobject, jbyte);
+
+/*
+ * Class:     TestClass1
+ * Method:    msn
+ * Signature: (S)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_msn
+  (JNIEnv *, jobject, jshort);
+
+/*
+ * Class:     TestClass1
+ * Method:    min
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_min
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1
+ * Method:    mln
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_mln
+  (JNIEnv *, jobject, jlong);
+
+/*
+ * Class:     TestClass1
+ * Method:    mfn
+ * Signature: (F)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_mfn
+  (JNIEnv *, jobject, jfloat);
+
+/*
+ * Class:     TestClass1
+ * Method:    mdn
+ * Signature: (D)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_mdn
+  (JNIEnv *, jobject, jdouble);
+
+/*
+ * Class:     TestClass1
+ * Method:    mon
+ * Signature: (Ljava/lang/Object;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_mon
+  (JNIEnv *, jobject, jobject);
+
+/*
+ * Class:     TestClass1
+ * Method:    mtn
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_mtn
+  (JNIEnv *, jobject, jstring);
+
+/*
+ * Class:     TestClass1
+ * Method:    mgn
+ * Signature: (Ljava/util/List;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_mgn
+  (JNIEnv *, jobject, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
+/* Header for class TestClass1_Inner2 */
+
+#ifndef _Included_TestClass1_Inner2
+#define _Included_TestClass1_Inner2
+#ifdef __cplusplus
+extern "C" {
+#endif
+#undef TestClass1_Inner2_bc
+#define TestClass1_Inner2_bc 0L
+#undef TestClass1_Inner2_sc
+#define TestClass1_Inner2_sc 0L
+#undef TestClass1_Inner2_ic
+#define TestClass1_Inner2_ic 0L
+#undef TestClass1_Inner2_lc
+#define TestClass1_Inner2_lc 0LL
+#undef TestClass1_Inner2_fc
+#define TestClass1_Inner2_fc 0.0f
+#undef TestClass1_Inner2_dc
+#define TestClass1_Inner2_dc 0.0
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    bmn
+ * Signature: ()B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_00024Inner2_bmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    smn
+ * Signature: ()S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_00024Inner2_smn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    imn
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_00024Inner2_imn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    lmn
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_00024Inner2_lmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    fmn
+ * Signature: ()F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_00024Inner2_fmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    dmn
+ * Signature: ()D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_00024Inner2_dmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    omn
+ * Signature: ()Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner2_omn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    tmn
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_00024Inner2_tmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    gmn
+ * Signature: ()Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner2_gmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    vmn
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_vmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    bmn1
+ * Signature: ()B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_00024Inner2_bmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    smn1
+ * Signature: ()S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_00024Inner2_smn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    imn1
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_00024Inner2_imn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    lmn1
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_00024Inner2_lmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    fmn1
+ * Signature: ()F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_00024Inner2_fmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    dmn1
+ * Signature: ()D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_00024Inner2_dmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    omn1
+ * Signature: ()Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner2_omn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    tmn1
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_00024Inner2_tmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    gmn1
+ * Signature: ()Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner2_gmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    vmn1
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_vmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    bmn2
+ * Signature: (I)B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_00024Inner2_bmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    smn2
+ * Signature: (I)S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_00024Inner2_smn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    imn2
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_00024Inner2_imn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    lmn2
+ * Signature: (I)J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_00024Inner2_lmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    fmn2
+ * Signature: (I)F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_00024Inner2_fmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    dmn2
+ * Signature: (I)D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_00024Inner2_dmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    omn2
+ * Signature: (I)Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner2_omn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    tmn2
+ * Signature: (I)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_00024Inner2_tmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    gmn2
+ * Signature: (I)Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner2_gmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    vmn2
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_vmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    mbn
+ * Signature: (B)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_mbn
+  (JNIEnv *, jobject, jbyte);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    msn
+ * Signature: (S)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_msn
+  (JNIEnv *, jobject, jshort);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    min
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_min
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    mln
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_mln
+  (JNIEnv *, jobject, jlong);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    mfn
+ * Signature: (F)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_mfn
+  (JNIEnv *, jobject, jfloat);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    mdn
+ * Signature: (D)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_mdn
+  (JNIEnv *, jobject, jdouble);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    mon
+ * Signature: (Ljava/lang/Object;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_mon
+  (JNIEnv *, jobject, jobject);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    mtn
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_mtn
+  (JNIEnv *, jobject, jstring);
+
+/*
+ * Class:     TestClass1_Inner2
+ * Method:    mgn
+ * Signature: (Ljava/util/List;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner2_mgn
+  (JNIEnv *, jobject, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
+/* Header for class TestClass1_Inner1 */
+
+#ifndef _Included_TestClass1_Inner1
+#define _Included_TestClass1_Inner1
+#ifdef __cplusplus
+extern "C" {
+#endif
+#undef TestClass1_Inner1_bc
+#define TestClass1_Inner1_bc 0L
+#undef TestClass1_Inner1_sc
+#define TestClass1_Inner1_sc 0L
+#undef TestClass1_Inner1_ic
+#define TestClass1_Inner1_ic 0L
+#undef TestClass1_Inner1_lc
+#define TestClass1_Inner1_lc 0LL
+#undef TestClass1_Inner1_fc
+#define TestClass1_Inner1_fc 0.0f
+#undef TestClass1_Inner1_dc
+#define TestClass1_Inner1_dc 0.0
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    bmn
+ * Signature: ()B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_00024Inner1_bmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    smn
+ * Signature: ()S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_00024Inner1_smn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    imn
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_00024Inner1_imn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    lmn
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_00024Inner1_lmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    fmn
+ * Signature: ()F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_00024Inner1_fmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    dmn
+ * Signature: ()D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_00024Inner1_dmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    omn
+ * Signature: ()Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner1_omn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    tmn
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_00024Inner1_tmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    gmn
+ * Signature: ()Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner1_gmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    vmn
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_vmn
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    bmn1
+ * Signature: ()B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_00024Inner1_bmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    smn1
+ * Signature: ()S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_00024Inner1_smn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    imn1
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_00024Inner1_imn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    lmn1
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_00024Inner1_lmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    fmn1
+ * Signature: ()F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_00024Inner1_fmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    dmn1
+ * Signature: ()D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_00024Inner1_dmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    omn1
+ * Signature: ()Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner1_omn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    tmn1
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_00024Inner1_tmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    gmn1
+ * Signature: ()Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner1_gmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    vmn1
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_vmn1
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    bmn2
+ * Signature: (I)B
+ */
+JNIEXPORT jbyte JNICALL Java_TestClass1_00024Inner1_bmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    smn2
+ * Signature: (I)S
+ */
+JNIEXPORT jshort JNICALL Java_TestClass1_00024Inner1_smn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    imn2
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_TestClass1_00024Inner1_imn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    lmn2
+ * Signature: (I)J
+ */
+JNIEXPORT jlong JNICALL Java_TestClass1_00024Inner1_lmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    fmn2
+ * Signature: (I)F
+ */
+JNIEXPORT jfloat JNICALL Java_TestClass1_00024Inner1_fmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    dmn2
+ * Signature: (I)D
+ */
+JNIEXPORT jdouble JNICALL Java_TestClass1_00024Inner1_dmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    omn2
+ * Signature: (I)Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner1_omn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    tmn2
+ * Signature: (I)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_TestClass1_00024Inner1_tmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    gmn2
+ * Signature: (I)Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_TestClass1_00024Inner1_gmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    vmn2
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_vmn2
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    mbn
+ * Signature: (B)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_mbn
+  (JNIEnv *, jobject, jbyte);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    msn
+ * Signature: (S)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_msn
+  (JNIEnv *, jobject, jshort);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    min
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_min
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    mln
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_mln
+  (JNIEnv *, jobject, jlong);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    mfn
+ * Signature: (F)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_mfn
+  (JNIEnv *, jobject, jfloat);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    mdn
+ * Signature: (D)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_mdn
+  (JNIEnv *, jobject, jdouble);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    mon
+ * Signature: (Ljava/lang/Object;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_mon
+  (JNIEnv *, jobject, jobject);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    mtn
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_mtn
+  (JNIEnv *, jobject, jstring);
+
+/*
+ * Class:     TestClass1_Inner1
+ * Method:    mgn
+ * Signature: (Ljava/util/List;)V
+ */
+JNIEXPORT void JNICALL Java_TestClass1_00024Inner1_mgn
+  (JNIEnv *, jobject, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
+/* Header for class TestClass2 */
+
+#ifndef _Included_TestClass2
+#define _Included_TestClass2
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifdef __cplusplus
+}
+#endif
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javah/6572945/gold/jni.file.3	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,79 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class TestClass3 */
+
+#ifndef _Included_TestClass3
+#define _Included_TestClass3
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifdef __cplusplus
+}
+#endif
+#endif
+/* Header for class TestClass3_Inner2 */
+
+#ifndef _Included_TestClass3_Inner2
+#define _Included_TestClass3_Inner2
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifdef __cplusplus
+}
+#endif
+#endif
+/* Header for class TestClass3_Inner2_Inner2B */
+
+#ifndef _Included_TestClass3_Inner2_Inner2B
+#define _Included_TestClass3_Inner2_Inner2B
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifdef __cplusplus
+}
+#endif
+#endif
+/* Header for class TestClass3_Inner2_Inner2A */
+
+#ifndef _Included_TestClass3_Inner2_Inner2A
+#define _Included_TestClass3_Inner2_Inner2A
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifdef __cplusplus
+}
+#endif
+#endif
+/* Header for class TestClass3_Inner1 */
+
+#ifndef _Included_TestClass3_Inner1
+#define _Included_TestClass3_Inner1
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifdef __cplusplus
+}
+#endif
+#endif
+/* Header for class TestClass3_Inner1_Inner1B */
+
+#ifndef _Included_TestClass3_Inner1_Inner1B
+#define _Included_TestClass3_Inner1_Inner1B
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifdef __cplusplus
+}
+#endif
+#endif
+/* Header for class TestClass3_Inner1_Inner1A */
+
+#ifndef _Included_TestClass3_Inner1_Inner1A
+#define _Included_TestClass3_Inner1_Inner1A
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifdef __cplusplus
+}
+#endif
+#endif
--- a/langtools/test/tools/javah/MissingParamClassTest.sh	Fri Oct 16 09:32:29 2009 -0700
+++ b/langtools/test/tools/javah/MissingParamClassTest.sh	Fri Oct 16 18:02:31 2009 -0700
@@ -77,10 +77,7 @@
 rm -f ParamClassTest.class MissingParamClassException.class ParamClassTest.h
 rm -f ${TMP1}
 
-cp ${TESTSRC}${FS}ParamClassTest.java .
-cp ${TESTSRC}${FS}MissingParamClassException.java .
-
-"${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d . "${TESTSRC}${FS}ParamClassTest.java"
+"${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d . "${TESTSRC}${FS}ParamClassTest.java" "${TESTSRC}${FS}MissingParamClassException.java"
 
 # Before running javah remove dependent class file
 rm -f MissingParamClassException.class 
@@ -88,15 +85,12 @@
 "${TESTJAVA}${FS}bin${FS}javah" ${TESTTOOLVMOPTS} ParamClassTest 2>${TMP1}
 
 if [ -f $GENERATED_HEADER_FILE ]; then
-     echo "Failed"
-     exit 1
+     echo "1-- Failed: $GENERATED_HEADER_FILE found"
+     rc=1
 fi
-if [ ! -f ${TMP1} ]; then
-     echo "Failed"
-     exit 1
-else
-     echo "Passed"
-     exit 0
+if [ ! -s ${TMP1} ]; then
+     echo "1-- Failed: ${TMP1} is empty"
+     rc=1
 fi
 
 # Clean out work dir
@@ -104,7 +98,9 @@
 rm -f $GENERATED_HEADER_FILE $TMP1 
 
 # Re-compile everything
-"${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS}  -d . ${TESTSRC}${FS}ParamClassTest.java
+
+"${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d . "${TESTSRC}${FS}ParamClassTest.java" "${TESTSRC}${FS}MissingParamClassException.java"
+
 
 # Before re-run of javah remove dependent class file Param.class 
 rm -f Param.class
@@ -112,13 +108,17 @@
 "${TESTJAVA}${FS}bin${FS}javah" ${TESTTOOLVMOPTS} ParamClassTest 2>${TMP1}
 
 if [ -f $GENERATED_HEADER_FILE ]; then
-     echo "Failed"
-     exit 1
+     echo "2-- Failed: $GENERATED_HEADER_FILE found"
+     rc=1
+fi
+if [ ! -s ${TMP1} ]; then
+     echo "2-- Failed: ${TMP1} is empty"
+     rc=1
 fi
-if [ ! -f ${TMP1} ]; then
-     echo "Failed"
-     exit 1
+
+if [ "$rc" = "" ]; then
+    echo Passed
 else
-     echo "Passed"
-     exit 0
+    echo Failed
+    exit 1
 fi
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javah/compareTest/CompareTest.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,265 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+import java.io.DataInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import com.sun.tools.classfile.AccessFlags;
+import com.sun.tools.classfile.ClassFile;
+import com.sun.tools.classfile.ConstantPoolException;
+import com.sun.tools.classfile.Method;
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.util.LinkedHashSet;
+
+public class CompareTest {
+    String[][] testCases = {
+        { },
+        { "-jni" },
+//        { "-llni" },
+    };
+
+    public static void main(String... args) throws Exception {
+        new CompareTest().run(args);
+    }
+
+    public void run(String... args) throws Exception {
+        old_javah_cmd = new File(args[0]);
+        rt_jar = new File(args[1]);
+
+        Set<String> testClasses;
+        if (args.length > 2) {
+            testClasses = new LinkedHashSet<String>(Arrays.asList(Arrays.copyOfRange(args, 2, args.length)));
+        } else
+            testClasses = getNativeClasses(new JarFile(rt_jar));
+
+        for (String[] options: testCases) {
+            for (String name: testClasses) {
+                test(Arrays.asList(options), rt_jar, name);
+            }
+        }
+
+        if (errors == 0)
+            System.out.println(count + " tests passed");
+        else
+            throw new Exception(errors + "/" + count + " tests failed");
+    }
+
+    public void test(List<String> options, File bootclasspath, String className)
+            throws IOException, InterruptedException {
+        System.err.println("test: " + options + " " + className);
+        count++;
+
+        testOptions = options;
+        testClassName = className;
+
+        File oldOutDir = initDir(file(new File("old"), className));
+        int old_rc = old_javah(options, oldOutDir, bootclasspath, className);
+
+        File newOutDir = initDir(file(new File("new"), className));
+        int new_rc = new_javah(options, newOutDir, bootclasspath, className);
+
+        if (old_rc != new_rc)
+            error("return codes differ; old: " + old_rc + ", new: " + new_rc);
+
+        compare(oldOutDir, newOutDir);
+    }
+
+    int old_javah(List<String> options, File outDir, File bootclasspath, String className)
+            throws IOException, InterruptedException {
+        List<String> cmd = new ArrayList<String>();
+        cmd.add(old_javah_cmd.getPath());
+        cmd.addAll(options);
+        cmd.add("-d");
+        cmd.add(outDir.getPath());
+        cmd.add("-bootclasspath");
+        cmd.add(bootclasspath.getPath());
+        cmd.add(className);
+        System.err.println("old_javah: " + cmd);
+        ProcessBuilder pb = new ProcessBuilder(cmd);
+        pb.redirectErrorStream(true);
+        Process p = pb.start();
+        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
+        String line;
+        StringBuilder sb = new StringBuilder();
+        while ((line = in.readLine()) != null) {
+            sb.append(line);
+            sb.append("\n");
+        }
+        System.err.println("old javah out: " + sb.toString());
+        return p.waitFor();
+    }
+
+    int new_javah(List<String> options, File outDir, File bootclasspath, String className) {
+        List<String> args = new ArrayList<String>();
+        args.addAll(options);
+        args.add("-d");
+        args.add(outDir.getPath());
+        args.add("-bootclasspath");
+        args.add(bootclasspath.getPath());
+        args.add(className);
+        StringWriter sw = new StringWriter();
+        PrintWriter pw = new PrintWriter(sw);
+        int rc = com.sun.tools.javah.Main.run(args.toArray(new String[args.size()]), pw);
+        pw.close();
+        System.err.println("new javah out: " + sw.toString());
+        return rc;
+    }
+
+    Set<String> getNativeClasses(JarFile jar) throws IOException, ConstantPoolException {
+        System.err.println("getNativeClasses: " + jar.getName());
+        Set<String> results = new TreeSet<String>();
+        Enumeration<JarEntry> e = jar.entries();
+        while (e.hasMoreElements()) {
+            JarEntry je = e.nextElement();
+            if (isNativeClass(jar, je)) {
+                String name = je.getName();
+                results.add(name.substring(0, name.length() - 6).replace("/", "."));
+            }
+        }
+        return results;
+    }
+
+    boolean isNativeClass(JarFile jar, JarEntry entry) throws IOException, ConstantPoolException {
+        String name = entry.getName();
+        if (name.startsWith("META-INF") || !name.endsWith(".class"))
+            return false;
+        //String className = name.substring(0, name.length() - 6).replace("/", ".");
+        //System.err.println("check " + className);
+        InputStream in = jar.getInputStream(entry);
+        ClassFile cf = ClassFile.read(in);
+        for (int i = 0; i < cf.methods.length; i++) {
+            Method m = cf.methods[i];
+            if (m.access_flags.is(AccessFlags.ACC_NATIVE)) {
+                // System.err.println(className);
+                return true;
+            }
+        }
+        return false;
+    }
+
+    void compare(File f1, File f2) throws IOException {
+        if (f1.isFile() && f2.isFile())
+            compareFiles(f1, f2);
+        else if (f1.isDirectory() && f2.isDirectory())
+            compareDirectories(f1, f2);
+        else
+            error("files differ: "
+                + f1 + " (" + getFileType(f1) + "), "
+                + f2 + " (" + getFileType(f2) + ")");
+    }
+
+    void compareDirectories(File d1, File d2) throws IOException {
+        Set<String> list = new TreeSet<String>();
+        list.addAll(Arrays.asList(d1.list()));
+        list.addAll(Arrays.asList(d2.list()));
+        for (String c: list)
+            compare(new File(d1, c), new File(d2, c));
+    }
+
+    void compareFiles(File f1, File f2) throws IOException {
+        byte[] c1 = readFile(f1);
+        byte[] c2 = readFile(f2);
+        if (!Arrays.equals(c1, c2))
+            error("files differ: " + f1 + ", " + f2);
+    }
+
+    byte[] readFile(File file) throws IOException {
+        int size = (int) file.length();
+        byte[] data = new byte[size];
+        DataInputStream in = new DataInputStream(new FileInputStream(file));
+        try {
+            in.readFully(data);
+        } finally {
+            in.close();
+        }
+        return data;
+    }
+
+    String getFileType(File f) {
+        return f.isDirectory() ? "directory"
+                : f.isFile() ? "file"
+                : f.exists() ? "other"
+                : "not found";
+    }
+
+    /**
+     * Set up an empty directory.
+     */
+    public File initDir(File dir) {
+        if (dir.exists())
+            deleteAll(dir);
+        dir.mkdirs();
+        return dir;
+    }
+
+    /**
+     * Delete a file or a directory (including all its contents).
+     */
+    boolean deleteAll(File file) {
+        if (file.isDirectory()) {
+            for (File f: file.listFiles())
+                deleteAll(f);
+        }
+        return file.delete();
+    }
+
+    File file(File dir, String... path) {
+        File f = dir;
+        for (String p: path)
+            f = new File(f, p);
+        return f;
+    }
+
+    /**
+     * Report an error.
+     */
+    void error(String msg, String... more) {
+        System.err.println("test: " + testOptions + " " + testClassName);
+        System.err.println("error: " + msg);
+        for (String s: more)
+            System.err.println(s);
+        errors++;
+        System.exit(1);
+    }
+
+    File old_javah_cmd;
+    File rt_jar;
+    List<String> testOptions;
+    String testClassName;
+    int count;
+    int errors;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javah/compareTest/CompareTest.sh	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,43 @@
+#!/bin/sh
+#
+# Copyright 2009 Sun Microsystems, Inc.  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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+# CA 95054 USA or visit www.sun.com if you need additional information or
+# have any questions.
+#
+
+jdk=${1:-/opt/jdk/1.6.0}
+javah=${jdk}/bin/javah
+rtjar=${jdk}/jre/lib/rt.jar
+
+# compile test
+mkdir -p build/compareTest
+/opt/jdk/1.7.0/bin/javac -classpath build/classes -d build/compareTest test/tools/javah/compareTest/*.java
+
+# run test
+/opt/jdk/1.7.0/bin/java -classpath build/compareTest:build/classes CompareTest $javah $rtjar 2>&1 | tee CompareTest.out
+
+# show diffs for tests that failed
+grep 'error:' CompareTest.out | sed -e 's|.*new/||' -e 's/\.h$//' -e 's|_|.|g' > CompareTest.classes.fail
+
+for i in $(cat CompareTest.classes.fail) ; do 
+	/opt/jdk/1.7.0/bin/java -classpath compareTest:build/classes CompareTest $javah $rtjar $i 
+	diff -r old new 
+done 
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javah/compareTest/FindNativeFiles.java	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Enumeration;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import com.sun.tools.classfile.AccessFlags;
+import com.sun.tools.classfile.ClassFile;
+import com.sun.tools.classfile.ConstantPoolException;
+import com.sun.tools.classfile.Method;
+import java.util.Comparator;
+import java.util.Set;
+import java.util.TreeSet;
+
+public class FindNativeFiles {
+    public static void main(String[] args) throws IOException, ConstantPoolException {
+        new FindNativeFiles().run(args);
+    }
+
+    public void run(String[] args) throws IOException, ConstantPoolException {
+        JarFile jar = new JarFile(args[0]);
+        Set<JarEntry> entries = getNativeClasses(jar);
+        for (JarEntry e: entries) {
+            String name = e.getName();
+            String className = name.substring(0, name.length() - 6).replace("/", ".");
+            System.out.println(className);
+        }
+    }
+
+    Set<JarEntry> getNativeClasses(JarFile jar) throws IOException, ConstantPoolException {
+        Set<JarEntry> results = new TreeSet<JarEntry>(new Comparator<JarEntry>() {
+            public int compare(JarEntry o1, JarEntry o2) {
+                return o1.getName().compareTo(o2.getName());
+            }
+        });
+        Enumeration<JarEntry> e = jar.entries();
+        while (e.hasMoreElements()) {
+            JarEntry je = e.nextElement();
+            if (isNativeClass(jar, je))
+                results.add(je);
+        }
+        return results;
+    }
+
+    boolean isNativeClass(JarFile jar, JarEntry entry) throws IOException, ConstantPoolException {
+        String name = entry.getName();
+        if (name.startsWith("META-INF") || !name.endsWith(".class"))
+            return false;
+        //String className = name.substring(0, name.length() - 6).replace("/", ".");
+        //System.err.println("check " + className);
+        InputStream in = jar.getInputStream(entry);
+        ClassFile cf = ClassFile.read(in);
+        in.close();
+        for (int i = 0; i < cf.methods.length; i++) {
+            Method m = cf.methods[i];
+            if (m.access_flags.is(AccessFlags.ACC_NATIVE)) {
+                // System.err.println(className);
+                return true;
+            }
+        }
+        return false;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javah/compareTest/README	Fri Oct 16 18:02:31 2009 -0700
@@ -0,0 +1,16 @@
+test/tools/javah/compareTest/README
+
+This directory contains a program for comparing the output of new javah against the
+output of JDK 6 or other older versions of javah.
+
+It cannot be run automatically because of the need for the older version of javah
+to compare against.
+
+The test works by scanning a jar file, such as rt.jar, looking for all files with
+native methods.  It then runs both the old and new versions of javah on those
+classes with native methods, and verifies that the results are character-for-character
+identical.
+
+To run the test, build langtools, then execute the script in the root langtools 
+directory, providing the location of the JDK to be tested. The default is
+/opt/jdk/1.6.0.