jdk/src/share/classes/com/sun/java/util/jar/pack/NativeUnpack.java

Print this page
rev 5675 : 7186946: Refine unpacker resource usage
Reviewed-by: jrose, jjh, mschoene
   1 /*
   2  * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  85 
  86     static {
  87         // If loading from stand alone build uncomment this.
  88         // System.loadLibrary("unpack");
  89         java.security.AccessController.doPrivileged(
  90                 new sun.security.action.LoadLibraryAction("unpack"));
  91         initIDs();
  92     }
  93 
  94     NativeUnpack(UnpackerImpl p200) {
  95         super();
  96         _p200  = p200;
  97         _props = p200.props;
  98         p200._nunp = this;
  99     }
 100 
 101     // for JNI callbacks
 102     static private Object currentInstance() {
 103         UnpackerImpl p200 = (UnpackerImpl) Utils.getTLGlobals();
 104         return (p200 == null)? null: p200._nunp;




 105     }
 106 
 107     // Callback from the unpacker engine to get more data.
 108     private long readInputFn(ByteBuffer pbuf, long minlen) throws IOException {
 109         if (in == null)  return 0;  // nothing is readable
 110         long maxlen = pbuf.capacity() - pbuf.position();
 111         assert(minlen <= maxlen);  // don't talk nonsense
 112         long numread = 0;
 113         int steps = 0;
 114         while (numread < minlen) {
 115             steps++;
 116             // read available input, up to buf.length or maxlen
 117             int readlen = _buf.length;
 118             if (readlen > (maxlen - numread))
 119                 readlen = (int)(maxlen - numread);
 120             int nr = in.read(_buf, 0, readlen);
 121             if (nr <= 0)  break;
 122             numread += nr;
 123             assert(numread <= maxlen);
 124             // %%% get rid of this extra copy by using nio?


   1 /*
   2  * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  85 
  86     static {
  87         // If loading from stand alone build uncomment this.
  88         // System.loadLibrary("unpack");
  89         java.security.AccessController.doPrivileged(
  90                 new sun.security.action.LoadLibraryAction("unpack"));
  91         initIDs();
  92     }
  93 
  94     NativeUnpack(UnpackerImpl p200) {
  95         super();
  96         _p200  = p200;
  97         _props = p200.props;
  98         p200._nunp = this;
  99     }
 100 
 101     // for JNI callbacks
 102     static private Object currentInstance() {
 103         UnpackerImpl p200 = (UnpackerImpl) Utils.getTLGlobals();
 104         return (p200 == null)? null: p200._nunp;
 105     }
 106 
 107     private synchronized long getUnpackerPtr() {
 108         return unpackerPtr;
 109     }
 110 
 111     // Callback from the unpacker engine to get more data.
 112     private long readInputFn(ByteBuffer pbuf, long minlen) throws IOException {
 113         if (in == null)  return 0;  // nothing is readable
 114         long maxlen = pbuf.capacity() - pbuf.position();
 115         assert(minlen <= maxlen);  // don't talk nonsense
 116         long numread = 0;
 117         int steps = 0;
 118         while (numread < minlen) {
 119             steps++;
 120             // read available input, up to buf.length or maxlen
 121             int readlen = _buf.length;
 122             if (readlen > (maxlen - numread))
 123                 readlen = (int)(maxlen - numread);
 124             int nr = in.read(_buf, 0, readlen);
 125             if (nr <= 0)  break;
 126             numread += nr;
 127             assert(numread <= maxlen);
 128             // %%% get rid of this extra copy by using nio?