Docstoc

TRANSPARENT PROXIES FOR JAVA FUTURES

Document Sample
TRANSPARENT PROXIES FOR JAVA FUTURES Powered By Docstoc
					T RANSPARENT P ROXIES FOR
      J AVA F UTURES

           Polyvios Pratikakis
              Jaime Spacco
             Michael Hicks

   University of Maryland, College Park

                              Transparent Proxies for Java Futures – p. 1/5
Concurrent Programming

    Threads of execution: Thread objects running
    in parallel
    Asynchronous method invocations: Methods
    can be called asynchronously
    e.g:
     Main thread:
     o = new O();
     o.m(); //async



                                  Transparent Proxies for Java Futures – p. 2/5
Concurrent Programming

    Threads of execution: Thread objects running
    in parallel
    Asynchronous method invocations: Methods
    can be called asynchronously
    e.g:
     Main thread:             Child thread:
     o = new O();
     o.m(); //async      ⇒    o.m();



                                  Transparent Proxies for Java Futures – p. 2/5
Concurrent Programming

    Threads of execution: Thread objects running
    in parallel
    Asynchronous method invocations: Methods
    can be called asynchronously
    e.g:
     Main thread:             Child thread:
     o = new O();
     o.m(); //async      ⇒    o.m();
     ...


                                  Transparent Proxies for Java Futures – p. 2/5
Futures
    What happens with returned value?
    “Future” or “promise”: a placeholder for the
    result
    “Claim” a future:
    If the result is not available, wait for it
    Futures are proxies. Other examples:
        Suspensions (lazy invocation)
        Remote objects
        Other wrappers

                                  Transparent Proxies for Java Futures – p. 3/5
Java Transparent Proxy Framework

    Static analysis and program transformation
       Based on qualifier inference system
       Formalization and proof of soundness
    Implementation of Futures via async methods
      Also lazy invocations, other applications
    Benefits
       Simple programming model
       Can improve application performance


                                  Transparent Proxies for Java Futures – p. 4/5
MultiLISP futures
    (future e) means e executes in parallel
    Lisp is functional and dynamically typed
    No need for the programmer to insert claims:
    The runtime system checks every access.
    If it is a future, claim before access
    Programmer only inserts future notations
    Futures are transparent




                                  Transparent Proxies for Java Futures – p. 5/5
Java Futures not Transparent

    Java is statically typed
    Futures in JSR166 must be claimed explicitly:
     public interface Future<V > {
       V get();
       V get(long timeout, TimeUnit unit);
       ...
     }




                                   Transparent Proxies for Java Futures – p. 6/5
Programming Overhead

 To convert a method invocation to asynchronous
     Change the call site to be asynchronous
     Change the type of the result to Future
       Change the type of variables to which the
       result flows
       Insert claims
  It is usual to claim early to avoid rewriting a lot o
 code

       Question: can we do this automatically?
                                       Transparent Proxies for Java Futures – p. 7/5
Type Qualifiers

    Qualifiers refine the meaning of types
    final Integer is to Integer like
    Future<String> is to String
    “Proxyness” is a type qualifier: proxy or
    nonproxy.
    If x has type
        proxy String then x could be a proxy
        nonproxy String then x is not a proxy
    nonproxy ≤ proxy


                                   Transparent Proxies for Java Futures – p. 8/5
Automatic Transformation
    Use qualifier inference to determine where
    proxies flow
    Transform program based on results
       Rewrite proxy types
       Insert claims whenever a proxy is used
       concretely




                                  Transparent Proxies for Java Futures – p. 9/5
Example: Initial Program

  procRequest(Socket sock) {
    Buffer in = readBuf(sock);

    Request req = translate(in);

    Buffer out = process(req);

    writeBuf(sock,out);
  }
  Request translate(Buffer in) {
    Request result;
    . . . in.foo() . . .
    return result;
  }
                                   Transparent Proxies for Java Futures – p. 10/5
Example: Async Calls

  procRequest(Socket sock) {
    Buffer in = @readBuf(sock);

    Request req = @translate(in);

    Buffer out = @process(req);

    writeBuf(sock,out);
  }
  Request translate(Buffer in) {
    Request result;
    . . . in.foo() . . .
    return result;
  }
                                    Transparent Proxies for Java Futures – p. 11/5
Example: Qualified Types

  procRequest(Socket sock) {
    Buffer in = proxy @readBuf(sock);

    Request req = proxy @translate(in);

    Buffer out = proxy @process(req);

    writeBuf(sock,out);
  }
  Request translate(Buffer in) {
    Request result;
    . . . in.foo() . . .
    return result;
  }
                                   Transparent Proxies for Java Futures – p. 12/5
Example: Qualified Types

  procRequest(Socket sock) {
    proxy Buffer in = proxy @readBuf(sock);

    Request req = proxy @translate(in);

    Buffer out = proxy @process(req);

    writeBuf(sock,out);
  }
  Request translate(Buffer in) {
    Request result;
    . . . in.foo() . . .
    return result;
  }
                                   Transparent Proxies for Java Futures – p. 13/5
Example: Qualified Types

  procRequest(Socket sock) {
    proxy Buffer in = proxy @readBuf(sock);

    Request req = proxy @translate(in);

    Buffer out = proxy @process(req);

    writeBuf(sock,out);
  }
  Request translate(Buffer in) {
    Request result;
    . . . in.foo() . . .
    return result;
  }
                                   Transparent Proxies for Java Futures – p. 14/5
Example: Qualified Types

  procRequest(Socket sock) {
    proxy Buffer in = proxy @readBuf(sock);

    Request req = proxy @translate(proxy in);

    Buffer out = proxy @process(req);

    writeBuf(sock,out);
  }
  Request translate(Buffer in) {
    Request result;
    . . . in.foo() . . .
    return result;
  }
                                   Transparent Proxies for Java Futures – p. 15/5
Example: Qualified Types

  procRequest(Socket sock) {
    proxy Buffer in = proxy @readBuf(sock);

    Request req = proxy @translate(proxy in);

    Buffer out = proxy @process(req);

    writeBuf(sock,out);
  }
  Request translate(Buffer in) {
    Request result;
    . . . in.foo() . . .
    return result;
  }
                                   Transparent Proxies for Java Futures – p. 16/5
Example: Qualified Types

  procRequest(Socket sock) {
    proxy Buffer in = proxy @readBuf(sock);

    proxy Request req = proxy @translate(proxy in

    Buffer out = proxy @process(req);

    writeBuf(sock,out);
  }
  Request translate(Buffer in) {
    Request result;
    . . . in.foo() . . .
    return result;
  }
                                   Transparent Proxies for Java Futures – p. 17/5
Example: Qualified Types

  procRequest(Socket sock) {
    proxy Buffer in = proxy @readBuf(sock);

    proxy Request req = proxy @translate(proxy in

    Buffer out = proxy @process(req);

    writeBuf(sock,out);
  }
  Request translate(Buffer in) {
    Request result;
    . . . in.foo() . . .
    return result;
  }
                                   Transparent Proxies for Java Futures – p. 18/5
Example: Qualified Types

  procRequest(Socket sock) {
    proxy Buffer in = proxy @readBuf(sock);

    proxy Request req = proxy @translate(proxy in

    Buffer out = proxy @process(proxy req);

    writeBuf(sock,out);
  }
  Request translate(Buffer in) {
    Request result;
    . . . in.foo() . . .
    return result;
  }
                                   Transparent Proxies for Java Futures – p. 19/5
Example: Qualified Types

  procRequest(Socket sock) {
    proxy Buffer in = proxy @readBuf(sock);

    proxy Request req = proxy @translate(proxy in

    Buffer out = proxy @process(proxy req);

    writeBuf(sock,out);
  }
  Request translate(Buffer in) {
    Request result;
    . . . in.foo() . . .
    return result;
  }
                                   Transparent Proxies for Java Futures – p. 20/5
Example: Qualified Types

  procRequest(Socket sock) {
    proxy Buffer in = proxy @readBuf(sock);

    proxy Request req = proxy @translate(proxy in

    proxy Buffer out = proxy @process(proxy req);

    writeBuf(sock,out);
  }
  Request translate(Buffer in) {
    Request result;
    . . . in.foo() . . .
    return result;
  }
                                   Transparent Proxies for Java Futures – p. 21/5
Example: Qualified Types

  procRequest(Socket sock) {
    proxy Buffer in = proxy @readBuf(sock);

    proxy Request req = proxy @translate(proxy in

    proxy Buffer out = proxy @process(proxy req);

    writeBuf(sock,out);
  }
  Request translate(Buffer in) {
    Request result;
    . . . in.foo() . . .
    return result;
  }
                                   Transparent Proxies for Java Futures – p. 22/5
Example: Qualified Types

  procRequest(Socket sock) {
    proxy Buffer in = proxy @readBuf(sock);

    proxy Request req = proxy @translate(proxy in

    proxy Buffer out = proxy @process(proxy req);

    writeBuf(sock,proxy out);
  }
  Request translate(Buffer in) {
    Request result;
    . . . in.foo() . . .
    return result;
  }
                                   Transparent Proxies for Java Futures – p. 23/5
Example: Qualified Types

  procRequest(Socket sock) {
    proxy Buffer in = proxy @readBuf(sock);

    proxy Request req = proxy @translate(proxy in

    proxy Buffer out = proxy @process(proxy req);

    writeBuf(sock,proxy out);
  }
  Request translate(Buffer in) {
    Request result;
    . . . in.foo() . . .
    return result;
  }
                                   Transparent Proxies for Java Futures – p. 24/5
Example: Qualified Types

  procRequest(Socket sock) {
    proxy Buffer in = proxy @readBuf(sock);

    proxy Request req = proxy @translate(proxy in

    proxy Buffer out = proxy @process(proxy req);

    writeBuf(sock,proxy out);
  }
  Request translate(proxy Buffer in) {
    Request result;
    . . . in.foo() . . .
    return result;
  }
                                  Transparent Proxies for Java Futures – p. 25/5
Example: Future Transformation

  procRequest(Socket sock) {
    Buffer in = @readBuf(sock);

    Request req = proxy @translate(in);

    Buffer out = proxy @process(req);

    writeBuf(sock,out);
  }
  Request translate(Buffer in) {
    Request result;
    . . . in.foo() . . .
    return result;
  }
                                   Transparent Proxies for Java Futures – p. 26/5
Example: Future Transformation

  procRequest(Socket sock) {
    Object in = new Proxy{
      private Object result;
      public void run() {
         result = readBuf(sock); }
      public synchronized Object get(){
         . . . return result; }
    }();
    Executor.run((Runnable)in);
    Request req = @translate(in);
    Buffer out = @process(req);
    writeBuf(sock,out);
  }
                                  Transparent Proxies for Java Futures – p. 27/5
Example: Future Transformation

  procRequest(Socket sock) {
    Object in = new Proxy{
      private Object result;
      public void run() {
         result = readBuf(sock); }
      public synchronized Object get(){
         . . . return result; }
    }();
    Executor.run((Runnable)in);
    Object req = new Proxy{. . . translate(in) . . .
    Object out = new Proxy{. . . process(req) . . .
    writeBuf(sock,out);
  }
                                       Transparent Proxies for Java Futures – p. 28/5
Example: Qualified types

  Request translate(Buffer in) {
    Request result;
    ...
    in.foo();
    ...
    return result;
  }




                                   Transparent Proxies for Java Futures – p. 29/5
Example: Qualified types

  Request translate(Buffer in) {
    Request result;
    ...
    in.foo();
    ...
    return result;
  }


                      concrete use



                                     Transparent Proxies for Java Futures – p. 30/5
Example: Qualified types

  Request translate(Buffer in) {
    Request result;
    ...
    (nonproxy in).foo();
    ...
    return result;
  }




                                   Transparent Proxies for Java Futures – p. 31/5
Example: Qualified types

  Request translate(Buffer in) {                             proxy
    Request result;
    ...
    (nonproxy in).foo();
    ...
    return result;
  }




                                   Transparent Proxies for Java Futures – p. 32/5
Example: Qualified types

  Request translate(Buffer in) {
    Request result;
    ...
    (nonproxy in).foo();
    ...
    return result;
  }




                                   Transparent Proxies for Java Futures – p. 33/5
Example: Future Transformation

  Request translate(Object inF) {
    Request result;
    ...
    Buffer in = (Buffer)
        (inF instanceof Proxy ?
         inF.get() :
         inF);
    in.foo();
    ...
    return result;
  }
                                       claim

                                    Transparent Proxies for Java Futures – p. 34/5
Other Uses of Proxies
    User can define:
       What is a concrete usage (places where an
       unwrapping would be necessary)
       Where proxies are created
       What is a claim
    E.g. suspensions (lazy proxies):
       Concrete usage: same as futures
       Proxy creation: lazy invocations
       Claim: evaluate the invocation and return
       its result
                                  Transparent Proxies for Java Futures – p. 35/5
Other Uses of Qualifier Inference
    tainted / untainted qualifiers (for security)
    null / non-null qualifiers: can be used to
    enforce stronger interfaces
    stack / heap allocation for objects:
    Figure out which objects can be stack-allocate
    and if/when they need to be moved to the
    heap




                                   Transparent Proxies for Java Futures – p. 36/5
Formalism: Checking System

   FJQ : Featherweight Java + Qualifiers: checkin
   system
      If the programmer annotated every type
      with a qualifier by hand, would it be
      correct?
   Proof of soundness for FJQ :
      If the annotated program typechecks, then
      everything is claimed before used



                                 Transparent Proxies for Java Futures – p. 37/5
Formalism: Inference System

    FJQ : Inference system that produces FJQ
      i
    programs
        Find the values of the proxy qualifier
        automatically
    Correctness of inference:
      If FJQ finds a solution, the resulting
           i

      annotated program typechecks in FJQ




                                   Transparent Proxies for Java Futures – p. 38/5
Formalism: Features
    Use set types to improve precision:
     class   A { ... }
     class   B extends A { . . . }
     class   C extends A { . . . }
     ...
     A var   = new B();


    Variable var has type {B}A
    Selective flow-sensitive coercions from proxy
    to nonproxy

                                     Transparent Proxies for Java Futures – p. 39/5
Implementation

    Uses Soot
      Jimple: Three-address code SSA-like
      representation of bytecode
      Spark: Points-to analysis engine
    Extends Spark’s Andersen-style points-to
    analysis with selective flow-sensitivity
    Bytecode to bytecode transformation
    Handles the full Java language (exceptions,
    JNI, reflection, etc)

                                  Transparent Proxies for Java Futures – p. 40/5
Performance
   RMI peer-to-peer application
   Each peer searches in the network to find
   service providers




                                  Transparent Proxies for Java Futures – p. 41/5
Example

  Service findService(LocalPeer self,
                      String sName) {
    Service s = self.getService(sName);
    if (s != null) return s;
    else {
      self.forward(
        new FindServiceMessage(sName));
      return getRemoteService(self, sName);
    }
  }



                                  Transparent Proxies for Java Futures – p. 42/5
Example

  Service findService(LocalPeer self,
                      String sName) {
    Service s = self.getService(sName);
    if (s != null) return s;
    else {
      self.forward(
        new FindServiceMessage(sName));
      return getRemoteService(self, sName);
    }
  }



                                  Transparent Proxies for Java Futures – p. 43/5
Example

  Service findService(LocalPeer self,
                      String sName) {
    Service s = self.getService(sName);
    if (s != null) return s;
    else {
      self.forward(
        new FindServiceMessage(sName));
      return getRemoteService(self, sName);
    }
  }



                                  Transparent Proxies for Java Futures – p. 44/5
Example

  Service findService(LocalPeer self,
                      String sName) {
    Service s = self.getService(sName);
    if (s != null) return s;
    else {
      self.forward(
        new FindServiceMessage(sName));
      return getRemoteService(self, sName);
    }
  }



                                  Transparent Proxies for Java Futures – p. 45/5
Example

  Service findService(LocalPeer self,
                      String sName) {
    Service s = self.getService(sName);
    if (s != null) return s;
    else {
      @self.forward(
        new FindServiceMessage(sName));
      return $getRemoteService(self, sName);
    }
  }


 $ denotes a lazy invocation
                                  Transparent Proxies for Java Futures – p. 46/5
Analysis Performance

  Analysis   Time              classes
              (s)   analyzed   w/ fut.   changed                     claims
     FI       73      1324       27               2                         7
    FS        92      1324        9               2                         2
   SPARK      66      1320       n/a            n/a                      n/a




                                         Transparent Proxies for Java Futures – p. 47/5
Related Work
    Futures and async methods
       MultiLISP (Halstead et al.)
       Promises (Liskov and Shrira)
       Touch elimination (Flanagan and Felleisen
       Polyphonic C# (Benton et al.)
       Lazy Task Creation (Halstead, Frigo et al.)
       SCOOP/Eiffel (Compton)
       Async RMI (Raje et al, Sysala et al.)



                                   Transparent Proxies for Java Futures – p. 48/5
Related Work
    Static Analysis
       Points-to analysis (many)
       Qualifier inference (Foster et al.)
       Value flow analysis (Heintze and Tardieu)




                                 Transparent Proxies for Java Futures – p. 49/5
Future Work
    Incorporate into a general framework for
    qualifiers in Java
       Arbitrary qualifier partial order
       Context-sensitive analysis
       Faster algorithm
    Incremental analysis
       Only re-run analysis for files affected by
       local change
       Don’t reanalyze the library every time

                                   Transparent Proxies for Java Futures – p. 50/5
Summary

   Framework for programming with proxies
      Simplifies programming process
      Avoids violations of transparency
   Novel static analysis
     Extends qualifier inference with
     flow-sensitive coercions
     Has additional applications (Stack-allocate
     objects, not-null types, etc)
   Formalization and proof of soundness
   Prototype implementation
                                 Transparent Proxies for Java Futures – p. 51/5

				
DOCUMENT INFO
Shared By:
Stats:
views:34
posted:3/19/2011
language:English
pages:53
Description: Transparent proxy means that the client does not need to know the existence of a proxy server, it adapted to your request fields (message), and will send the real IP, and more for the router's NAT forwarding.