Merge pull request #2427 from yang-g/per_call_oauth_creds_impl

Per call oauth creds impl
diff --git a/Makefile b/Makefile
index 4756b75..2ae0cd0 100644
--- a/Makefile
+++ b/Makefile
@@ -145,7 +145,7 @@
 CXX_tsan = clang++
 LD_tsan = clang
 LDXX_tsan = clang++
-CPPFLAGS_tsan = -O0 -fsanitize=thread -fno-omit-frame-pointer
+CPPFLAGS_tsan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-error=unused-command-line-argument
 LDFLAGS_tsan = -fsanitize=thread
 DEFINES_tsan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=10
 
@@ -155,7 +155,7 @@
 CXX_asan = clang++
 LD_asan = clang
 LDXX_asan = clang++
-CPPFLAGS_asan = -O0 -fsanitize=address -fno-omit-frame-pointer
+CPPFLAGS_asan = -O0 -fsanitize=address -fno-omit-frame-pointer -Wno-error=unused-command-line-argument
 LDFLAGS_asan = -fsanitize=address
 DEFINES_asan = GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3
 
@@ -165,7 +165,7 @@
 CXX_msan = clang++-libc++
 LD_msan = clang
 LDXX_msan = clang++-libc++
-CPPFLAGS_msan = -O0 -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1
+CPPFLAGS_msan = -O0 -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 -Wno-error=unused-command-line-argument
 OPENSSL_CFLAGS_msan = -DPURIFY
 LDFLAGS_msan = -fsanitize=memory -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1
 DEFINES_msan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=4
@@ -176,7 +176,7 @@
 CXX_ubsan = clang++
 LD_ubsan = clang
 LDXX_ubsan = clang++
-CPPFLAGS_ubsan = -O1 -fsanitize=undefined -fno-omit-frame-pointer
+CPPFLAGS_ubsan = -O1 -fsanitize=undefined -fno-omit-frame-pointer -Wno-error=unused-command-line-argument
 OPENSSL_CFLAGS_ubsan = -DPURIFY
 LDFLAGS_ubsan = -fsanitize=undefined
 DEFINES_ubsan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3
@@ -241,10 +241,6 @@
 HOST_LD = $(LD)
 HOST_LDXX = $(LDXX)
 
-CPPFLAGS += $(CPPFLAGS_$(CONFIG))
-DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\"
-LDFLAGS += $(LDFLAGS_$(CONFIG))
-
 ifdef EXTRA_DEFINES
 DEFINES += $(EXTRA_DEFINES)
 endif
@@ -258,6 +254,10 @@
 CPPFLAGS += -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter
 LDFLAGS += -g
 
+CPPFLAGS += $(CPPFLAGS_$(CONFIG))
+DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\"
+LDFLAGS += $(LDFLAGS_$(CONFIG))
+
 ifneq ($(SYSTEM),MINGW32)
 PIC_CPPFLAGS = -fPIC
 CPPFLAGS += -fPIC
@@ -1443,7 +1443,7 @@
 
 $(LIBDIR)/$(CONFIG)/zlib/libz.a:
 	$(E) "[MAKE]    Building zlib"
-	$(Q)(cd third_party/zlib ; CC="$(CC)" CFLAGS="$(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG))" ./configure --static)
+	$(Q)(cd third_party/zlib ; CC="$(CC)" CFLAGS="$(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(ZLIB_CFLAGS_EXTRA)" ./configure --static)
 	$(Q)$(MAKE) -C third_party/zlib clean
 	$(Q)$(MAKE) -C third_party/zlib
 	$(Q)mkdir -p $(LIBDIR)/$(CONFIG)/zlib
@@ -1452,7 +1452,7 @@
 $(LIBDIR)/$(CONFIG)/openssl/libssl.a:
 	$(E) "[MAKE]    Building openssl for $(SYSTEM)"
 ifeq ($(SYSTEM),Darwin)
-	$(Q)(cd third_party/openssl ; CC="$(CC) $(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG))" ./Configure darwin64-x86_64-cc)
+	$(Q)(cd third_party/openssl ; CC="$(CC) $(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_EXTRA)" ./Configure darwin64-x86_64-cc)
 else
 ifeq ($(SYSTEM),MINGW32)
 	@echo "We currently don't have a good way to compile OpenSSL in-place under msys."
@@ -1473,7 +1473,7 @@
 	@echo "  CPPFLAGS=-I/c/OpenSSL-Win64/include LDFLAGS=-L/c/OpenSSL-Win64 make"
 	@false
 else
-	$(Q)(cd third_party/openssl ; CC="$(CC) $(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG))" ./config no-asm $(OPENSSL_CONFIG_$(CONFIG)))
+	$(Q)(cd third_party/openssl ; CC="$(CC) $(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_EXTRA)" ./config no-asm $(OPENSSL_CONFIG_$(CONFIG)))
 endif
 endif
 	$(Q)$(MAKE) -C third_party/openssl clean
@@ -1487,7 +1487,7 @@
 
 $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure
 	$(E) "[MAKE]    Building protobuf"
-	$(Q)(cd third_party/protobuf ; CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS_$(CONFIG)) -g" CPPFLAGS="$(PIC_CPPFLAGS) $(CPPFLAGS_$(CONFIG)) -g" ./configure --disable-shared --enable-static)
+	$(Q)(cd third_party/protobuf ; CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS_$(CONFIG)) -g $(PROTOBUF_LDFLAGS_EXTRA)" CPPFLAGS="$(PIC_CPPFLAGS) $(CPPFLAGS_$(CONFIG)) -g $(PROTOBUF_CPPFLAGS_EXTRA)" ./configure --disable-shared --enable-static)
 	$(Q)$(MAKE) -C third_party/protobuf clean
 	$(Q)$(MAKE) -C third_party/protobuf
 	$(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf
diff --git a/include/grpc++/channel_arguments.h b/include/grpc++/channel_arguments.h
index 7b17830..4d92637 100644
--- a/include/grpc++/channel_arguments.h
+++ b/include/grpc++/channel_arguments.h
@@ -54,14 +54,21 @@
   ChannelArguments() {}
   ~ChannelArguments() {}
 
+  ChannelArguments(const ChannelArguments& other);
+  ChannelArguments& operator=(ChannelArguments other) {
+    Swap(other);
+    return *this;
+  }
+
+  void Swap(ChannelArguments& other);
+
   // grpc specific channel argument setters
   // Set target name override for SSL host name checking.
   void SetSslTargetNameOverride(const grpc::string& name);
   // TODO(yangg) add flow control options
 
   // Set the compression algorithm for the channel.
-  void _Experimental_SetCompressionAlgorithm(
-      grpc_compression_algorithm algorithm);
+  void SetCompressionAlgorithm(grpc_compression_algorithm algorithm);
 
   // Generic channel argument setters. Only for advanced use cases.
   void SetInt(const grpc::string& key, int value);
@@ -74,10 +81,6 @@
   friend class SecureCredentials;
   friend class testing::ChannelArgumentsTest;
 
-  // TODO(yangg) implement copy and assign
-  ChannelArguments(const ChannelArguments&);
-  ChannelArguments& operator=(const ChannelArguments&);
-
   // Returns empty string when it is not set.
   grpc::string GetSslTargetNameOverride() const;
 
diff --git a/include/grpc++/client_context.h b/include/grpc++/client_context.h
index 6b8d721..9df7669 100644
--- a/include/grpc++/client_context.h
+++ b/include/grpc++/client_context.h
@@ -110,12 +110,11 @@
     creds_ = creds;
   }
 
-  grpc_compression_algorithm _experimental_get_compression_algorithm() const {
+  grpc_compression_algorithm get_compression_algorithm() const {
     return compression_algorithm_;
   }
 
-  void _experimental_set_compression_algorithm(
-      grpc_compression_algorithm algorithm);
+  void set_compression_algorithm(grpc_compression_algorithm algorithm);
 
   std::shared_ptr<const AuthContext> auth_context() const;
 
diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h
index 3c72c1d..504f0cc 100644
--- a/include/grpc/grpc.h
+++ b/include/grpc/grpc.h
@@ -45,40 +45,49 @@
 extern "C" {
 #endif
 
-/* Completion Queues enable notification of the completion of asynchronous
-   actions. */
+/*! \mainpage GRPC Core
+ *
+ * \section intro_sec The GRPC Core library is a low-level library designed
+ * to be wrapped by higher level libraries.
+ *
+ * The top-level API is provided in grpc.h. 
+ * Security related functionality lives in grpc_security.h.
+ */
+
+/** Completion Queues enable notification of the completion of asynchronous
+    actions. */
 typedef struct grpc_completion_queue grpc_completion_queue;
 
-/* The Channel interface allows creation of Call objects. */
+/** The Channel interface allows creation of Call objects. */
 typedef struct grpc_channel grpc_channel;
 
-/* A server listens to some port and responds to request calls */
+/** A server listens to some port and responds to request calls */
 typedef struct grpc_server grpc_server;
 
-/* A Call represents an RPC. When created, it is in a configuration state
-   allowing properties to be set until it is invoked. After invoke, the Call
-   can have messages written to it and read from it. */
+/** A Call represents an RPC. When created, it is in a configuration state
+    allowing properties to be set until it is invoked. After invoke, the Call
+    can have messages written to it and read from it. */
 typedef struct grpc_call grpc_call;
 
-/* Type specifier for grpc_arg */
+/** Type specifier for grpc_arg */
 typedef enum {
   GRPC_ARG_STRING,
   GRPC_ARG_INTEGER,
   GRPC_ARG_POINTER
 } grpc_arg_type;
 
-/* A single argument... each argument has a key and a value
+/** A single argument... each argument has a key and a value
 
-   A note on naming keys:
-     Keys are namespaced into groups, usually grouped by library, and are
-     keys for module XYZ are named XYZ.key1, XYZ.key2, etc. Module names must
-     be restricted to the regex [A-Za-z][_A-Za-z0-9]{,15}.
-     Key names must be restricted to the regex [A-Za-z][_A-Za-z0-9]{,47}.
+    A note on naming keys:
+      Keys are namespaced into groups, usually grouped by library, and are
+      keys for module XYZ are named XYZ.key1, XYZ.key2, etc. Module names must
+      be restricted to the regex [A-Za-z][_A-Za-z0-9]{,15}.
+      Key names must be restricted to the regex [A-Za-z][_A-Za-z0-9]{,47}.
 
-     GRPC core library keys are prefixed by grpc.
+    GRPC core library keys are prefixed by grpc.
 
-     Library authors are strongly encouraged to #define symbolic constants for
-     their keys so that it's possible to change them in the future. */
+    Library authors are strongly encouraged to \#define symbolic constants for
+    their keys so that it's possible to change them in the future. */
 typedef struct {
   grpc_arg_type type;
   char *key;
@@ -107,16 +116,22 @@
 } grpc_channel_args;
 
 /* Channel argument keys: */
-/* Enable census for tracing and stats collection */
+/** Enable census for tracing and stats collection */
 #define GRPC_ARG_ENABLE_CENSUS "grpc.census"
-/* Maximum number of concurrent incoming streams to allow on a http2
-   connection */
+/** Maximum number of concurrent incoming streams to allow on a http2
+    connection */
 #define GRPC_ARG_MAX_CONCURRENT_STREAMS "grpc.max_concurrent_streams"
-/* Maximum message length that the channel can receive */
+/** Maximum message length that the channel can receive */
 #define GRPC_ARG_MAX_MESSAGE_LENGTH "grpc.max_message_length"
-/* Initial sequence number for http2 transports */
+/** Initial sequence number for http2 transports */
 #define GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER \
   "grpc.http2.initial_sequence_number"
+/** Primary user agent: goes at the start of the user-agent metadata
+    sent on each request */
+#define GRPC_ARG_PRIMARY_USER_AGENT_STRING "grpc.primary_user_agent"
+/** Secondary user agent: goes at the end of the user-agent metadata
+    sent on each request */
+#define GRPC_ARG_SECONDARY_USER_AGENT_STRING "grpc.secondary_user_agent"
 
 /** Connectivity state of a channel. */
 typedef enum {
@@ -132,59 +147,59 @@
   GRPC_CHANNEL_FATAL_FAILURE
 } grpc_connectivity_state;
 
-/* Result of a grpc call. If the caller satisfies the prerequisites of a
-   particular operation, the grpc_call_error returned will be GRPC_CALL_OK.
-   Receiving any other value listed here is an indication of a bug in the
-   caller. */
+/** Result of a grpc call. If the caller satisfies the prerequisites of a
+    particular operation, the grpc_call_error returned will be GRPC_CALL_OK.
+    Receiving any other value listed here is an indication of a bug in the
+    caller. */
 typedef enum grpc_call_error {
-  /* everything went ok */
+  /** everything went ok */
   GRPC_CALL_OK = 0,
-  /* something failed, we don't know what */
+  /** something failed, we don't know what */
   GRPC_CALL_ERROR,
-  /* this method is not available on the server */
+  /** this method is not available on the server */
   GRPC_CALL_ERROR_NOT_ON_SERVER,
-  /* this method is not available on the client */
+  /** this method is not available on the client */
   GRPC_CALL_ERROR_NOT_ON_CLIENT,
-  /* this method must be called before server_accept */
+  /** this method must be called before server_accept */
   GRPC_CALL_ERROR_ALREADY_ACCEPTED,
-  /* this method must be called before invoke */
+  /** this method must be called before invoke */
   GRPC_CALL_ERROR_ALREADY_INVOKED,
-  /* this method must be called after invoke */
+  /** this method must be called after invoke */
   GRPC_CALL_ERROR_NOT_INVOKED,
-  /* this call is already finished
-     (writes_done or write_status has already been called) */
+  /** this call is already finished
+      (writes_done or write_status has already been called) */
   GRPC_CALL_ERROR_ALREADY_FINISHED,
-  /* there is already an outstanding read/write operation on the call */
+  /** there is already an outstanding read/write operation on the call */
   GRPC_CALL_ERROR_TOO_MANY_OPERATIONS,
-  /* the flags value was illegal for this call */
+  /** the flags value was illegal for this call */
   GRPC_CALL_ERROR_INVALID_FLAGS,
-  /* invalid metadata was passed to this call */
+  /** invalid metadata was passed to this call */
   GRPC_CALL_ERROR_INVALID_METADATA,
-  /* completion queue for notification has not been registered with the server
-     */
+  /** completion queue for notification has not been registered with the 
+      server */
   GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE
 } grpc_call_error;
 
 /* Write Flags: */
-/* Hint that the write may be buffered and need not go out on the wire
-   immediately. GRPC is free to buffer the message until the next non-buffered
-   write, or until writes_done, but it need not buffer completely or at all. */
+/** Hint that the write may be buffered and need not go out on the wire
+    immediately. GRPC is free to buffer the message until the next non-buffered
+    write, or until writes_done, but it need not buffer completely or at all. */
 #define GRPC_WRITE_BUFFER_HINT (0x00000001u)
-/* Force compression to be disabled for a particular write
-   (start_write/add_metadata). Illegal on invoke/accept. */
+/** Force compression to be disabled for a particular write
+    (start_write/add_metadata). Illegal on invoke/accept. */
 #define GRPC_WRITE_NO_COMPRESS (0x00000002u)
-/* Mask of all valid flags. */
+/** Mask of all valid flags. */
 #define GRPC_WRITE_USED_MASK (GRPC_WRITE_BUFFER_HINT | GRPC_WRITE_NO_COMPRESS)
 
-/* A single metadata element */
+/** A single metadata element */
 typedef struct grpc_metadata {
   const char *key;
   const char *value;
   size_t value_length;
 
-  /* The following fields are reserved for grpc internal use.
-     There is no need to initialize them, and they will be set to garbage during
-     calls to grpc. */
+  /** The following fields are reserved for grpc internal use.
+      There is no need to initialize them, and they will be set to garbage during
+      calls to grpc. */
   struct {
     void *obfuscated[3];
   } internal_data;
@@ -235,42 +250,41 @@
 void grpc_call_details_destroy(grpc_call_details *details);
 
 typedef enum {
-  /* Send initial metadata: one and only one instance MUST be sent for each
-     call,
-     unless the call was cancelled - in which case this can be skipped */
+  /** Send initial metadata: one and only one instance MUST be sent for each
+      call, unless the call was cancelled - in which case this can be skipped */
   GRPC_OP_SEND_INITIAL_METADATA = 0,
-  /* Send a message: 0 or more of these operations can occur for each call */
+  /** Send a message: 0 or more of these operations can occur for each call */
   GRPC_OP_SEND_MESSAGE,
-  /* Send a close from the client: one and only one instance MUST be sent from
-     the client,
-     unless the call was cancelled - in which case this can be skipped */
+  /** Send a close from the client: one and only one instance MUST be sent from
+      the client, unless the call was cancelled - in which case this can be 
+      skipped */
   GRPC_OP_SEND_CLOSE_FROM_CLIENT,
-  /* Send status from the server: one and only one instance MUST be sent from
-     the server
-     unless the call was cancelled - in which case this can be skipped */
+  /** Send status from the server: one and only one instance MUST be sent from
+      the server unless the call was cancelled - in which case this can be 
+      skipped */
   GRPC_OP_SEND_STATUS_FROM_SERVER,
-  /* Receive initial metadata: one and only one MUST be made on the client, must
-     not be made on the server */
+  /** Receive initial metadata: one and only one MUST be made on the client, 
+      must not be made on the server */
   GRPC_OP_RECV_INITIAL_METADATA,
-  /* Receive a message: 0 or more of these operations can occur for each call */
+  /** Receive a message: 0 or more of these operations can occur for each call */
   GRPC_OP_RECV_MESSAGE,
-  /* Receive status on the client: one and only one must be made on the client.
+  /** Receive status on the client: one and only one must be made on the client.
      This operation always succeeds, meaning ops paired with this operation
      will also appear to succeed, even though they may not have. In that case
-     the status will indicate some failure.
-     */
+     the status will indicate some failure. */
   GRPC_OP_RECV_STATUS_ON_CLIENT,
-  /* Receive close on the server: one and only one must be made on the server
-     */
+  /** Receive close on the server: one and only one must be made on the 
+      server */
   GRPC_OP_RECV_CLOSE_ON_SERVER
 } grpc_op_type;
 
-/* Operation data: one field for each op type (except SEND_CLOSE_FROM_CLIENT
-   which has
-   no arguments) */
+/** Operation data: one field for each op type (except SEND_CLOSE_FROM_CLIENT
+   which has no arguments) */
 typedef struct grpc_op {
+  /** Operation type, as defined by grpc_op_type */
   grpc_op_type op;
-  gpr_uint32 flags; /**< Write flags bitset for grpc_begin_messages */
+  /** Write flags bitset for grpc_begin_messages */
+  gpr_uint32 flags; 
   union {
     struct {
       size_t count;
@@ -283,53 +297,49 @@
       grpc_status_code status;
       const char *status_details;
     } send_status_from_server;
-    /* ownership of the array is with the caller, but ownership of the elements
-       stays with the call object (ie key, value members are owned by the call
-       object, recv_initial_metadata->array is owned by the caller).
-       After the operation completes, call grpc_metadata_array_destroy on this
-       value, or reuse it in a future op. */
+    /** ownership of the array is with the caller, but ownership of the elements
+        stays with the call object (ie key, value members are owned by the call
+        object, recv_initial_metadata->array is owned by the caller).
+        After the operation completes, call grpc_metadata_array_destroy on this
+        value, or reuse it in a future op. */
     grpc_metadata_array *recv_initial_metadata;
-    /* ownership of the byte buffer is moved to the caller; the caller must call
-       grpc_byte_buffer_destroy on this value, or reuse it in a future op. */
+    /** ownership of the byte buffer is moved to the caller; the caller must call
+        grpc_byte_buffer_destroy on this value, or reuse it in a future op. */
     grpc_byte_buffer **recv_message;
     struct {
-      /* ownership of the array is with the caller, but ownership of the
-         elements
-         stays with the call object (ie key, value members are owned by the call
-         object, trailing_metadata->array is owned by the caller).
-         After the operation completes, call grpc_metadata_array_destroy on this
-         value, or reuse it in a future op. */
+      /** ownership of the array is with the caller, but ownership of the
+          elements stays with the call object (ie key, value members are owned 
+          by the call object, trailing_metadata->array is owned by the caller).
+          After the operation completes, call grpc_metadata_array_destroy on this
+          value, or reuse it in a future op. */
       grpc_metadata_array *trailing_metadata;
       grpc_status_code *status;
-      /* status_details is a buffer owned by the application before the op
-         completes
-         and after the op has completed. During the operation status_details may
-         be
-         reallocated to a size larger than *status_details_capacity, in which
-         case
-         *status_details_capacity will be updated with the new array capacity.
+      /** status_details is a buffer owned by the application before the op
+          completes and after the op has completed. During the operation
+          status_details may be reallocated to a size larger than 
+          *status_details_capacity, in which case *status_details_capacity will 
+          be updated with the new array capacity.
 
-         Pre-allocating space:
-         size_t my_capacity = 8;
-         char *my_details = gpr_malloc(my_capacity);
-         x.status_details = &my_details;
-         x.status_details_capacity = &my_capacity;
+          Pre-allocating space:
+          size_t my_capacity = 8;
+          char *my_details = gpr_malloc(my_capacity);
+          x.status_details = &my_details;
+          x.status_details_capacity = &my_capacity;
 
-         Not pre-allocating space:
-         size_t my_capacity = 0;
-         char *my_details = NULL;
-         x.status_details = &my_details;
-         x.status_details_capacity = &my_capacity;
+          Not pre-allocating space:
+          size_t my_capacity = 0;
+          char *my_details = NULL;
+          x.status_details = &my_details;
+          x.status_details_capacity = &my_capacity;
 
-         After the call:
-         gpr_free(my_details); */
+          After the call:
+          gpr_free(my_details); */
       char **status_details;
       size_t *status_details_capacity;
     } recv_status_on_client;
     struct {
-      /* out argument, set to 1 if the call failed in any way (seen as a
-         cancellation
-         on the server), or 0 if the call succeeded */
+      /** out argument, set to 1 if the call failed in any way (seen as a
+          cancellation on the server), or 0 if the call succeeded */
       int *cancelled;
     } recv_close_on_server;
   } data;
@@ -379,62 +389,62 @@
 grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cq, void *tag,
                                        gpr_timespec deadline);
 
-/* Begin destruction of a completion queue. Once all possible events are
-   drained then grpc_completion_queue_next will start to produce
-   GRPC_QUEUE_SHUTDOWN events only. At that point it's safe to call
-   grpc_completion_queue_destroy.
+/** Begin destruction of a completion queue. Once all possible events are
+    drained then grpc_completion_queue_next will start to produce
+    GRPC_QUEUE_SHUTDOWN events only. At that point it's safe to call
+    grpc_completion_queue_destroy.
 
-   After calling this function applications should ensure that no
-   NEW work is added to be published on this completion queue. */
+    After calling this function applications should ensure that no
+    NEW work is added to be published on this completion queue. */
 void grpc_completion_queue_shutdown(grpc_completion_queue *cq);
 
-/* Destroy a completion queue. The caller must ensure that the queue is
-   drained and no threads are executing grpc_completion_queue_next */
+/** Destroy a completion queue. The caller must ensure that the queue is
+    drained and no threads are executing grpc_completion_queue_next */
 void grpc_completion_queue_destroy(grpc_completion_queue *cq);
 
-/* Create a call given a grpc_channel, in order to call 'method'. All
-   completions are sent to 'completion_queue'. 'method' and 'host' need only
-   live through the invocation of this function. */
+/** Create a call given a grpc_channel, in order to call 'method'. All
+    completions are sent to 'completion_queue'. 'method' and 'host' need only
+    live through the invocation of this function. */
 grpc_call *grpc_channel_create_call(grpc_channel *channel,
                                     grpc_completion_queue *completion_queue,
                                     const char *method, const char *host,
                                     gpr_timespec deadline);
 
-/* Pre-register a method/host pair on a channel. */
+/** Pre-register a method/host pair on a channel. */
 void *grpc_channel_register_call(grpc_channel *channel, const char *method,
                                  const char *host);
 
-/* Create a call given a handle returned from grpc_channel_register_call */
+/** Create a call given a handle returned from grpc_channel_register_call */
 grpc_call *grpc_channel_create_registered_call(
     grpc_channel *channel, grpc_completion_queue *completion_queue,
     void *registered_call_handle, gpr_timespec deadline);
 
-/* Start a batch of operations defined in the array ops; when complete, post a
-   completion of type 'tag' to the completion queue bound to the call.
-   The order of ops specified in the batch has no significance.
-   Only one operation of each type can be active at once in any given
-   batch. You must call grpc_completion_queue_next or
-   grpc_completion_queue_pluck on the completion queue associated with 'call'
-   for work to be performed.
-   THREAD SAFETY: access to grpc_call_start_batch in multi-threaded environment
-   needs to be synchronized. As an optimization, you may synchronize batches
-   containing just send operations independently from batches containing just
-   receive operations. */
+/** Start a batch of operations defined in the array ops; when complete, post a
+    completion of type 'tag' to the completion queue bound to the call.
+    The order of ops specified in the batch has no significance.
+    Only one operation of each type can be active at once in any given
+    batch. You must call grpc_completion_queue_next or
+    grpc_completion_queue_pluck on the completion queue associated with 'call'
+    for work to be performed.
+    THREAD SAFETY: access to grpc_call_start_batch in multi-threaded environment
+    needs to be synchronized. As an optimization, you may synchronize batches
+    containing just send operations independently from batches containing just
+    receive operations. */
 grpc_call_error grpc_call_start_batch(grpc_call *call, const grpc_op *ops,
                                       size_t nops, void *tag);
 
-/* Create a client channel to 'target'. Additional channel level configuration
-   MAY be provided by grpc_channel_args, though the expectation is that most
-   clients will want to simply pass NULL. See grpc_channel_args definition for
-   more on this. The data in 'args' need only live through the invocation of
-   this function. */
+/** Create a client channel to 'target'. Additional channel level configuration
+    MAY be provided by grpc_channel_args, though the expectation is that most
+    clients will want to simply pass NULL. See grpc_channel_args definition for
+    more on this. The data in 'args' need only live through the invocation of
+    this function. */
 grpc_channel *grpc_channel_create(const char *target,
                                   const grpc_channel_args *args);
 
-/* Create a lame client: this client fails every operation attempted on it. */
+/** Create a lame client: this client fails every operation attempted on it. */
 grpc_channel *grpc_lame_client_channel_create(void);
 
-/* Close and destroy a grpc channel */
+/** Close and destroy a grpc channel */
 void grpc_channel_destroy(grpc_channel *channel);
 
 /* Error handling for grpc_call
@@ -443,49 +453,49 @@
    If a grpc_call fails, it's guaranteed that no change to the call state
    has been made. */
 
-/* Called by clients to cancel an RPC on the server.
-   Can be called multiple times, from any thread.
-   THREAD-SAFETY grpc_call_cancel and grpc_call_cancel_with_status
-   are thread-safe, and can be called at any point before grpc_call_destroy
-   is called.*/
+/** Called by clients to cancel an RPC on the server.
+    Can be called multiple times, from any thread.
+    THREAD-SAFETY grpc_call_cancel and grpc_call_cancel_with_status
+    are thread-safe, and can be called at any point before grpc_call_destroy
+    is called.*/
 grpc_call_error grpc_call_cancel(grpc_call *call);
 
-/* Called by clients to cancel an RPC on the server.
-   Can be called multiple times, from any thread.
-   If a status has not been received for the call, set it to the status code
-   and description passed in.
-   Importantly, this function does not send status nor description to the
-   remote endpoint. */
+/** Called by clients to cancel an RPC on the server.
+    Can be called multiple times, from any thread.
+    If a status has not been received for the call, set it to the status code
+    and description passed in.
+    Importantly, this function does not send status nor description to the
+    remote endpoint. */
 grpc_call_error grpc_call_cancel_with_status(grpc_call *call,
                                              grpc_status_code status,
                                              const char *description);
 
-/* Destroy a call.
-   THREAD SAFETY: grpc_call_destroy is thread-compatible */
+/** Destroy a call.
+    THREAD SAFETY: grpc_call_destroy is thread-compatible */
 void grpc_call_destroy(grpc_call *call);
 
-/* Request notification of a new call. 'cq_for_notification' must
-   have been registered to the server via grpc_server_register_completion_queue.
-   */
+/** Request notification of a new call. 'cq_for_notification' must
+    have been registered to the server via 
+    grpc_server_register_completion_queue. */
 grpc_call_error grpc_server_request_call(
     grpc_server *server, grpc_call **call, grpc_call_details *details,
     grpc_metadata_array *request_metadata,
     grpc_completion_queue *cq_bound_to_call,
     grpc_completion_queue *cq_for_notification, void *tag_new);
 
-/* Registers a method in the server.
-   Methods to this (host, method) pair will not be reported by
-   grpc_server_request_call, but instead be reported by
-   grpc_server_request_registered_call when passed the appropriate
-   registered_method (as returned by this function).
-   Must be called before grpc_server_start.
-   Returns NULL on failure. */
+/** Registers a method in the server.
+    Methods to this (host, method) pair will not be reported by
+    grpc_server_request_call, but instead be reported by
+    grpc_server_request_registered_call when passed the appropriate
+    registered_method (as returned by this function).
+    Must be called before grpc_server_start.
+    Returns NULL on failure. */
 void *grpc_server_register_method(grpc_server *server, const char *method,
                                   const char *host);
 
-/* Request notification of a new pre-registered call. 'cq_for_notification' must
-   have been registered to the server via grpc_server_register_completion_queue.
-   */
+/** Request notification of a new pre-registered call. 'cq_for_notification' 
+    must have been registered to the server via 
+    grpc_server_register_completion_queue. */
 grpc_call_error grpc_server_request_registered_call(
     grpc_server *server, void *registered_method, grpc_call **call,
     gpr_timespec *deadline, grpc_metadata_array *request_metadata,
@@ -493,45 +503,45 @@
     grpc_completion_queue *cq_bound_to_call,
     grpc_completion_queue *cq_for_notification, void *tag_new);
 
-/* Create a server. Additional configuration for each incoming channel can
-   be specified with args. If no additional configuration is needed, args can
-   be NULL. See grpc_channel_args for more. The data in 'args' need only live
-   through the invocation of this function. */
+/** Create a server. Additional configuration for each incoming channel can
+    be specified with args. If no additional configuration is needed, args can
+    be NULL. See grpc_channel_args for more. The data in 'args' need only live
+    through the invocation of this function. */
 grpc_server *grpc_server_create(const grpc_channel_args *args);
 
-/* Register a completion queue with the server. Must be done for any
-   notification completion queue that is passed to grpc_server_request_*_call
-   and to grpc_server_shutdown_and_notify. Must be performed prior to
-   grpc_server_start. */
+/** Register a completion queue with the server. Must be done for any
+    notification completion queue that is passed to grpc_server_request_*_call
+    and to grpc_server_shutdown_and_notify. Must be performed prior to
+    grpc_server_start. */
 void grpc_server_register_completion_queue(grpc_server *server,
                                            grpc_completion_queue *cq);
 
-/* Add a HTTP2 over plaintext over tcp listener.
-   Returns bound port number on success, 0 on failure.
-   REQUIRES: server not started */
+/** Add a HTTP2 over plaintext over tcp listener.
+    Returns bound port number on success, 0 on failure.
+    REQUIRES: server not started */
 int grpc_server_add_http2_port(grpc_server *server, const char *addr);
 
-/* Start a server - tells all listeners to start listening */
+/** Start a server - tells all listeners to start listening */
 void grpc_server_start(grpc_server *server);
 
-/* Begin shutting down a server.
-   After completion, no new calls or connections will be admitted.
-   Existing calls will be allowed to complete.
-   Send a GRPC_OP_COMPLETE event when there are no more calls being serviced.
-   Shutdown is idempotent, and all tags will be notified at once if multiple
-   grpc_server_shutdown_and_notify calls are made. 'cq' must have been
-   registered to this server via grpc_server_register_completion_queue. */
+/** Begin shutting down a server.
+    After completion, no new calls or connections will be admitted.
+    Existing calls will be allowed to complete.
+    Send a GRPC_OP_COMPLETE event when there are no more calls being serviced.
+    Shutdown is idempotent, and all tags will be notified at once if multiple
+    grpc_server_shutdown_and_notify calls are made. 'cq' must have been
+    registered to this server via grpc_server_register_completion_queue. */
 void grpc_server_shutdown_and_notify(grpc_server *server,
                                      grpc_completion_queue *cq, void *tag);
 
-/* Cancel all in-progress calls.
-   Only usable after shutdown. */
+/** Cancel all in-progress calls.
+    Only usable after shutdown. */
 void grpc_server_cancel_all_calls(grpc_server *server);
 
-/* Destroy a server.
-   Shutdown must have completed beforehand (i.e. all tags generated by
-   grpc_server_shutdown_and_notify must have been received, and at least
-   one call to grpc_server_shutdown_and_notify must have been made). */
+/** Destroy a server.
+    Shutdown must have completed beforehand (i.e. all tags generated by
+    grpc_server_shutdown_and_notify must have been received, and at least
+    one call to grpc_server_shutdown_and_notify must have been made). */
 void grpc_server_destroy(grpc_server *server);
 
 /** Enable or disable a tracer.
diff --git a/include/grpc/support/port_platform.h b/include/grpc/support/port_platform.h
index a5d1b62..57fed18 100644
--- a/include/grpc/support/port_platform.h
+++ b/include/grpc/support/port_platform.h
@@ -71,6 +71,7 @@
 
 #if !defined(GPR_NO_AUTODETECT_PLATFORM)
 #if defined(_WIN64) || defined(WIN64)
+#define GPR_PLATFORM_STRING "windows"
 #define GPR_WIN32 1
 #define GPR_ARCH_64 1
 #define GPR_GETPID_IN_PROCESS_H 1
@@ -84,6 +85,7 @@
 #endif
 #define GPR_WINDOWS_CRASH_HANDLER 1
 #elif defined(_WIN32) || defined(WIN32)
+#define GPR_PLATFORM_STRING "windows"
 #define GPR_ARCH_32 1
 #define GPR_WIN32 1
 #define GPR_GETPID_IN_PROCESS_H 1
@@ -97,6 +99,7 @@
 #endif
 #define GPR_WINDOWS_CRASH_HANDLER 1
 #elif defined(ANDROID) || defined(__ANDROID__)
+#define GPR_PLATFORM_STRING "android"
 #define GPR_ANDROID 1
 #define GPR_ARCH_32 1
 #define GPR_CPU_LINUX 1
@@ -117,6 +120,7 @@
 #define GPR_GETPID_IN_UNISTD_H 1
 #define GPR_HAVE_MSG_NOSIGNAL 1
 #elif defined(__linux__)
+#define GPR_PLATFORM_STRING "linux"
 #ifndef _BSD_SOURCE
 #define _BSD_SOURCE
 #endif
@@ -173,9 +177,11 @@
 #define _BSD_SOURCE
 #endif
 #if TARGET_OS_IPHONE
+#define GPR_PLATFORM_STRING "ios"
 #define GPR_CPU_IPHONE 1
 #define GPR_PTHREAD_TLS 1
 #else /* TARGET_OS_IPHONE */
+#define GPR_PLATFORM_STRING "osx"
 #define GPR_CPU_POSIX 1
 #define GPR_GCC_TLS 1
 #endif
@@ -201,6 +207,7 @@
 #define GPR_ARCH_32 1
 #endif /* _LP64 */
 #elif defined(__FreeBSD__)
+#define GPR_PLATFORM_STRING "freebsd"
 #ifndef _BSD_SOURCE
 #define _BSD_SOURCE
 #endif
@@ -232,6 +239,11 @@
 #endif
 #endif /* GPR_NO_AUTODETECT_PLATFORM */
 
+#ifndef GPR_PLATFORM_STRING
+#warning "GPR_PLATFORM_STRING not auto-detected"
+#define GPR_PLATFORM_STRING "unknown"
+#endif
+
 /* For a common case, assume that the platform has a C99-like stdint.h */
 
 #include <stdint.h>
diff --git a/include/grpc/support/time.h b/include/grpc/support/time.h
index 3f375f6..be59c37 100644
--- a/include/grpc/support/time.h
+++ b/include/grpc/support/time.h
@@ -83,6 +83,9 @@
 /* Return the current time measured from the given clocks epoch. */
 gpr_timespec gpr_now(gpr_clock_type clock);
 
+/* Convert a timespec from one clock to another */
+gpr_timespec gpr_convert_clock_type(gpr_timespec t, gpr_clock_type target_clock);
+
 /* Return -ve, 0, or +ve according to whether a < b, a == b, or a > b
    respectively.  */
 int gpr_time_cmp(gpr_timespec a, gpr_timespec b);
diff --git a/src/core/channel/client_channel.c b/src/core/channel/client_channel.c
index 10e01eb..c1aa580 100644
--- a/src/core/channel/client_channel.c
+++ b/src/core/channel/client_channel.c
@@ -236,21 +236,6 @@
   }
 }
 
-static void pick_target(grpc_lb_policy *lb_policy, call_data *calld) {
-  grpc_metadata_batch *initial_metadata;
-  grpc_transport_stream_op *op = &calld->waiting_op;
-
-  GPR_ASSERT(op->bind_pollset);
-  GPR_ASSERT(op->send_ops);
-  GPR_ASSERT(op->send_ops->nops >= 1);
-  GPR_ASSERT(op->send_ops->ops[0].type == GRPC_OP_METADATA);
-  initial_metadata = &op->send_ops->ops[0].data.metadata;
-
-  grpc_iomgr_closure_init(&calld->async_setup_task, picked_target, calld);
-  grpc_lb_policy_pick(lb_policy, op->bind_pollset, initial_metadata,
-                      &calld->picked_channel, &calld->async_setup_task);
-}
-
 static grpc_iomgr_closure *merge_into_waiting_op(
     grpc_call_element *elem, grpc_transport_stream_op *new_op) {
   call_data *calld = elem->call_data;
@@ -358,12 +343,23 @@
           gpr_mu_lock(&chand->mu_config);
           lb_policy = chand->lb_policy;
           if (lb_policy) {
+            grpc_transport_stream_op *op = &calld->waiting_op;
+            grpc_pollset *bind_pollset = op->bind_pollset;
+            grpc_metadata_batch *initial_metadata = &op->send_ops->ops[0].data.metadata;
             GRPC_LB_POLICY_REF(lb_policy, "pick");
             gpr_mu_unlock(&chand->mu_config);
             calld->state = CALL_WAITING_FOR_PICK;
+
+            GPR_ASSERT(op->bind_pollset);
+            GPR_ASSERT(op->send_ops);
+            GPR_ASSERT(op->send_ops->nops >= 1);
+            GPR_ASSERT(
+                op->send_ops->ops[0].type == GRPC_OP_METADATA);
             gpr_mu_unlock(&calld->mu_state);
 
-            pick_target(lb_policy, calld);
+            grpc_iomgr_closure_init(&calld->async_setup_task, picked_target, calld);
+            grpc_lb_policy_pick(lb_policy, bind_pollset, initial_metadata,
+                                &calld->picked_channel, &calld->async_setup_task);
 
             GRPC_LB_POLICY_UNREF(lb_policy, "pick");
           } else if (chand->resolver != NULL) {
diff --git a/src/core/channel/http_client_filter.c b/src/core/channel/http_client_filter.c
index 63e4912..bc821b1 100644
--- a/src/core/channel/http_client_filter.c
+++ b/src/core/channel/http_client_filter.c
@@ -32,13 +32,17 @@
 
 #include "src/core/channel/http_client_filter.h"
 #include <string.h>
+#include <grpc/support/alloc.h>
 #include <grpc/support/log.h>
+#include <grpc/support/string_util.h>
+#include "src/core/support/string.h"
 
 typedef struct call_data {
   grpc_linked_mdelem method;
   grpc_linked_mdelem scheme;
   grpc_linked_mdelem te_trailers;
   grpc_linked_mdelem content_type;
+  grpc_linked_mdelem user_agent;
   int sent_initial_metadata;
 
   int got_initial_metadata;
@@ -58,6 +62,8 @@
   grpc_mdelem *scheme;
   grpc_mdelem *content_type;
   grpc_mdelem *status;
+  /** complete user agent mdelem */
+  grpc_mdelem *user_agent;
 } channel_data;
 
 /* used to silence 'variable not used' warnings */
@@ -115,6 +121,8 @@
                                    GRPC_MDELEM_REF(channeld->te_trailers));
       grpc_metadata_batch_add_tail(&op->data.metadata, &calld->content_type,
                                    GRPC_MDELEM_REF(channeld->content_type));
+      grpc_metadata_batch_add_tail(&op->data.metadata, &calld->user_agent,
+                                   GRPC_MDELEM_REF(channeld->user_agent));
       break;
     }
   }
@@ -169,6 +177,55 @@
   return "http";
 }
 
+static grpc_mdstr *user_agent_from_args(grpc_mdctx *mdctx,
+                                        const grpc_channel_args *args) {
+  gpr_strvec v;
+  size_t i;
+  int is_first = 1;
+  char *tmp;
+  grpc_mdstr *result;
+
+  gpr_strvec_init(&v);
+
+  for (i = 0; args && i < args->num_args; i++) {
+    if (0 == strcmp(args->args[i].key, GRPC_ARG_PRIMARY_USER_AGENT_STRING)) {
+      if (args->args[i].type != GRPC_ARG_STRING) {
+        gpr_log(GPR_ERROR, "Channel argument '%s' should be a string",
+                GRPC_ARG_PRIMARY_USER_AGENT_STRING);
+      } else {
+        if (!is_first) gpr_strvec_add(&v, gpr_strdup(" "));
+        is_first = 0;
+        gpr_strvec_add(&v, gpr_strdup(args->args[i].value.string));
+      }
+    }
+  }
+
+  gpr_asprintf(&tmp, "%sgrpc-c/%s (%s)", is_first ? "" : " ",
+               grpc_version_string(), GPR_PLATFORM_STRING);
+  is_first = 0;
+  gpr_strvec_add(&v, tmp);
+
+  for (i = 0; args && i < args->num_args; i++) {
+    if (0 == strcmp(args->args[i].key, GRPC_ARG_SECONDARY_USER_AGENT_STRING)) {
+      if (args->args[i].type != GRPC_ARG_STRING) {
+        gpr_log(GPR_ERROR, "Channel argument '%s' should be a string",
+                GRPC_ARG_SECONDARY_USER_AGENT_STRING);
+      } else {
+        if (!is_first) gpr_strvec_add(&v, gpr_strdup(" "));
+        is_first = 0;
+        gpr_strvec_add(&v, gpr_strdup(args->args[i].value.string));
+      }
+    }
+  }
+
+  tmp = gpr_strvec_flatten(&v, NULL);
+  gpr_strvec_destroy(&v);
+  result = grpc_mdstr_from_string(mdctx, tmp);
+  gpr_free(tmp);
+
+  return result;
+}
+
 /* Constructor for channel_data */
 static void init_channel_elem(grpc_channel_element *elem, grpc_channel *master,
                               const grpc_channel_args *args, grpc_mdctx *mdctx,
@@ -189,6 +246,9 @@
   channeld->content_type =
       grpc_mdelem_from_strings(mdctx, "content-type", "application/grpc");
   channeld->status = grpc_mdelem_from_strings(mdctx, ":status", "200");
+  channeld->user_agent = grpc_mdelem_from_metadata_strings(
+      mdctx, grpc_mdstr_from_string(mdctx, "user-agent"),
+      user_agent_from_args(mdctx, args));
 }
 
 /* Destructor for channel data */
@@ -201,6 +261,7 @@
   GRPC_MDELEM_UNREF(channeld->scheme);
   GRPC_MDELEM_UNREF(channeld->content_type);
   GRPC_MDELEM_UNREF(channeld->status);
+  GRPC_MDELEM_UNREF(channeld->user_agent);
 }
 
 const grpc_channel_filter grpc_http_client_filter = {
diff --git a/src/core/client_config/subchannel.c b/src/core/client_config/subchannel.c
index 35f1726..487f5af 100644
--- a/src/core/client_config/subchannel.c
+++ b/src/core/client_config/subchannel.c
@@ -300,7 +300,7 @@
 }
 
 static void start_connect(grpc_subchannel *c) {
-  gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
+  gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
   c->next_attempt = now;
   c->backoff_delta = gpr_time_from_seconds(1, GPR_TIMESPAN);
 
@@ -585,7 +585,7 @@
     c->have_alarm = 1;
     c->next_attempt = gpr_time_add(c->next_attempt, c->backoff_delta);
     c->backoff_delta = gpr_time_add(c->backoff_delta, c->backoff_delta);
-    grpc_alarm_init(&c->alarm, c->next_attempt, on_alarm, c, gpr_now(GPR_CLOCK_REALTIME));
+    grpc_alarm_init(&c->alarm, c->next_attempt, on_alarm, c, gpr_now(GPR_CLOCK_MONOTONIC));
     gpr_mu_unlock(&c->mu);
   }
 }
diff --git a/src/core/iomgr/alarm.c b/src/core/iomgr/alarm.c
index 5b9a37e..931f746 100644
--- a/src/core/iomgr/alarm.c
+++ b/src/core/iomgr/alarm.c
@@ -36,6 +36,7 @@
 #include "src/core/iomgr/alarm_heap.h"
 #include "src/core/iomgr/alarm_internal.h"
 #include "src/core/iomgr/time_averaged_stats.h"
+#include <grpc/support/log.h>
 #include <grpc/support/sync.h>
 #include <grpc/support/useful.h>
 
@@ -67,6 +68,7 @@
 static gpr_mu g_mu;
 /* Allow only one run_some_expired_alarms at once */
 static gpr_mu g_checker_mu;
+static gpr_clock_type g_clock_type;
 static shard_type g_shards[NUM_SHARDS];
 /* Protected by g_mu */
 static shard_type *g_shard_queue[NUM_SHARDS];
@@ -85,6 +87,7 @@
 
   gpr_mu_init(&g_mu);
   gpr_mu_init(&g_checker_mu);
+  g_clock_type = now.clock_type;
 
   for (i = 0; i < NUM_SHARDS; i++) {
     shard_type *shard = &g_shards[i];
@@ -102,7 +105,7 @@
 
 void grpc_alarm_list_shutdown(void) {
   int i;
-  while (run_some_expired_alarms(NULL, gpr_inf_future(GPR_CLOCK_REALTIME), NULL,
+  while (run_some_expired_alarms(NULL, gpr_inf_future(g_clock_type), NULL,
                                  0))
     ;
   for (i = 0; i < NUM_SHARDS; i++) {
@@ -175,6 +178,8 @@
                      gpr_timespec now) {
   int is_first_alarm = 0;
   shard_type *shard = &g_shards[shard_idx(alarm)];
+  GPR_ASSERT(deadline.clock_type == g_clock_type);
+  GPR_ASSERT(now.clock_type == g_clock_type);
   alarm->cb = alarm_cb;
   alarm->cb_arg = alarm_cb_arg;
   alarm->deadline = deadline;
@@ -355,6 +360,7 @@
 }
 
 int grpc_alarm_check(gpr_mu *drop_mu, gpr_timespec now, gpr_timespec *next) {
+  GPR_ASSERT(now.clock_type == g_clock_type);
   return run_some_expired_alarms(drop_mu, now, next, 1);
 }
 
diff --git a/src/core/iomgr/iomgr.c b/src/core/iomgr/iomgr.c
index 0244f68..a18c176 100644
--- a/src/core/iomgr/iomgr.c
+++ b/src/core/iomgr/iomgr.c
@@ -57,9 +57,9 @@
 static void background_callback_executor(void *ignored) {
   gpr_mu_lock(&g_mu);
   while (!g_shutdown) {
-    gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_REALTIME);
+    gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC);
     gpr_timespec short_deadline = gpr_time_add(
-        gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(100, GPR_TIMESPAN));
+        gpr_now(GPR_CLOCK_MONOTONIC), gpr_time_from_millis(100, GPR_TIMESPAN));
     if (g_cbs_head) {
       grpc_iomgr_closure *closure = g_cbs_head;
       g_cbs_head = closure->next;
@@ -67,7 +67,7 @@
       gpr_mu_unlock(&g_mu);
       closure->cb(closure->cb_arg, closure->success);
       gpr_mu_lock(&g_mu);
-    } else if (grpc_alarm_check(&g_mu, gpr_now(GPR_CLOCK_REALTIME),
+    } else if (grpc_alarm_check(&g_mu, gpr_now(GPR_CLOCK_MONOTONIC),
                                 &deadline)) {
     } else {
       gpr_mu_unlock(&g_mu);
@@ -90,7 +90,7 @@
   gpr_thd_id id;
   gpr_mu_init(&g_mu);
   gpr_cv_init(&g_rcv);
-  grpc_alarm_list_init(gpr_now(GPR_CLOCK_REALTIME));
+  grpc_alarm_list_init(gpr_now(GPR_CLOCK_MONOTONIC));
   g_root_object.next = g_root_object.prev = &g_root_object;
   g_root_object.name = "root";
   grpc_iomgr_platform_init();
@@ -145,7 +145,7 @@
       } while (g_cbs_head);
       continue;
     }
-    if (grpc_alarm_check(&g_mu, gpr_inf_future(GPR_CLOCK_REALTIME), NULL)) {
+    if (grpc_alarm_check(&g_mu, gpr_inf_future(GPR_CLOCK_MONOTONIC), NULL)) {
       gpr_log(GPR_DEBUG, "got late alarm");
       continue;
     }
diff --git a/src/core/iomgr/pollset_posix.c b/src/core/iomgr/pollset_posix.c
index efb301d..c8646af 100644
--- a/src/core/iomgr/pollset_posix.c
+++ b/src/core/iomgr/pollset_posix.c
@@ -136,7 +136,7 @@
 
 int grpc_pollset_work(grpc_pollset *pollset, gpr_timespec deadline) {
   /* pollset->mu already held */
-  gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
+  gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
   if (gpr_time_cmp(now, deadline) > 0) {
     return 0;
   }
@@ -205,7 +205,7 @@
                                          gpr_timespec now) {
   gpr_timespec timeout;
   static const int max_spin_polling_us = 10;
-  if (gpr_time_cmp(deadline, gpr_inf_future(GPR_CLOCK_REALTIME)) == 0) {
+  if (gpr_time_cmp(deadline, gpr_inf_future(deadline.clock_type)) == 0) {
     return -1;
   }
   if (gpr_time_cmp(deadline, gpr_time_add(now, gpr_time_from_micros(
diff --git a/src/core/iomgr/pollset_windows.c b/src/core/iomgr/pollset_windows.c
index 24226cc..a9c4739 100644
--- a/src/core/iomgr/pollset_windows.c
+++ b/src/core/iomgr/pollset_windows.c
@@ -70,7 +70,7 @@
 
 int grpc_pollset_work(grpc_pollset *pollset, gpr_timespec deadline) {
   gpr_timespec now;
-  now = gpr_now(GPR_CLOCK_REALTIME);
+  now = gpr_now(GPR_CLOCK_MONOTONIC);
   if (gpr_time_cmp(now, deadline) > 0) {
     return 0 /* GPR_FALSE */;
   }
diff --git a/src/core/iomgr/tcp_client_posix.c b/src/core/iomgr/tcp_client_posix.c
index dc0489e..41d8b16 100644
--- a/src/core/iomgr/tcp_client_posix.c
+++ b/src/core/iomgr/tcp_client_posix.c
@@ -114,6 +114,8 @@
   void (*cb)(void *arg, grpc_endpoint *tcp) = ac->cb;
   void *cb_arg = ac->cb_arg;
 
+  grpc_alarm_cancel(&ac->alarm);
+
   gpr_mu_lock(&ac->mu);
   if (success) {
     do {
@@ -178,8 +180,6 @@
   if (done) {
     gpr_mu_destroy(&ac->mu);
     gpr_free(ac);
-  } else {
-    grpc_alarm_cancel(&ac->alarm);
   }
   cb(cb_arg, ep);
 }
@@ -253,8 +253,8 @@
   ac->write_closure.cb_arg = ac;
 
   gpr_mu_lock(&ac->mu);
-  grpc_alarm_init(&ac->alarm, deadline, on_alarm, ac,
-                  gpr_now(GPR_CLOCK_REALTIME));
+  grpc_alarm_init(&ac->alarm, gpr_convert_clock_type(deadline, GPR_CLOCK_MONOTONIC), 
+                  on_alarm, ac, gpr_now(GPR_CLOCK_MONOTONIC));
   grpc_fd_notify_on_write(ac->fd, &ac->write_closure);
   gpr_mu_unlock(&ac->mu);
 
diff --git a/src/core/iomgr/tcp_client_windows.c b/src/core/iomgr/tcp_client_windows.c
index 1674145..39fd431 100644
--- a/src/core/iomgr/tcp_client_windows.c
+++ b/src/core/iomgr/tcp_client_windows.c
@@ -216,7 +216,7 @@
   ac->aborted = 0;
 
   grpc_alarm_init(&ac->alarm, deadline, on_alarm, ac,
-                  gpr_now(GPR_CLOCK_REALTIME));
+                  gpr_now(GPR_CLOCK_MONOTONIC));
   socket->write_info.outstanding = 1;
   grpc_socket_notify_on_write(socket, on_connect, ac);
   return;
diff --git a/src/core/support/sync_posix.c b/src/core/support/sync_posix.c
index 41af8ce..61572b9 100644
--- a/src/core/support/sync_posix.c
+++ b/src/core/support/sync_posix.c
@@ -63,10 +63,11 @@
 
 int gpr_cv_wait(gpr_cv *cv, gpr_mu *mu, gpr_timespec abs_deadline) {
   int err = 0;
-  if (gpr_time_cmp(abs_deadline, gpr_inf_future(GPR_CLOCK_REALTIME)) == 0) {
+  if (gpr_time_cmp(abs_deadline, gpr_inf_future(abs_deadline.clock_type)) == 0) {
     err = pthread_cond_wait(cv, mu);
   } else {
     struct timespec abs_deadline_ts;
+    abs_deadline = gpr_convert_clock_type(abs_deadline, GPR_CLOCK_REALTIME);
     abs_deadline_ts.tv_sec = abs_deadline.tv_sec;
     abs_deadline_ts.tv_nsec = abs_deadline.tv_nsec;
     err = pthread_cond_timedwait(cv, mu, &abs_deadline_ts);
diff --git a/src/core/support/sync_win32.c b/src/core/support/sync_win32.c
index 63196d1..54f84a4 100644
--- a/src/core/support/sync_win32.c
+++ b/src/core/support/sync_win32.c
@@ -83,10 +83,10 @@
   int timeout = 0;
   DWORD timeout_max_ms;
   mu->locked = 0;
-  if (gpr_time_cmp(abs_deadline, gpr_inf_future(GPR_CLOCK_REALTIME)) == 0) {
+  if (gpr_time_cmp(abs_deadline, gpr_inf_future(abs_deadline.clock_type)) == 0) {
     SleepConditionVariableCS(cv, &mu->cs, INFINITE);
   } else {
-    gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
+    gpr_timespec now = gpr_now(abs_deadline.clock_type);
     gpr_int64 now_ms = now.tv_sec * 1000 + now.tv_nsec / 1000000;
     gpr_int64 deadline_ms =
         abs_deadline.tv_sec * 1000 + abs_deadline.tv_nsec / 1000000;
diff --git a/src/core/support/time.c b/src/core/support/time.c
index 570f195..b523ae0 100644
--- a/src/core/support/time.c
+++ b/src/core/support/time.c
@@ -290,3 +290,30 @@
 double gpr_timespec_to_micros(gpr_timespec t) {
   return (double)t.tv_sec * GPR_US_PER_SEC + t.tv_nsec * 1e-3;
 }
+
+gpr_timespec gpr_convert_clock_type(gpr_timespec t, gpr_clock_type clock_type) {
+  if (t.clock_type == clock_type) {
+    return t;
+  }
+
+  if (t.tv_nsec == 0) {
+    if (t.tv_sec == TYPE_MAX(time_t)) {
+      t.clock_type = clock_type;
+      return t;
+    }
+    if (t.tv_sec == TYPE_MIN(time_t)) {
+      t.clock_type = clock_type;
+      return t;
+    }
+  }
+
+  if (clock_type == GPR_TIMESPAN) {
+    return gpr_time_sub(t, gpr_now(t.clock_type));
+  }
+
+  if (t.clock_type == GPR_TIMESPAN) {
+    return gpr_time_add(gpr_now(clock_type), t);
+  }
+
+  return gpr_time_add(gpr_now(clock_type), gpr_time_sub(t, gpr_now(t.clock_type)));
+}
diff --git a/src/core/support/time_posix.c b/src/core/support/time_posix.c
index 258b2e6..841485c 100644
--- a/src/core/support/time_posix.c
+++ b/src/core/support/time_posix.c
@@ -120,7 +120,7 @@
   for (;;) {
     /* We could simplify by using clock_nanosleep instead, but it might be
      * slightly less portable. */
-    now = gpr_now(GPR_CLOCK_REALTIME);
+    now = gpr_now(until.clock_type);
     if (gpr_time_cmp(until, now) <= 0) {
       return;
     }
diff --git a/src/core/support/time_win32.c b/src/core/support/time_win32.c
index 238cd07..7f64c80 100644
--- a/src/core/support/time_win32.c
+++ b/src/core/support/time_win32.c
@@ -80,7 +80,7 @@
   for (;;) {
     /* We could simplify by using clock_nanosleep instead, but it might be
      * slightly less portable. */
-    now = gpr_now(GPR_CLOCK_REALTIME);
+    now = gpr_now(until.clock_type);
     if (gpr_time_cmp(until, now) <= 0) {
       return;
     }
diff --git a/src/core/surface/call.c b/src/core/surface/call.c
index 6e643b5..e08273e 100644
--- a/src/core/surface/call.c
+++ b/src/core/surface/call.c
@@ -348,7 +348,7 @@
   }
   grpc_call_stack_init(channel_stack, server_transport_data, initial_op_ptr,
                        CALL_STACK_FROM_CALL(call));
-  if (gpr_time_cmp(send_deadline, gpr_inf_future(GPR_CLOCK_REALTIME)) != 0) {
+  if (gpr_time_cmp(send_deadline, gpr_inf_future(send_deadline.clock_type)) != 0) {
     set_deadline_alarm(call, send_deadline);
   }
   return call;
@@ -1278,8 +1278,8 @@
   }
   GRPC_CALL_INTERNAL_REF(call, "alarm");
   call->have_alarm = 1;
-  grpc_alarm_init(&call->alarm, deadline, call_alarm, call,
-                  gpr_now(GPR_CLOCK_REALTIME));
+  grpc_alarm_init(&call->alarm, gpr_convert_clock_type(deadline, GPR_CLOCK_MONOTONIC), call_alarm, call,
+                  gpr_now(GPR_CLOCK_MONOTONIC));
 }
 
 /* we offset status by a small amount when storing it into transport metadata
diff --git a/src/core/surface/call.h b/src/core/surface/call.h
index 3b6f9c9..265638d 100644
--- a/src/core/surface/call.h
+++ b/src/core/surface/call.h
@@ -134,6 +134,10 @@
                                   grpc_completion_queue *cq_for_notification,
                                   void *tag);
 
+void grpc_server_log_shutdown(char *file, int line, gpr_log_severity severity,
+                              grpc_server *server, grpc_completion_queue *cq,
+                              void *tag);
+
 /* Set a context pointer.
    No thread safety guarantees are made wrt this value. */
 void grpc_call_context_set(grpc_call *call, grpc_context_index elem,
@@ -151,6 +155,9 @@
   grpc_server_log_request_call(sev, server, call, details, initial_metadata, \
                                cq_bound_to_call, cq_for_notifications, tag)
 
+#define GRPC_SERVER_LOG_SHUTDOWN(sev, server, cq, tag) \
+  if (grpc_trace_batch) grpc_server_log_shutdown(sev, server, cq, tag)
+
 gpr_uint8 grpc_call_is_client(grpc_call *call);
 
 #endif /* GRPC_INTERNAL_CORE_SURFACE_CALL_H */
diff --git a/src/core/surface/call_log_batch.c b/src/core/surface/call_log_batch.c
index 997046d..7bf8caf 100644
--- a/src/core/surface/call_log_batch.c
+++ b/src/core/surface/call_log_batch.c
@@ -136,3 +136,11 @@
           "tag=%p)", server, call, details, initial_metadata,
           cq_bound_to_call, cq_for_notification, tag);
 }
+
+void grpc_server_log_shutdown(char *file, int line, gpr_log_severity severity,
+                              grpc_server *server, grpc_completion_queue *cq,
+                              void *tag) {
+  gpr_log(file, line, severity,
+          "grpc_server_shutdown_and_notify(server=%p, cq=%p, tag=%p)", server,
+          cq, tag);
+}
diff --git a/src/core/surface/completion_queue.c b/src/core/surface/completion_queue.c
index 8484418..3f60b0b 100644
--- a/src/core/surface/completion_queue.c
+++ b/src/core/surface/completion_queue.c
@@ -148,6 +148,8 @@
                                       gpr_timespec deadline) {
   grpc_event ret;
 
+  deadline = gpr_convert_clock_type(deadline, GPR_CLOCK_MONOTONIC);
+
   GRPC_CQ_INTERNAL_REF(cc, "next");
   gpr_mu_lock(GRPC_POLLSET_MU(&cc->pollset));
   for (;;) {
@@ -188,6 +190,8 @@
   grpc_cq_completion *c;
   grpc_cq_completion *prev;
 
+  deadline = gpr_convert_clock_type(deadline, GPR_CLOCK_MONOTONIC);
+
   GRPC_CQ_INTERNAL_REF(cc, "pluck");
   gpr_mu_lock(GRPC_POLLSET_MU(&cc->pollset));
   for (;;) {
diff --git a/src/core/surface/server.c b/src/core/surface/server.c
index f2d6b11..439452a 100644
--- a/src/core/surface/server.c
+++ b/src/core/surface/server.c
@@ -980,6 +980,8 @@
   channel_broadcaster broadcaster;
   request_killer reqkill;
 
+  GRPC_SERVER_LOG_SHUTDOWN(GPR_INFO, server, cq, tag);
+
   /* lock, and gather up some stuff to do */
   gpr_mu_lock(&server->mu_global);
   grpc_cq_begin_op(cq);
diff --git a/src/core/transport/chttp2/parsing.c b/src/core/transport/chttp2/parsing.c
index aa32f2e..904b9af 100644
--- a/src/core/transport/chttp2/parsing.c
+++ b/src/core/transport/chttp2/parsing.c
@@ -588,7 +588,7 @@
   GPR_ASSERT(stream_parsing);
 
   GRPC_CHTTP2_IF_TRACING(gpr_log(
-      GPR_INFO, "HTTP:%d:HDR: %s: %s", stream_parsing->id,
+      GPR_INFO, "HTTP:%d:HDR:%s: %s: %s", stream_parsing->id,
       transport_parsing->is_client ? "CLI" : "SVR",
       grpc_mdstr_as_c_string(md->key), grpc_mdstr_as_c_string(md->value)));
 
diff --git a/src/core/transport/chttp2/stream_encoder.c b/src/core/transport/chttp2/stream_encoder.c
index d30059a..65b31a5 100644
--- a/src/core/transport/chttp2/stream_encoder.c
+++ b/src/core/transport/chttp2/stream_encoder.c
@@ -438,7 +438,7 @@
   char timeout_str[GRPC_CHTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE];
   grpc_mdelem *mdelem;
   grpc_chttp2_encode_timeout(
-      gpr_time_sub(deadline, gpr_now(GPR_CLOCK_REALTIME)), timeout_str);
+      gpr_time_sub(deadline, gpr_now(deadline.clock_type)), timeout_str);
   mdelem = grpc_mdelem_from_metadata_strings(
       c->mdctx, GRPC_MDSTR_REF(c->timeout_key_str),
       grpc_mdstr_from_string(c->mdctx, timeout_str));
@@ -560,6 +560,7 @@
   grpc_mdctx *mdctx = compressor->mdctx;
   grpc_linked_mdelem *l;
   int need_unref = 0;
+  gpr_timespec deadline;
 
   GPR_ASSERT(stream_id != 0);
 
@@ -589,9 +590,9 @@
           l->md = hpack_enc(compressor, l->md, &st);
           need_unref |= l->md != NULL;
         }
-        if (gpr_time_cmp(op->data.metadata.deadline,
-                         gpr_inf_future(GPR_CLOCK_REALTIME)) != 0) {
-          deadline_enc(compressor, op->data.metadata.deadline, &st);
+        deadline = op->data.metadata.deadline;
+        if (gpr_time_cmp(deadline, gpr_inf_future(deadline.clock_type)) != 0) {
+          deadline_enc(compressor, deadline, &st);
         }
         curop++;
         break;
diff --git a/src/core/transport/transport_op_string.c b/src/core/transport/transport_op_string.c
index 9d127c5..10d796f 100644
--- a/src/core/transport/transport_op_string.c
+++ b/src/core/transport/transport_op_string.c
@@ -61,7 +61,7 @@
     if (m != md.list.head) gpr_strvec_add(b, gpr_strdup(", "));
     put_metadata(b, m->md);
   }
-  if (gpr_time_cmp(md.deadline, gpr_inf_future(GPR_CLOCK_REALTIME)) != 0) {
+  if (gpr_time_cmp(md.deadline, gpr_inf_future(md.deadline.clock_type)) != 0) {
     char *tmp;
     gpr_asprintf(&tmp, " deadline=%d.%09d", md.deadline.tv_sec,
                  md.deadline.tv_nsec);
diff --git a/src/cpp/client/channel_arguments.cc b/src/cpp/client/channel_arguments.cc
index 92ac5ea..da6602e 100644
--- a/src/cpp/client/channel_arguments.cc
+++ b/src/cpp/client/channel_arguments.cc
@@ -33,11 +33,49 @@
 
 #include <grpc++/channel_arguments.h>
 
+#include <grpc/support/log.h>
+
 #include "src/core/channel/channel_args.h"
 
 namespace grpc {
 
-void ChannelArguments::_Experimental_SetCompressionAlgorithm(
+ChannelArguments::ChannelArguments(const ChannelArguments& other)
+    : strings_(other.strings_) {
+  args_.reserve(other.args_.size());
+  auto list_it_dst = strings_.begin();
+  auto list_it_src = other.strings_.begin();
+  for (auto a = other.args_.begin(); a != other.args_.end(); ++a) {
+    grpc_arg ap;
+    ap.type = a->type;
+    GPR_ASSERT(list_it_src->c_str() == a->key);
+    ap.key = const_cast<char*>(list_it_dst->c_str());
+    ++list_it_src;
+    ++list_it_dst;
+    switch (a->type) {
+      case GRPC_ARG_INTEGER:
+        ap.value.integer = a->value.integer;
+        break;
+      case GRPC_ARG_STRING:
+        GPR_ASSERT(list_it_src->c_str() == a->value.string);
+        ap.value.string = const_cast<char*>(list_it_dst->c_str());
+        ++list_it_src;
+        ++list_it_dst;
+        break;
+      case GRPC_ARG_POINTER:
+        ap.value.pointer = a->value.pointer;
+        ap.value.pointer.p = a->value.pointer.copy(ap.value.pointer.p);
+        break;
+    }
+    args_.push_back(ap);
+  }
+}
+
+void ChannelArguments::Swap(ChannelArguments& other) {
+  args_.swap(other.args_);
+  strings_.swap(other.strings_);
+}
+
+void ChannelArguments::SetCompressionAlgorithm(
     grpc_compression_algorithm algorithm) {
   SetInt(GRPC_COMPRESSION_ALGORITHM_ARG, algorithm);
 }
diff --git a/src/cpp/client/client_context.cc b/src/cpp/client/client_context.cc
index 69216d2..14ab772 100644
--- a/src/cpp/client/client_context.cc
+++ b/src/cpp/client/client_context.cc
@@ -79,7 +79,7 @@
   }
 }
 
-void ClientContext::_experimental_set_compression_algorithm(
+void ClientContext::set_compression_algorithm(
     grpc_compression_algorithm algorithm) {
   char* algorithm_name = NULL;
   if (!grpc_compression_algorithm_name(algorithm, &algorithm_name)) {
diff --git a/src/cpp/client/create_channel.cc b/src/cpp/client/create_channel.cc
index 510af2b..38eeda0 100644
--- a/src/cpp/client/create_channel.cc
+++ b/src/cpp/client/create_channel.cc
@@ -32,9 +32,11 @@
  */
 
 #include <memory>
+#include <sstream>
 
 #include "src/cpp/client/channel.h"
 #include <grpc++/channel_interface.h>
+#include <grpc++/channel_arguments.h>
 #include <grpc++/create_channel.h>
 
 namespace grpc {
@@ -43,7 +45,12 @@
 std::shared_ptr<ChannelInterface> CreateChannel(
     const grpc::string& target, const std::shared_ptr<Credentials>& creds,
     const ChannelArguments& args) {
-  return creds ? creds->CreateChannel(target, args)
+  ChannelArguments cp_args = args;
+  std::ostringstream user_agent_prefix;
+  user_agent_prefix << "grpc-c++/" << grpc_version_string();
+  cp_args.SetString(GRPC_ARG_PRIMARY_USER_AGENT_STRING,
+                    user_agent_prefix.str());
+  return creds ? creds->CreateChannel(target, cp_args)
                : std::shared_ptr<ChannelInterface>(
                      new Channel(target, grpc_lame_client_channel_create()));
 }
diff --git a/src/csharp/Grpc.Auth/GoogleCredential.cs b/src/csharp/Grpc.Auth/GoogleCredential.cs
index 8d5e543..7edf19e 100644
--- a/src/csharp/Grpc.Auth/GoogleCredential.cs
+++ b/src/csharp/Grpc.Auth/GoogleCredential.cs
@@ -35,8 +35,11 @@
 using System.Collections.Generic;
 using System.IO;
 using System.Security.Cryptography;
+using System.Threading;
+using System.Threading.Tasks;
 
 using Google.Apis.Auth.OAuth2;
+using Google.Apis.Auth.OAuth2.Responses;
 using Newtonsoft.Json.Linq;
 using Org.BouncyCastle.Crypto.Parameters;
 using Org.BouncyCastle.Security;
@@ -100,6 +103,19 @@
             return new GoogleCredential(serviceCredential);
         }
 
+        public Task<bool> RequestAccessTokenAsync(CancellationToken taskCancellationToken)
+        {
+            return credential.RequestAccessTokenAsync(taskCancellationToken);
+        }
+
+        public TokenResponse Token
+        {
+            get
+            {
+                return credential.Token;
+            }
+        }
+
         internal ServiceCredential InternalCredential
         {
             get
diff --git a/src/csharp/Grpc.Core.Tests/Internal/MetadataArraySafeHandleTest.cs b/src/csharp/Grpc.Core.Tests/Internal/MetadataArraySafeHandleTest.cs
index 320423b..e03e20c 100644
--- a/src/csharp/Grpc.Core.Tests/Internal/MetadataArraySafeHandleTest.cs
+++ b/src/csharp/Grpc.Core.Tests/Internal/MetadataArraySafeHandleTest.cs
@@ -51,7 +51,8 @@
         [Test]
         public void CreateAndDestroy()
         {
-            var metadata = new Metadata {
+            var metadata = new Metadata
+            {
                 new Metadata.Entry("host", "somehost"),
                 new Metadata.Entry("header2", "header value"),
             };
diff --git a/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj b/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj
index af4a75a..d3c69ab 100644
--- a/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj
+++ b/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj
@@ -32,21 +32,34 @@
     <PlatformTarget>x86</PlatformTarget>
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="Google.Apis.Auth.PlatformServices">
+    <Reference Include="Google.Apis.Auth, Version=1.9.1.12395, Culture=neutral, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\packages\Google.Apis.Auth.1.9.1\lib\net40\Google.Apis.Auth.dll</HintPath>
+    </Reference>
+    <Reference Include="Google.Apis.Auth.PlatformServices, Version=1.9.1.12399, Culture=neutral, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
       <HintPath>..\packages\Google.Apis.Auth.1.9.1\lib\net40\Google.Apis.Auth.PlatformServices.dll</HintPath>
     </Reference>
-    <Reference Include="Google.Apis.Core">
+    <Reference Include="Google.Apis.Core, Version=1.9.1.12394, Culture=neutral, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
       <HintPath>..\packages\Google.Apis.Core.1.9.1\lib\portable-net40+sl50+win+wpa81+wp80\Google.Apis.Core.dll</HintPath>
     </Reference>
-    <Reference Include="Microsoft.Threading.Tasks">
+    <Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
       <HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
     </Reference>
-    <Reference Include="Microsoft.Threading.Tasks.Extensions">
+    <Reference Include="Microsoft.Threading.Tasks.Extensions, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
       <HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
     </Reference>
-    <Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop">
+    <Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop, Version=1.0.168.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
       <HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
     </Reference>
+    <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\packages\Newtonsoft.Json.6.0.6\lib\net45\Newtonsoft.Json.dll</HintPath>
+    </Reference>
     <Reference Include="nunit.framework">
       <HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
     </Reference>
@@ -63,16 +76,15 @@
     </Reference>
     <Reference Include="System.Net" />
     <Reference Include="System.Net.Http" />
-    <Reference Include="System.Net.Http.Extensions">
+    <Reference Include="System.Net.Http.Extensions, Version=2.2.28.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
       <HintPath>..\packages\Microsoft.Net.Http.2.2.28\lib\net45\System.Net.Http.Extensions.dll</HintPath>
     </Reference>
-    <Reference Include="System.Net.Http.Primitives">
+    <Reference Include="System.Net.Http.Primitives, Version=4.2.28.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
       <HintPath>..\packages\Microsoft.Net.Http.2.2.28\lib\net45\System.Net.Http.Primitives.dll</HintPath>
     </Reference>
     <Reference Include="System.Net.Http.WebRequest" />
-    <Reference Include="Newtonsoft.Json">
-      <HintPath>..\packages\Newtonsoft.Json.6.0.6\lib\net45\Newtonsoft.Json.dll</HintPath>
-    </Reference>
   </ItemGroup>
   <ItemGroup>
     <Compile Include="..\Grpc.Core\Version.cs">
diff --git a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs
index 05e732d..ea83aaf 100644
--- a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs
+++ b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs
@@ -135,7 +135,7 @@
             GrpcEnvironment.Shutdown();
         }
 
-        private void RunTestCase(string testCase, TestService.ITestServiceClient client)
+        private void RunTestCase(string testCase, TestService.TestServiceClient client)
         {
             switch (testCase)
             {
@@ -163,6 +163,12 @@
                 case "compute_engine_creds":
                     RunComputeEngineCreds(client);
                     break;
+                case "oauth2_auth_token":
+                    RunOAuth2AuthToken(client);
+                    break;
+                case "per_rpc_creds":
+                    RunPerRpcCreds(client);
+                    break;
                 case "cancel_after_begin":
                     RunCancelAfterBegin(client);
                     break;
@@ -355,6 +361,51 @@
             Console.WriteLine("Passed!");
         }
 
+        public static void RunOAuth2AuthToken(TestService.TestServiceClient client)
+        {
+            Console.WriteLine("running oauth2_auth_token");
+            var credential = GoogleCredential.GetApplicationDefault().CreateScoped(new[] { AuthScope });
+            Assert.IsTrue(credential.RequestAccessTokenAsync(CancellationToken.None).Result);
+            string oauth2Token = credential.Token.AccessToken;
+
+            // Intercept calls with an OAuth2 token obtained out-of-band.
+            client.HeaderInterceptor = new MetadataInterceptorDelegate((metadata) =>
+            {
+                metadata.Add(new Metadata.Entry("Authorization", "Bearer " + oauth2Token));
+            });
+
+            var request = SimpleRequest.CreateBuilder()
+                .SetFillUsername(true)
+                .SetFillOauthScope(true)
+                .Build();
+
+            var response = client.UnaryCall(request);
+
+            Assert.AreEqual(AuthScopeResponse, response.OauthScope);
+            Assert.AreEqual(ServiceAccountUser, response.Username);
+            Console.WriteLine("Passed!");
+        }
+
+        public static void RunPerRpcCreds(TestService.TestServiceClient client)
+        {
+            Console.WriteLine("running per_rpc_creds");
+
+            var credential = GoogleCredential.GetApplicationDefault().CreateScoped(new[] { AuthScope });
+            Assert.IsTrue(credential.RequestAccessTokenAsync(CancellationToken.None).Result);
+            string oauth2Token = credential.Token.AccessToken;
+
+            var request = SimpleRequest.CreateBuilder()
+                .SetFillUsername(true)
+                .SetFillOauthScope(true)
+                .Build();
+
+            var response = client.UnaryCall(request, headers: new Metadata { new Metadata.Entry("Authorization", "Bearer " + oauth2Token) } );
+
+            Assert.AreEqual(AuthScopeResponse, response.OauthScope);
+            Assert.AreEqual(ServiceAccountUser, response.Username);
+            Console.WriteLine("Passed!");
+        }
+
         public static void RunCancelAfterBegin(TestService.ITestServiceClient client)
         {
             Task.Run(async () =>
diff --git a/src/node/README.md b/src/node/README.md
index 2f4c490..78781da 100644
--- a/src/node/README.md
+++ b/src/node/README.md
@@ -54,10 +54,10 @@
 Returns the same structure that `load` returns, but takes a reflection object from `ProtoBuf.js` instead of a file name.
 
 ```javascript
-function buildServer(serviceArray)
+function Server([serverOpions])
 ```
 
-Takes an array of service objects and returns a constructor for a server that handles requests to all of those services.
+Constructs a server to which service/implementation pairs can be added.
 
 
 ```javascript
diff --git a/src/node/examples/math_server.js b/src/node/examples/math_server.js
index 0a86e7e..b1f8a63 100644
--- a/src/node/examples/math_server.js
+++ b/src/node/examples/math_server.js
@@ -36,8 +36,6 @@
 var grpc = require('..');
 var math = grpc.load(__dirname + '/math.proto').math;
 
-var Server = grpc.buildServer([math.Math.service]);
-
 /**
  * Server function for division. Provides the /Math/DivMany and /Math/Div
  * functions (Div is just DivMany with only one stream element). For each
@@ -108,19 +106,17 @@
     stream.end();
   });
 }
-
-var server = new Server({
-  'math.Math' : {
-    div: mathDiv,
-    fib: mathFib,
-    sum: mathSum,
-    divMany: mathDivMany
-  }
+var server = new grpc.Server();
+server.addProtoService(math.Math.service, {
+  div: mathDiv,
+  fib: mathFib,
+  sum: mathSum,
+  divMany: mathDivMany
 });
 
 if (require.main === module) {
   server.bind('0.0.0.0:50051');
-  server.listen();
+  server.start();
 }
 
 /**
diff --git a/src/node/examples/route_guide_server.js b/src/node/examples/route_guide_server.js
index c777eab..70044a3 100644
--- a/src/node/examples/route_guide_server.js
+++ b/src/node/examples/route_guide_server.js
@@ -40,8 +40,6 @@
 var grpc = require('..');
 var examples = grpc.load(__dirname + '/route_guide.proto').examples;
 
-var Server = grpc.buildServer([examples.RouteGuide.service]);
-
 var COORD_FACTOR = 1e7;
 
 /**
@@ -228,14 +226,14 @@
  * @return {Server} The new server object
  */
 function getServer() {
-  return new Server({
-    'examples.RouteGuide' : {
-      getFeature: getFeature,
-      listFeatures: listFeatures,
-      recordRoute: recordRoute,
-      routeChat: routeChat
-    }
+  var server = new grpc.Server();
+  server.addProtoService(examples.RouteGuide.service, {
+    getFeature: getFeature,
+    listFeatures: listFeatures,
+    recordRoute: recordRoute,
+    routeChat: routeChat
   });
+  return server;
 }
 
 if (require.main === module) {
diff --git a/src/node/examples/stock_server.js b/src/node/examples/stock_server.js
index caaf9f9..f2eb6ad 100644
--- a/src/node/examples/stock_server.js
+++ b/src/node/examples/stock_server.js
@@ -37,8 +37,6 @@
 var grpc = require('..');
 var examples = grpc.load(__dirname + '/stock.proto').examples;
 
-var StockServer = grpc.buildServer([examples.Stock.service]);
-
 function getLastTradePrice(call, callback) {
   callback(null, {symbol: call.request.symbol, price: 88});
 }
@@ -73,13 +71,12 @@
   });
 }
 
-var stockServer = new StockServer({
-  'examples.Stock' : {
-    getLastTradePrice: getLastTradePrice,
-    getLastTradePriceMultiple: getLastTradePriceMultiple,
-    watchFutureTrades: watchFutureTrades,
-    getHighestTradePrice: getHighestTradePrice
-  }
+var stockServer = new grpc.Server();
+stockServer.addProtoService(examples.Stock.service, {
+  getLastTradePrice: getLastTradePrice,
+  getLastTradePriceMultiple: getLastTradePriceMultiple,
+  watchFutureTrades: watchFutureTrades,
+  getHighestTradePrice: getHighestTradePrice
 });
 
 if (require.main === module) {
diff --git a/src/node/index.js b/src/node/index.js
index b6a4e2d..d81e780 100644
--- a/src/node/index.js
+++ b/src/node/index.js
@@ -133,9 +133,9 @@
 exports.load = load;
 
 /**
- * See docs for server.makeServerConstructor
+ * See docs for Server
  */
-exports.buildServer = server.makeProtobufServerConstructor;
+exports.Server = server.Server;
 
 /**
  * Status name to code number mapping
@@ -159,5 +159,3 @@
 exports.getGoogleAuthDelegate = getGoogleAuthDelegate;
 
 exports.makeGenericClientConstructor = client.makeClientConstructor;
-
-exports.makeGenericServerConstructor = server.makeServerConstructor;
diff --git a/src/node/interop/interop_client.js b/src/node/interop/interop_client.js
index b61b0b6..e810e68 100644
--- a/src/node/interop/interop_client.js
+++ b/src/node/interop/interop_client.js
@@ -318,6 +318,51 @@
   });
 }
 
+function oauth2Test(expected_user, scope, per_rpc, client, done) {
+  (new GoogleAuth()).getApplicationDefault(function(err, credential) {
+    assert.ifError(err);
+    var arg = {
+      fill_username: true,
+      fill_oauth_scope: true
+    };
+    credential = credential.createScoped(scope);
+    credential.getAccessToken(function(err, token) {
+      assert.ifError(err);
+      var updateMetadata = function(authURI, metadata, callback) {
+        metadata = _.clone(metadata);
+        if (metadata.Authorization) {
+          metadata.Authorization = _.clone(metadata.Authorization);
+        } else {
+          metadata.Authorization = [];
+        }
+        metadata.Authorization.push('Bearer ' + token);
+        callback(null, metadata);
+      };
+      var makeTestCall = function(error, client_metadata) {
+        assert.ifError(error);
+        var call = client.unaryCall(arg, function(err, resp) {
+          assert.ifError(err);
+          assert.strictEqual(resp.username, expected_user);
+          assert.strictEqual(resp.oauth_scope, AUTH_SCOPE_RESPONSE);
+        });
+        call.on('status', function(status) {
+          assert.strictEqual(status.code, grpc.status.OK);
+          if (done) {
+            done();
+          }
+        });
+      };
+      if (per_rpc) {
+        updateMetadata('', {}, makeTestCall);
+      } else {
+        client.updateMetadata = updateMetadata;
+        makeTestCall(null, {});
+      }
+
+    });
+  });
+}
+
 /**
  * Map from test case names to test functions
  */
@@ -333,7 +378,9 @@
   timeout_on_sleeping_server: timeoutOnSleepingServer,
   compute_engine_creds: _.partial(authTest, COMPUTE_ENGINE_USER, null),
   service_account_creds: _.partial(authTest, AUTH_USER, AUTH_SCOPE),
-  jwt_token_creds: _.partial(authTest, AUTH_USER, null)
+  jwt_token_creds: _.partial(authTest, AUTH_USER, null),
+  oauth2_auth_token: _.partial(oauth2Test, AUTH_USER, AUTH_SCOPE, false),
+  per_rpc_creds: _.partial(oauth2Test, AUTH_USER, AUTH_SCOPE, true)
 };
 
 /**
diff --git a/src/node/interop/interop_server.js b/src/node/interop/interop_server.js
index 0baa78a..505c6bb 100644
--- a/src/node/interop/interop_server.js
+++ b/src/node/interop/interop_server.js
@@ -38,7 +38,6 @@
 var _ = require('lodash');
 var grpc = require('..');
 var testProto = grpc.load(__dirname + '/test.proto').grpc.testing;
-var Server = grpc.buildServer([testProto.TestService.service]);
 
 /**
  * Create a buffer filled with size zeroes
@@ -173,16 +172,15 @@
                                                     key_data,
                                                     pem_data);
   }
-  var server = new Server({
-    'grpc.testing.TestService' : {
-      emptyCall: handleEmpty,
-      unaryCall: handleUnary,
-      streamingOutputCall: handleStreamingOutput,
-      streamingInputCall: handleStreamingInput,
-      fullDuplexCall: handleFullDuplex,
-      halfDuplexCall: handleHalfDuplex
-    }
-  }, null, options);
+  var server = new grpc.Server(options);
+  server.addProtoService(testProto.TestService.service, {
+    emptyCall: handleEmpty,
+    unaryCall: handleUnary,
+    streamingOutputCall: handleStreamingOutput,
+    streamingInputCall: handleStreamingInput,
+    fullDuplexCall: handleFullDuplex,
+    halfDuplexCall: handleHalfDuplex
+  });
   var port_num = server.bind('0.0.0.0:' + port, server_creds);
   return {server: server, port: port_num};
 }
diff --git a/src/node/src/server.js b/src/node/src/server.js
index 00be400..0a3a003 100644
--- a/src/node/src/server.js
+++ b/src/node/src/server.js
@@ -72,6 +72,9 @@
     status.metadata = error.metadata;
   }
   var error_batch = {};
+  if (!call.metadataSent) {
+    error_batch[grpc.opType.SEND_INITIAL_METADATA] = {};
+  }
   error_batch[grpc.opType.SEND_STATUS_FROM_SERVER] = status;
   call.startBatch(error_batch, function(){});
 }
@@ -115,6 +118,10 @@
   if (metadata) {
     status.metadata = metadata;
   }
+  if (!call.metadataSent) {
+    end_batch[grpc.opType.SEND_INITIAL_METADATA] = {};
+    call.metadataSent = true;
+  }
   end_batch[grpc.opType.SEND_MESSAGE] = serialize(value);
   end_batch[grpc.opType.SEND_STATUS_FROM_SERVER] = status;
   call.startBatch(end_batch, function (){});
@@ -136,6 +143,10 @@
   stream.serialize = common.wrapIgnoreNull(serialize);
   function sendStatus() {
     var batch = {};
+    if (!stream.call.metadataSent) {
+      stream.call.metadataSent = true;
+      batch[grpc.opType.SEND_INITIAL_METADATA] = {};
+    }
     batch[grpc.opType.SEND_STATUS_FROM_SERVER] = stream.status;
     stream.call.startBatch(batch, function(){});
   }
@@ -239,6 +250,10 @@
 function _write(chunk, encoding, callback) {
   /* jshint validthis: true */
   var batch = {};
+  if (!this.call.metadataSent) {
+    batch[grpc.opType.SEND_INITIAL_METADATA] = {};
+    this.call.metadataSent = true;
+  }
   batch[grpc.opType.SEND_MESSAGE] = this.serialize(chunk);
   this.call.startBatch(batch, function(err, value) {
     if (err) {
@@ -251,6 +266,23 @@
 
 ServerWritableStream.prototype._write = _write;
 
+function sendMetadata(responseMetadata) {
+  /* jshint validthis: true */
+  if (!this.call.metadataSent) {
+    this.call.metadataSent = true;
+    var batch = [];
+    batch[grpc.opType.SEND_INITIAL_METADATA] = responseMetadata;
+    this.call.startBatch(batch, function(err) {
+      if (err) {
+        this.emit('error', err);
+        return;
+      }
+    });
+  }
+}
+
+ServerWritableStream.prototype.sendMetadata = sendMetadata;
+
 util.inherits(ServerReadableStream, Readable);
 
 /**
@@ -339,6 +371,7 @@
 
 ServerDuplexStream.prototype._read = _read;
 ServerDuplexStream.prototype._write = _write;
+ServerDuplexStream.prototype.sendMetadata = sendMetadata;
 
 /**
  * Fully handle a unary call
@@ -348,12 +381,20 @@
  */
 function handleUnary(call, handler, metadata) {
   var emitter = new EventEmitter();
+  emitter.sendMetadata = function(responseMetadata) {
+    if (!call.metadataSent) {
+      call.metadataSent = true;
+      var batch = {};
+      batch[grpc.opType.SEND_INITIAL_METADATA] = responseMetadata;
+      call.startBatch(batch, function() {});
+    }
+  };
   emitter.on('error', function(error) {
     handleError(call, error);
   });
+  emitter.metadata = metadata;
   waitForCancel(call, emitter);
   var batch = {};
-  batch[grpc.opType.SEND_INITIAL_METADATA] = metadata;
   batch[grpc.opType.RECV_MESSAGE] = true;
   call.startBatch(batch, function(err, result) {
     if (err) {
@@ -392,8 +433,8 @@
 function handleServerStreaming(call, handler, metadata) {
   var stream = new ServerWritableStream(call, handler.serialize);
   waitForCancel(call, stream);
+  stream.metadata = metadata;
   var batch = {};
-  batch[grpc.opType.SEND_INITIAL_METADATA] = metadata;
   batch[grpc.opType.RECV_MESSAGE] = true;
   call.startBatch(batch, function(err, result) {
     if (err) {
@@ -419,13 +460,19 @@
  */
 function handleClientStreaming(call, handler, metadata) {
   var stream = new ServerReadableStream(call, handler.deserialize);
+  stream.sendMetadata = function(responseMetadata) {
+    if (!call.metadataSent) {
+      call.metadataSent = true;
+      var batch = {};
+      batch[grpc.opType.SEND_INITIAL_METADATA] = responseMetadata;
+      call.startBatch(batch, function() {});
+    }
+  };
   stream.on('error', function(error) {
     handleError(call, error);
   });
   waitForCancel(call, stream);
-  var metadata_batch = {};
-  metadata_batch[grpc.opType.SEND_INITIAL_METADATA] = metadata;
-  call.startBatch(metadata_batch, function() {});
+  stream.metadata = metadata;
   handler.func(stream, function(err, value, trailer) {
     stream.terminate();
     if (err) {
@@ -449,9 +496,7 @@
   var stream = new ServerDuplexStream(call, handler.serialize,
                                       handler.deserialize);
   waitForCancel(call, stream);
-  var metadata_batch = {};
-  metadata_batch[grpc.opType.SEND_INITIAL_METADATA] = metadata;
-  call.startBatch(metadata_batch, function() {});
+  stream.metadata = metadata;
   handler.func(stream);
 }
 
@@ -466,29 +511,28 @@
  * Constructs a server object that stores request handlers and delegates
  * incoming requests to those handlers
  * @constructor
- * @param {function(string, Object<string, Array<Buffer>>):
-           Object<string, Array<Buffer|string>>=} getMetadata Callback that gets
- *     metatada for a given method
  * @param {Object=} options Options that should be passed to the internal server
  *     implementation
  */
-function Server(getMetadata, options) {
+function Server(options) {
   this.handlers = {};
   var handlers = this.handlers;
   var server = new grpc.Server(options);
   this._server = server;
+  this.started = false;
   /**
    * Start the server and begin handling requests
    * @this Server
    */
-  this.listen = function() {
+  this.start = function() {
+    if (this.started) {
+      throw new Error('Server is already running');
+    }
+    this.started = true;
     console.log('Server starting');
     _.each(handlers, function(handler, handler_name) {
       console.log('Serving', handler_name);
     });
-    if (this.started) {
-      throw 'Server is already running';
-    }
     server.start();
     /**
      * Handles the SERVER_RPC_NEW event. If there is a handler associated with
@@ -523,11 +567,7 @@
         call.startBatch(batch, function() {});
         return;
       }
-      var response_metadata = {};
-      if (getMetadata) {
-        response_metadata = getMetadata(method, metadata);
-      }
-      streamHandlers[handler.type](call, handler, response_metadata);
+      streamHandlers[handler.type](call, handler, metadata);
     }
     server.requestCall(handleNewCall);
   };
@@ -565,6 +605,47 @@
   return true;
 };
 
+Server.prototype.addService = function(service, implementation) {
+  if (this.started) {
+    throw new Error('Can\'t add a service to a started server.');
+  }
+  var self = this;
+  _.each(service, function(attrs, name) {
+    var method_type;
+    if (attrs.requestStream) {
+      if (attrs.responseStream) {
+        method_type = 'bidi';
+      } else {
+        method_type = 'client_stream';
+      }
+    } else {
+      if (attrs.responseStream) {
+        method_type = 'server_stream';
+      } else {
+        method_type = 'unary';
+      }
+    }
+    if (implementation[name] === undefined) {
+      throw new Error('Method handler for ' + attrs.path +
+          ' not provided.');
+    }
+    var serialize = attrs.responseSerialize;
+    var deserialize = attrs.requestDeserialize;
+    var register_success = self.register(attrs.path,
+                                         _.bind(implementation[name],
+                                                implementation),
+                                         serialize, deserialize, method_type);
+    if (!register_success) {
+      throw new Error('Method handler for ' + attrs.path +
+          ' already provided.');
+    }
+  });
+};
+
+Server.prototype.addProtoService = function(service, implementation) {
+  this.addService(common.getProtobufServiceAttrs(service), implementation);
+};
+
 /**
  * Binds the server to the given port, with SSL enabled if creds is given
  * @param {string} port The port that the server should bind on, in the format
@@ -573,6 +654,9 @@
  *     nothing for an insecure port
  */
 Server.prototype.bind = function(port, creds) {
+  if (this.started) {
+    throw new Error('Can\'t bind an already running server to an address');
+  }
   if (creds) {
     return this._server.addSecureHttp2Port(port, creds);
   } else {
@@ -581,131 +665,6 @@
 };
 
 /**
- * Create a constructor for servers with services defined by service_attr_map.
- * That is an object that maps (namespaced) service names to objects that in
- * turn map method names to objects with the following keys:
- * path: The path on the server for accessing the method. For example, for
- *     protocol buffers, we use "/service_name/method_name"
- * requestStream: bool indicating whether the client sends a stream
- * resonseStream: bool indicating whether the server sends a stream
- * requestDeserialize: function to deserialize request objects
- * responseSerialize: function to serialize response objects
- * @param {Object} service_attr_map An object mapping service names to method
- *     attribute map objects
- * @return {function(Object, function, Object=)} New server constructor
+ * See documentation for Server
  */
-function makeServerConstructor(service_attr_map) {
-  /**
-   * Create a server with the given handlers for all of the methods.
-   * @constructor
-   * @param {Object} service_handlers Map from service names to map from method
-   *     names to handlers
-   * @param {function(string, Object<string, Array<Buffer>>):
-             Object<string, Array<Buffer|string>>=} getMetadata Callback that
-   *     gets metatada for a given method
-   * @param {Object=} options Options to pass to the underlying server
-   */
-  function SurfaceServer(service_handlers, getMetadata, options) {
-    var server = new Server(getMetadata, options);
-    this.inner_server = server;
-    _.each(service_attr_map, function(service_attrs, service_name) {
-      if (service_handlers[service_name] === undefined) {
-        throw new Error('Handlers for service ' +
-            service_name + ' not provided.');
-      }
-      _.each(service_attrs, function(attrs, name) {
-        var method_type;
-        if (attrs.requestStream) {
-          if (attrs.responseStream) {
-            method_type = 'bidi';
-          } else {
-            method_type = 'client_stream';
-          }
-        } else {
-          if (attrs.responseStream) {
-            method_type = 'server_stream';
-          } else {
-            method_type = 'unary';
-          }
-        }
-        if (service_handlers[service_name][name] === undefined) {
-          throw new Error('Method handler for ' + attrs.path +
-              ' not provided.');
-        }
-        var serialize = attrs.responseSerialize;
-        var deserialize = attrs.requestDeserialize;
-        server.register(attrs.path, _.bind(service_handlers[service_name][name],
-                                           service_handlers[service_name]),
-                        serialize, deserialize, method_type);
-      });
-    }, this);
-  }
-
-  /**
-   * Binds the server to the given port, with SSL enabled if creds is supplied
-   * @param {string} port The port that the server should bind on, in the format
-   *     "address:port"
-   * @param {boolean=} creds Credentials to use for SSL
-   * @return {SurfaceServer} this
-   */
-  SurfaceServer.prototype.bind = function(port, creds) {
-    return this.inner_server.bind(port, creds);
-  };
-
-  /**
-   * Starts the server listening on any bound ports
-   * @return {SurfaceServer} this
-   */
-  SurfaceServer.prototype.listen = function() {
-    this.inner_server.listen();
-    return this;
-  };
-
-  /**
-   * Shuts the server down; tells it to stop listening for new requests and to
-   * kill old requests.
-   */
-  SurfaceServer.prototype.shutdown = function() {
-    this.inner_server.shutdown();
-  };
-
-  return SurfaceServer;
-}
-
-/**
- * Create a constructor for servers that serve the given services.
- * @param {Array<ProtoBuf.Reflect.Service>} services The services that the
- *     servers will serve
- * @return {function(Object, function, Object=)} New server constructor
- */
-function makeProtobufServerConstructor(services) {
-  var qual_names = [];
-  var service_attr_map = {};
-  _.each(services, function(service) {
-    var service_name = common.fullyQualifiedName(service);
-    _.each(service.children, function(method) {
-      var name = common.fullyQualifiedName(method);
-      if (_.indexOf(qual_names, name) !== -1) {
-        throw new Error('Method ' + name + ' exposed by more than one service');
-      }
-      qual_names.push(name);
-    });
-    var method_attrs = common.getProtobufServiceAttrs(service);
-    if (!service_attr_map.hasOwnProperty(service_name)) {
-      service_attr_map[service_name] = {};
-    }
-    service_attr_map[service_name] = _.extend(service_attr_map[service_name],
-                                              method_attrs);
-  });
-  return makeServerConstructor(service_attr_map);
-}
-
-/**
- * See documentation for makeServerConstructor
- */
-exports.makeServerConstructor = makeServerConstructor;
-
-/**
- * See documentation for makeProtobufServerConstructor
- */
-exports.makeProtobufServerConstructor = makeProtobufServerConstructor;
+exports.Server = Server;
diff --git a/src/node/test/health_test.js b/src/node/test/health_test.js
index 4d1a508..bb700cc 100644
--- a/src/node/test/health_test.js
+++ b/src/node/test/health_test.js
@@ -49,14 +49,13 @@
       'grpc.test.TestService': 'SERVING'
     }
   };
-  var HealthServer = grpc.buildServer([health.service]);
-  var healthServer = new HealthServer({
-    'grpc.health.v1alpha.Health': new health.Implementation(statusMap)
-  });
+  var healthServer = new grpc.Server();
+  healthServer.addProtoService(health.service,
+                               new health.Implementation(statusMap));
   var healthClient;
   before(function() {
     var port_num = healthServer.bind('0.0.0.0:0');
-    healthServer.listen();
+    healthServer.start();
     healthClient = new health.Client('localhost:' + port_num);
   });
   after(function() {
diff --git a/src/node/test/interop_sanity_test.js b/src/node/test/interop_sanity_test.js
index fcd8eb6..0a5eb29 100644
--- a/src/node/test/interop_sanity_test.js
+++ b/src/node/test/interop_sanity_test.js
@@ -46,7 +46,7 @@
   before(function(done) {
     var server_obj = interop_server.getServer(0, true);
     server = server_obj.server;
-    server.listen();
+    server.start();
     port = 'localhost:' + server_obj.port;
     done();
   });
diff --git a/src/node/test/math_client_test.js b/src/node/test/math_client_test.js
index 3461922..f275185 100644
--- a/src/node/test/math_client_test.js
+++ b/src/node/test/math_client_test.js
@@ -52,7 +52,7 @@
 describe('Math client', function() {
   before(function(done) {
     var port_num = server.bind('0.0.0.0:0');
-    server.listen();
+    server.start();
     math_client = new math.Math('localhost:' + port_num);
     done();
   });
diff --git a/src/node/test/surface_test.js b/src/node/test/surface_test.js
index 1259572..18178e4 100644
--- a/src/node/test/surface_test.js
+++ b/src/node/test/surface_test.js
@@ -69,34 +69,45 @@
     });
   });
 });
-describe('Surface server constructor', function() {
-  it('Should fail with conflicting method names', function() {
-    assert.throws(function() {
-      grpc.buildServer([mathService, mathService]);
-    });
+describe('Server.prototype.addProtoService', function() {
+  var server;
+  var dummyImpls = {
+    'div': function() {},
+    'divMany': function() {},
+    'fib': function() {},
+    'sum': function() {}
+  };
+  beforeEach(function() {
+    server = new grpc.Server();
+  });
+  afterEach(function() {
+    server.shutdown();
   });
   it('Should succeed with a single service', function() {
     assert.doesNotThrow(function() {
-      grpc.buildServer([mathService]);
+      server.addProtoService(mathService, dummyImpls);
+    });
+  });
+  it('Should fail with conflicting method names', function() {
+    server.addProtoService(mathService, dummyImpls);
+    assert.throws(function() {
+      server.addProtoService(mathService, dummyImpls);
     });
   });
   it('Should fail with missing handlers', function() {
-    var Server = grpc.buildServer([mathService]);
     assert.throws(function() {
-      new Server({
-        'math.Math': {
-          'div': function() {},
-          'divMany': function() {},
-          'fib': function() {}
-        }
+      server.addProtoService(mathService, {
+        'div': function() {},
+        'divMany': function() {},
+        'fib': function() {}
       });
     }, /math.Math.Sum/);
   });
-  it('Should fail with no handlers for the service', function() {
-    var Server = grpc.buildServer([mathService]);
+  it('Should fail if the server has been started', function() {
+    server.start();
     assert.throws(function() {
-      new Server({});
-    }, /math.Math/);
+      server.addProtoService(mathService, dummyImpls);
+    });
   });
 });
 describe('Echo service', function() {
@@ -105,18 +116,16 @@
   before(function() {
     var test_proto = ProtoBuf.loadProtoFile(__dirname + '/echo_service.proto');
     var echo_service = test_proto.lookup('EchoService');
-    var Server = grpc.buildServer([echo_service]);
-    server = new Server({
-      'EchoService': {
-        echo: function(call, callback) {
-          callback(null, call.request);
-        }
+    server = new grpc.Server();
+    server.addProtoService(echo_service, {
+      echo: function(call, callback) {
+        callback(null, call.request);
       }
     });
     var port = server.bind('localhost:0');
     var Client = surface_client.makeProtobufClientConstructor(echo_service);
     client = new Client('localhost:' + port);
-    server.listen();
+    server.start();
   });
   after(function() {
     server.shutdown();
@@ -151,18 +160,14 @@
     var client;
     var server;
     before(function() {
-      var Server = grpc.makeGenericServerConstructor({
-        string: string_service_attrs
-      });
-      server = new Server({
-        string: {
-          capitalize: function(call, callback) {
-            callback(null, _.capitalize(call.request));
-          }
+      server = new grpc.Server();
+      server.addService(string_service_attrs, {
+        capitalize: function(call, callback) {
+          callback(null, _.capitalize(call.request));
         }
       });
       var port = server.bind('localhost:0');
-      server.listen();
+      server.start();
       var Client = grpc.makeGenericClientConstructor(string_service_attrs);
       client = new Client('localhost:' + port);
     });
@@ -178,6 +183,82 @@
     });
   });
 });
+describe('Echo metadata', function() {
+  var client;
+  var server;
+  before(function() {
+    var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto');
+    var test_service = test_proto.lookup('TestService');
+    server = new grpc.Server();
+    server.addProtoService(test_service, {
+      unary: function(call, cb) {
+        call.sendMetadata(call.metadata);
+        cb(null, {});
+      },
+      clientStream: function(stream, cb){
+        stream.on('data', function(data) {});
+        stream.on('end', function() {
+          stream.sendMetadata(stream.metadata);
+          cb(null, {});
+        });
+      },
+      serverStream: function(stream) {
+        stream.sendMetadata(stream.metadata);
+        stream.end();
+      },
+      bidiStream: function(stream) {
+        stream.on('data', function(data) {});
+        stream.on('end', function() {
+          stream.sendMetadata(stream.metadata);
+          stream.end();
+        });
+      }
+    });
+    var port = server.bind('localhost:0');
+    var Client = surface_client.makeProtobufClientConstructor(test_service);
+    client = new Client('localhost:' + port);
+    server.start();
+  });
+  after(function() {
+    server.shutdown();
+  });
+  it('with unary call', function(done) {
+    var call = client.unary({}, function(err, data) {
+      assert.ifError(err);
+    }, {key: ['value']});
+    call.on('metadata', function(metadata) {
+      assert.deepEqual(metadata.key, ['value']);
+      done();
+    });
+  });
+  it('with client stream call', function(done) {
+    var call = client.clientStream(function(err, data) {
+      assert.ifError(err);
+    }, {key: ['value']});
+    call.on('metadata', function(metadata) {
+      assert.deepEqual(metadata.key, ['value']);
+      done();
+    });
+    call.end();
+  });
+  it('with server stream call', function(done) {
+    var call = client.serverStream({}, {key: ['value']});
+    call.on('data', function() {});
+    call.on('metadata', function(metadata) {
+      assert.deepEqual(metadata.key, ['value']);
+      done();
+    });
+  });
+  it('with bidi stream call', function(done) {
+    var call = client.bidiStream({key: ['value']});
+    call.on('data', function() {});
+    call.on('metadata', function(metadata) {
+      assert.deepEqual(metadata.key, ['value']);
+      done();
+    });
+    call.end();
+  });
+});
 describe('Other conditions', function() {
   var client;
   var server;
@@ -185,72 +266,70 @@
   before(function() {
     var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto');
     var test_service = test_proto.lookup('TestService');
-    var Server = grpc.buildServer([test_service]);
-    server = new Server({
-      TestService: {
-        unary: function(call, cb) {
-          var req = call.request;
-          if (req.error) {
-            cb(new Error('Requested error'), null, {metadata: ['yes']});
+    server = new grpc.Server();
+    server.addProtoService(test_service, {
+      unary: function(call, cb) {
+        var req = call.request;
+        if (req.error) {
+          cb(new Error('Requested error'), null, {trailer_present: ['yes']});
+        } else {
+          cb(null, {count: 1}, {trailer_present: ['yes']});
+        }
+      },
+      clientStream: function(stream, cb){
+        var count = 0;
+        var errored;
+        stream.on('data', function(data) {
+          if (data.error) {
+            errored = true;
+            cb(new Error('Requested error'), null, {trailer_present: ['yes']});
           } else {
-            cb(null, {count: 1}, {metadata: ['yes']});
+            count += 1;
           }
-        },
-        clientStream: function(stream, cb){
-          var count = 0;
-          var errored;
-          stream.on('data', function(data) {
-            if (data.error) {
-              errored = true;
-              cb(new Error('Requested error'), null, {metadata: ['yes']});
-            } else {
-              count += 1;
-            }
-          });
-          stream.on('end', function() {
-            if (!errored) {
-              cb(null, {count: count}, {metadata: ['yes']});
-            }
-          });
-        },
-        serverStream: function(stream) {
-          var req = stream.request;
-          if (req.error) {
+        });
+        stream.on('end', function() {
+          if (!errored) {
+            cb(null, {count: count}, {trailer_present: ['yes']});
+          }
+        });
+      },
+      serverStream: function(stream) {
+        var req = stream.request;
+        if (req.error) {
+          var err = new Error('Requested error');
+          err.metadata = {trailer_present: ['yes']};
+          stream.emit('error', err);
+        } else {
+          for (var i = 0; i < 5; i++) {
+            stream.write({count: i});
+          }
+          stream.end({trailer_present: ['yes']});
+        }
+      },
+      bidiStream: function(stream) {
+        var count = 0;
+        stream.on('data', function(data) {
+          if (data.error) {
             var err = new Error('Requested error');
-            err.metadata = {metadata: ['yes']};
+            err.metadata = {
+              trailer_present: ['yes'],
+              count: ['' + count]
+            };
             stream.emit('error', err);
           } else {
-            for (var i = 0; i < 5; i++) {
-              stream.write({count: i});
-            }
-            stream.end({metadata: ['yes']});
+            stream.write({count: count});
+            count += 1;
           }
-        },
-        bidiStream: function(stream) {
-          var count = 0;
-          stream.on('data', function(data) {
-            if (data.error) {
-              var err = new Error('Requested error');
-              err.metadata = {
-                metadata: ['yes'],
-                count: ['' + count]
-              };
-              stream.emit('error', err);
-            } else {
-              stream.write({count: count});
-              count += 1;
-            }
-          });
-          stream.on('end', function() {
-            stream.end({metadata: ['yes']});
-          });
-        }
+        });
+        stream.on('end', function() {
+          stream.end({trailer_present: ['yes']});
+        });
       }
     });
     port = server.bind('localhost:0');
     var Client = surface_client.makeProtobufClientConstructor(test_service);
     client = new Client('localhost:' + port);
-    server.listen();
+    server.start();
   });
   after(function() {
     server.shutdown();
@@ -340,7 +419,7 @@
         assert.ifError(err);
       });
       call.on('status', function(status) {
-        assert.deepEqual(status.metadata.metadata, ['yes']);
+        assert.deepEqual(status.metadata.trailer_present, ['yes']);
         done();
       });
     });
@@ -349,7 +428,7 @@
         assert(err);
       });
       call.on('status', function(status) {
-        assert.deepEqual(status.metadata.metadata, ['yes']);
+        assert.deepEqual(status.metadata.trailer_present, ['yes']);
         done();
       });
     });
@@ -361,7 +440,7 @@
       call.write({error: false});
       call.end();
       call.on('status', function(status) {
-        assert.deepEqual(status.metadata.metadata, ['yes']);
+        assert.deepEqual(status.metadata.trailer_present, ['yes']);
         done();
       });
     });
@@ -373,7 +452,7 @@
       call.write({error: true});
       call.end();
       call.on('status', function(status) {
-        assert.deepEqual(status.metadata.metadata, ['yes']);
+        assert.deepEqual(status.metadata.trailer_present, ['yes']);
         done();
       });
     });
@@ -382,7 +461,7 @@
       call.on('data', function(){});
       call.on('status', function(status) {
         assert.strictEqual(status.code, grpc.status.OK);
-        assert.deepEqual(status.metadata.metadata, ['yes']);
+        assert.deepEqual(status.metadata.trailer_present, ['yes']);
         done();
       });
     });
@@ -390,7 +469,7 @@
       var call = client.serverStream({error: true});
       call.on('data', function(){});
       call.on('error', function(error) {
-        assert.deepEqual(error.metadata.metadata, ['yes']);
+        assert.deepEqual(error.metadata.trailer_present, ['yes']);
         done();
       });
     });
@@ -402,7 +481,7 @@
       call.on('data', function(){});
       call.on('status', function(status) {
         assert.strictEqual(status.code, grpc.status.OK);
-        assert.deepEqual(status.metadata.metadata, ['yes']);
+        assert.deepEqual(status.metadata.trailer_present, ['yes']);
         done();
       });
     });
@@ -413,7 +492,7 @@
       call.end();
       call.on('data', function(){});
       call.on('error', function(error) {
-        assert.deepEqual(error.metadata.metadata, ['yes']);
+        assert.deepEqual(error.metadata.trailer_present, ['yes']);
         done();
       });
     });
@@ -465,18 +544,17 @@
   var client;
   var server;
   before(function() {
-    var Server = grpc.buildServer([mathService]);
-    server = new Server({
-      'math.Math': {
-        'div': function(stream) {},
-        'divMany': function(stream) {},
-        'fib': function(stream) {},
-        'sum': function(stream) {}
-      }
+    server = new grpc.Server();
+    server.addProtoService(mathService, {
+      'div': function(stream) {},
+      'divMany': function(stream) {},
+      'fib': function(stream) {},
+      'sum': function(stream) {}
     });
     var port = server.bind('localhost:0');
     var Client = surface_client.makeProtobufClientConstructor(mathService);
     client = new Client('localhost:' + port);
+    server.start();
   });
   after(function() {
     server.shutdown();
diff --git a/src/objective-c/GRPCClient/private/GRPCCompletionQueue.m b/src/objective-c/GRPCClient/private/GRPCCompletionQueue.m
index 40aade4..12535c9 100644
--- a/src/objective-c/GRPCClient/private/GRPCCompletionQueue.m
+++ b/src/objective-c/GRPCClient/private/GRPCCompletionQueue.m
@@ -65,7 +65,8 @@
     dispatch_async(gDefaultConcurrentQueue, ^{
       while (YES) {
         // The following call blocks until an event is available.
-        grpc_event event = grpc_completion_queue_next(unmanagedQueue, gpr_inf_future);
+        grpc_event event = grpc_completion_queue_next(unmanagedQueue,
+                                                      gpr_inf_future(GPR_CLOCK_REALTIME));
         GRPCQueueCompletionHandler handler;
         switch (event.type) {
           case GRPC_OP_COMPLETE:
diff --git a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m
index 45f10f5..1db63df 100644
--- a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m
+++ b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m
@@ -246,8 +246,11 @@
     if (!_queue) {
       return nil;
     }
-    _call = grpc_channel_create_call(channel.unmanagedChannel, _queue.unmanagedQueue,
-                                     path.UTF8String, host.UTF8String, gpr_inf_future);
+    _call = grpc_channel_create_call(channel.unmanagedChannel,
+                                     _queue.unmanagedQueue,
+                                     path.UTF8String,
+                                     host.UTF8String,
+                                     gpr_inf_future(GPR_CLOCK_REALTIME));
     if (_call == NULL) {
       return nil;
     }
diff --git a/src/objective-c/RxLibrary/GRXImmediateWriter.m b/src/objective-c/RxLibrary/GRXImmediateWriter.m
index b6d2b2c..3edae78 100644
--- a/src/objective-c/RxLibrary/GRXImmediateWriter.m
+++ b/src/objective-c/RxLibrary/GRXImmediateWriter.m
@@ -76,28 +76,15 @@
 }
 
 + (GRXWriter *)writerWithValue:(id)value {
-  if (value) {
-    return [self writerWithEnumerator:[NSEnumerator grx_enumeratorWithSingleValue:value]];
-  } else {
-    return [self emptyWriter];
-  }
+  return [self writerWithEnumerator:[NSEnumerator grx_enumeratorWithSingleValue:value]];
 }
 
 + (GRXWriter *)writerWithError:(NSError *)error {
-  if (error) {
-    return [self writerWithEnumerator:nil error:error];
-  } else {
-    return [self emptyWriter];
-  }
+  return [self writerWithEnumerator:nil error:error];
 }
 
 + (GRXWriter *)emptyWriter {
-  static GRXImmediateWriter *emptyWriter;
-  static dispatch_once_t onceToken;
-  dispatch_once(&onceToken, ^{
-    emptyWriter = [self writerWithEnumerator:nil error:nil];
-  });
-  return emptyWriter;
+  return [self writerWithEnumerator:nil error:nil];
 }
 
 #pragma mark Conformance with GRXWriter
diff --git a/src/objective-c/RxLibrary/private/GRXNSFastEnumerator.m b/src/objective-c/RxLibrary/private/GRXNSFastEnumerator.m
index 2050fa9..0387c99 100644
--- a/src/objective-c/RxLibrary/private/GRXNSFastEnumerator.m
+++ b/src/objective-c/RxLibrary/private/GRXNSFastEnumerator.m
@@ -59,7 +59,6 @@
 
 // Designated initializer.
 - (instancetype)initWithContainer:(id<NSFastEnumeration>)container {
-  NSAssert(container, @"container can't be nil");
   if ((self = [super init])) {
     _container = container;
   }
diff --git a/src/objective-c/generated_libraries/RemoteTestClient/RemoteTest.podspec b/src/objective-c/generated_libraries/RemoteTestClient/RemoteTest.podspec
index dd0dab3..7cc9a04 100644
--- a/src/objective-c/generated_libraries/RemoteTestClient/RemoteTest.podspec
+++ b/src/objective-c/generated_libraries/RemoteTestClient/RemoteTest.podspec
@@ -7,7 +7,13 @@
   s.osx.deployment_target = "10.8"
 
   # Run protoc with the Objective-C and gRPC plugins to generate protocol messages and gRPC clients.
-  s.prepare_command = "protoc --objc_out=. --objcgrpc_out=. *.proto"
+  s.prepare_command = <<-CMD
+    cd ../../../..
+    # TODO(jcanizales): Make only Objective-C plugin.
+    make plugins
+    cd -
+    protoc --plugin=protoc-gen-grpc=../../../../bins/opt/grpc_objective_c_plugin --objc_out=. --grpc_out=. *.proto
+  CMD
 
   s.subspec "Messages" do |ms|
     ms.source_files = "*.pbobjc.{h,m}"
diff --git a/src/objective-c/generated_libraries/RouteGuideClient/RouteGuide.podspec b/src/objective-c/generated_libraries/RouteGuideClient/RouteGuide.podspec
index e26e62f..0e8dacd 100644
--- a/src/objective-c/generated_libraries/RouteGuideClient/RouteGuide.podspec
+++ b/src/objective-c/generated_libraries/RouteGuideClient/RouteGuide.podspec
@@ -7,7 +7,13 @@
   s.osx.deployment_target = "10.8"
 
   # Run protoc with the Objective-C and gRPC plugins to generate protocol messages and gRPC clients.
-  s.prepare_command = "protoc --objc_out=. --objcgrpc_out=. *.proto"
+  s.prepare_command = <<-CMD
+    cd ../../../..
+    # TODO(jcanizales): Make only Objective-C plugin.
+    make plugins
+    cd -
+    protoc --plugin=protoc-gen-grpc=../../../../bins/opt/grpc_objective_c_plugin --objc_out=. --grpc_out=. *.proto
+  CMD
 
   s.subspec "Messages" do |ms|
     ms.source_files = "*.pbobjc.{h,m}"
diff --git a/src/objective-c/tests/Tests.xcodeproj/xcshareddata/xcschemes/AllTests.xcscheme b/src/objective-c/tests/Tests.xcodeproj/xcshareddata/xcschemes/AllTests.xcscheme
new file mode 100644
index 0000000..3a6e2c3
--- /dev/null
+++ b/src/objective-c/tests/Tests.xcodeproj/xcshareddata/xcschemes/AllTests.xcscheme
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+   LastUpgradeVersion = "0630"
+   version = "1.3">
+   <BuildAction
+      parallelizeBuildables = "YES"
+      buildImplicitDependencies = "YES">
+      <BuildActionEntries>
+         <BuildActionEntry
+            buildForTesting = "YES"
+            buildForRunning = "YES"
+            buildForProfiling = "NO"
+            buildForArchiving = "NO"
+            buildForAnalyzing = "YES">
+            <BuildableReference
+               BuildableIdentifier = "primary"
+               BlueprintIdentifier = "63423F431B150A5F006CF63C"
+               BuildableName = "AllTests.xctest"
+               BlueprintName = "AllTests"
+               ReferencedContainer = "container:Tests.xcodeproj">
+            </BuildableReference>
+         </BuildActionEntry>
+      </BuildActionEntries>
+   </BuildAction>
+   <TestAction
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      shouldUseLaunchSchemeArgsEnv = "YES"
+      buildConfiguration = "Debug">
+      <Testables>
+         <TestableReference
+            skipped = "NO">
+            <BuildableReference
+               BuildableIdentifier = "primary"
+               BlueprintIdentifier = "63423F431B150A5F006CF63C"
+               BuildableName = "AllTests.xctest"
+               BlueprintName = "AllTests"
+               ReferencedContainer = "container:Tests.xcodeproj">
+            </BuildableReference>
+            <SkippedTests>
+               <Test
+                  Identifier = "LocalClearTextTests">
+               </Test>
+               <Test
+                  Identifier = "LocalClearTextTests/testConnectionToLocalServer">
+               </Test>
+            </SkippedTests>
+         </TestableReference>
+      </Testables>
+      <MacroExpansion>
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "63423F431B150A5F006CF63C"
+            BuildableName = "AllTests.xctest"
+            BlueprintName = "AllTests"
+            ReferencedContainer = "container:Tests.xcodeproj">
+         </BuildableReference>
+      </MacroExpansion>
+   </TestAction>
+   <LaunchAction
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      launchStyle = "0"
+      useCustomWorkingDirectory = "NO"
+      buildConfiguration = "Debug"
+      ignoresPersistentStateOnLaunch = "NO"
+      debugDocumentVersioning = "YES"
+      allowLocationSimulation = "YES">
+      <MacroExpansion>
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "63423F431B150A5F006CF63C"
+            BuildableName = "AllTests.xctest"
+            BlueprintName = "AllTests"
+            ReferencedContainer = "container:Tests.xcodeproj">
+         </BuildableReference>
+      </MacroExpansion>
+      <AdditionalOptions>
+      </AdditionalOptions>
+   </LaunchAction>
+   <ProfileAction
+      shouldUseLaunchSchemeArgsEnv = "YES"
+      savedToolIdentifier = ""
+      useCustomWorkingDirectory = "NO"
+      buildConfiguration = "Release"
+      debugDocumentVersioning = "YES">
+      <MacroExpansion>
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "63423F431B150A5F006CF63C"
+            BuildableName = "AllTests.xctest"
+            BlueprintName = "AllTests"
+            ReferencedContainer = "container:Tests.xcodeproj">
+         </BuildableReference>
+      </MacroExpansion>
+   </ProfileAction>
+   <AnalyzeAction
+      buildConfiguration = "Debug">
+   </AnalyzeAction>
+   <ArchiveAction
+      buildConfiguration = "Release"
+      revealArchiveInOrganizer = "YES">
+   </ArchiveAction>
+</Scheme>
diff --git a/src/objective-c/tests/run_tests.sh b/src/objective-c/tests/run_tests.sh
new file mode 100755
index 0000000..37fced3
--- /dev/null
+++ b/src/objective-c/tests/run_tests.sh
@@ -0,0 +1,49 @@
+#!/bin/bash
+# Copyright 2015, Google Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+#     * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+set -e
+
+cd $(dirname $0)
+
+# TODO(jcanizales): Remove when Cocoapods issue #3823 is resolved.
+export COCOAPODS_DISABLE_DETERMINISTIC_UUIDS=YES
+pod install
+
+# xcodebuild is very verbose. We filter its output and tell Bash to fail if any
+# element of the pipe fails.
+# TODO(jcanizales): Use xctool instead? Issue #2540.
+set -o pipefail
+XCODEBUILD_FILTER='(^===|^\*\*|\bfatal\b|\berror\b|\bwarning\b|\bfail)'
+xcodebuild \
+    -workspace Tests.xcworkspace \
+    -scheme AllTests \
+    -destination name="iPhone 6" \
+    test \
+    | egrep "$XCODEBUILD_FILTER" -
diff --git a/src/php/ext/grpc/server.c b/src/php/ext/grpc/server.c
index c319526..8b8d5b2 100644
--- a/src/php/ext/grpc/server.c
+++ b/src/php/ext/grpc/server.c
@@ -64,6 +64,7 @@
   wrapped_grpc_server *server = (wrapped_grpc_server *)object;
   if (server->wrapped != NULL) {
     grpc_server_shutdown_and_notify(server->wrapped, completion_queue, NULL);
+    grpc_server_cancel_all_calls(server->wrapped);
     grpc_completion_queue_pluck(completion_queue, NULL,
                                 gpr_inf_future(GPR_CLOCK_REALTIME));
     grpc_server_destroy(server->wrapped);
diff --git a/src/php/tests/unit_tests/EndToEndTest.php b/src/php/tests/unit_tests/EndToEndTest.php
index 296873f..2980dca 100755
--- a/src/php/tests/unit_tests/EndToEndTest.php
+++ b/src/php/tests/unit_tests/EndToEndTest.php
@@ -61,7 +61,6 @@
 
     $event = $this->server->requestCall();
     $this->assertSame('dummy_method', $event->method);
-    $this->assertSame([], $event->metadata);
     $server_call = $event->call;
 
     $event = $server_call->startBatch([
@@ -83,7 +82,6 @@
         Grpc\OP_RECV_STATUS_ON_CLIENT => true
                                  ]);
 
-    $this->assertSame([], $event->metadata);
     $status = $event->status;
     $this->assertSame([], $status->metadata);
     $this->assertSame(Grpc\STATUS_OK, $status->code);
diff --git a/src/php/tests/unit_tests/SecureEndToEndTest.php b/src/php/tests/unit_tests/SecureEndToEndTest.php
index 0c18cd3..f91c006 100755
--- a/src/php/tests/unit_tests/SecureEndToEndTest.php
+++ b/src/php/tests/unit_tests/SecureEndToEndTest.php
@@ -73,7 +73,6 @@
 
     $event = $this->server->requestCall();
     $this->assertSame('dummy_method', $event->method);
-    $this->assertSame([], $event->metadata);
     $server_call = $event->call;
 
     $event = $server_call->startBatch([
diff --git a/src/python/src/grpc/_adapter/_low_test.py b/src/python/src/grpc/_adapter/_low_test.py
index 268e5fe..a49cd00 100644
--- a/src/python/src/grpc/_adapter/_low_test.py
+++ b/src/python/src/grpc/_adapter/_low_test.py
@@ -129,7 +129,10 @@
     self.assertIsInstance(request_event.call, _low.Call)
     self.assertIs(server_request_tag, request_event.tag)
     self.assertEquals(1, len(request_event.results))
-    self.assertEquals(dict(client_initial_metadata), dict(request_event.results[0].initial_metadata))
+    got_initial_metadata = dict(request_event.results[0].initial_metadata)
+    self.assertEquals(
+        dict(client_initial_metadata),
+        dict((x, got_initial_metadata[x]) for x in zip(*client_initial_metadata)[0]))
     self.assertEquals(METHOD, request_event.call_details.method)
     self.assertEquals(HOST, request_event.call_details.host)
     self.assertLess(abs(DEADLINE - request_event.call_details.deadline), DEADLINE_TOLERANCE)
diff --git a/src/python/src/grpc/_links/_transmission_test.py b/src/python/src/grpc/_links/_transmission_test.py
index c5ef1ed..3eeec03 100644
--- a/src/python/src/grpc/_links/_transmission_test.py
+++ b/src/python/src/grpc/_links/_transmission_test.py
@@ -93,8 +93,13 @@
   def create_service_completion(self):
     return _intermediary_low.Code.OK, 'An exuberant test "details" message!'
 
-  def assertMetadataEqual(self, original_metadata, transmitted_metadata):
-    self.assertSequenceEqual(original_metadata, transmitted_metadata)
+  def assertMetadataTransmitted(self, original_metadata, transmitted_metadata):
+    # we need to filter out any additional metadata added in transmitted_metadata
+    # since implementations are allowed to add to what is sent (in any position)
+    keys, _ = zip(*original_metadata)
+    self.assertSequenceEqual(
+        original_metadata,
+        [x for x in transmitted_metadata if x[0] in keys])
 
 
 class RoundTripTest(unittest.TestCase):
diff --git a/src/python/src/grpc/framework/interfaces/links/test_cases.py b/src/python/src/grpc/framework/interfaces/links/test_cases.py
index 3ac212e..bf1f09d 100644
--- a/src/python/src/grpc/framework/interfaces/links/test_cases.py
+++ b/src/python/src/grpc/framework/interfaces/links/test_cases.py
@@ -161,8 +161,8 @@
     raise NotImplementedError()
 
   @abc.abstractmethod
-  def assertMetadataEqual(self, original_metadata, transmitted_metadata):
-    """Asserts that two metadata objects are equal.
+  def assertMetadataTransmitted(self, original_metadata, transmitted_metadata):
+    """Asserts that transmitted_metadata contains original_metadata.
 
     Args:
       original_metadata: A metadata object used in this test.
@@ -170,7 +170,8 @@
         through the system under test.
 
     Raises:
-      AssertionError: if the two metadata objects are not equal.
+      AssertionError: if the transmitted_metadata object does not contain
+        original_metadata.
     """
     raise NotImplementedError()
 
@@ -239,7 +240,7 @@
         self.assertFalse(initial_metadata_seen)
         self.assertFalse(seen_payloads)
         self.assertFalse(terminal_metadata_seen)
-        self.assertMetadataEqual(initial_metadata, ticket.initial_metadata)
+        self.assertMetadataTransmitted(initial_metadata, ticket.initial_metadata)
         initial_metadata_seen = True
 
       if ticket.payload is not None:
@@ -248,7 +249,7 @@
 
       if ticket.terminal_metadata is not None:
         self.assertFalse(terminal_metadata_seen)
-        self.assertMetadataEqual(terminal_metadata, ticket.terminal_metadata)
+        self.assertMetadataTransmitted(terminal_metadata, ticket.terminal_metadata)
         terminal_metadata_seen = True
     self.assertSequenceEqual(payloads, seen_payloads)
 
diff --git a/src/ruby/spec/generic/rpc_server_spec.rb b/src/ruby/spec/generic/rpc_server_spec.rb
index f2403de..0326f6e 100644
--- a/src/ruby/spec/generic/rpc_server_spec.rb
+++ b/src/ruby/spec/generic/rpc_server_spec.rb
@@ -35,6 +35,14 @@
   files.map { |f| File.open(File.join(test_root, f)).read }
 end
 
+def check_md(wanted_md, received_md)
+  wanted_md.zip(received_md).each do |w, r|
+    w.each do |key, value|
+      expect(r[key]).to eq(value)
+    end
+  end
+end
+
 # A test message
 class EchoMsg
   def self.marshal(_o)
@@ -376,7 +384,7 @@
         stub = EchoStub.new(@host, **client_opts)
         expect(stub.an_rpc(req, k1: 'v1', k2: 'v2')).to be_a(EchoMsg)
         wanted_md = [{ 'k1' => 'v1', 'k2' => 'v2' }]
-        expect(service.received_md).to eq(wanted_md)
+        check_md(wanted_md, service.received_md)
         @srv.stop
         t.join
       end
@@ -391,7 +399,7 @@
         deadline = service.delay + 1.0 # wait for long enough
         expect(stub.an_rpc(req, deadline, k1: 'v1', k2: 'v2')).to be_a(EchoMsg)
         wanted_md = [{ 'k1' => 'v1', 'k2' => 'v2' }]
-        expect(service.received_md).to eq(wanted_md)
+        check_md(wanted_md, service.received_md)
         @srv.stop
         t.join
       end
@@ -443,7 +451,7 @@
         expect(stub.an_rpc(req, k1: 'v1', k2: 'v2')).to be_a(EchoMsg)
         wanted_md = [{ 'k1' => 'updated-v1', 'k2' => 'v2',
                        'jwt_aud_uri' => "https://#{@host}/EchoService" }]
-        expect(service.received_md).to eq(wanted_md)
+        check_md(wanted_md, service.received_md)
         @srv.stop
         t.join
       end
@@ -535,7 +543,9 @@
           'method' => '/EchoService/an_rpc',
           'connect_k1' => 'connect_v1'
         }
-        expect(op.metadata).to eq(wanted_md)
+        wanted_md.each do |key, value|
+          expect(op.metadata[key]).to eq(value)
+        end
         @srv.stop
         t.join
       end
diff --git a/templates/Makefile.template b/templates/Makefile.template
index 044db4d..1e46db1 100644
--- a/templates/Makefile.template
+++ b/templates/Makefile.template
@@ -159,7 +159,7 @@
 CXX_tsan = clang++
 LD_tsan = clang
 LDXX_tsan = clang++
-CPPFLAGS_tsan = -O0 -fsanitize=thread -fno-omit-frame-pointer
+CPPFLAGS_tsan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-error=unused-command-line-argument
 LDFLAGS_tsan = -fsanitize=thread
 DEFINES_tsan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=10
 
@@ -169,7 +169,7 @@
 CXX_asan = clang++
 LD_asan = clang
 LDXX_asan = clang++
-CPPFLAGS_asan = -O0 -fsanitize=address -fno-omit-frame-pointer
+CPPFLAGS_asan = -O0 -fsanitize=address -fno-omit-frame-pointer -Wno-error=unused-command-line-argument
 LDFLAGS_asan = -fsanitize=address
 DEFINES_asan = GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3
 
@@ -179,7 +179,7 @@
 CXX_msan = clang++-libc++
 LD_msan = clang
 LDXX_msan = clang++-libc++
-CPPFLAGS_msan = -O0 -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1
+CPPFLAGS_msan = -O0 -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 -Wno-error=unused-command-line-argument
 OPENSSL_CFLAGS_msan = -DPURIFY
 LDFLAGS_msan = -fsanitize=memory -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1
 DEFINES_msan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=4
@@ -190,7 +190,7 @@
 CXX_ubsan = clang++
 LD_ubsan = clang
 LDXX_ubsan = clang++
-CPPFLAGS_ubsan = -O1 -fsanitize=undefined -fno-omit-frame-pointer
+CPPFLAGS_ubsan = -O1 -fsanitize=undefined -fno-omit-frame-pointer -Wno-error=unused-command-line-argument
 OPENSSL_CFLAGS_ubsan = -DPURIFY
 LDFLAGS_ubsan = -fsanitize=undefined
 DEFINES_ubsan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3
@@ -255,10 +255,6 @@
 HOST_LD = $(LD)
 HOST_LDXX = $(LDXX)
 
-CPPFLAGS += $(CPPFLAGS_$(CONFIG))
-DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\"
-LDFLAGS += $(LDFLAGS_$(CONFIG))
-
 ifdef EXTRA_DEFINES
 DEFINES += $(EXTRA_DEFINES)
 endif
@@ -272,6 +268,10 @@
 CPPFLAGS += -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter
 LDFLAGS += -g
 
+CPPFLAGS += $(CPPFLAGS_$(CONFIG))
+DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\"
+LDFLAGS += $(LDFLAGS_$(CONFIG))
+
 ifneq ($(SYSTEM),MINGW32)
 PIC_CPPFLAGS = -fPIC
 CPPFLAGS += -fPIC
@@ -816,7 +816,7 @@
 
 $(LIBDIR)/$(CONFIG)/zlib/libz.a:
 	$(E) "[MAKE]    Building zlib"
-	$(Q)(cd third_party/zlib ; CC="$(CC)" CFLAGS="$(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG))" ./configure --static)
+	$(Q)(cd third_party/zlib ; CC="$(CC)" CFLAGS="$(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(ZLIB_CFLAGS_EXTRA)" ./configure --static)
 	$(Q)$(MAKE) -C third_party/zlib clean
 	$(Q)$(MAKE) -C third_party/zlib
 	$(Q)mkdir -p $(LIBDIR)/$(CONFIG)/zlib
@@ -825,7 +825,7 @@
 $(LIBDIR)/$(CONFIG)/openssl/libssl.a:
 	$(E) "[MAKE]    Building openssl for $(SYSTEM)"
 ifeq ($(SYSTEM),Darwin)
-	$(Q)(cd third_party/openssl ; CC="$(CC) $(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG))" ./Configure darwin64-x86_64-cc)
+	$(Q)(cd third_party/openssl ; CC="$(CC) $(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_EXTRA)" ./Configure darwin64-x86_64-cc)
 else
 ifeq ($(SYSTEM),MINGW32)
 	@echo "We currently don't have a good way to compile OpenSSL in-place under msys."
@@ -846,7 +846,7 @@
 	@echo "  CPPFLAGS=-I/c/OpenSSL-Win64/include LDFLAGS=-L/c/OpenSSL-Win64 make"
 	@false
 else
-	$(Q)(cd third_party/openssl ; CC="$(CC) $(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG))" ./config no-asm $(OPENSSL_CONFIG_$(CONFIG)))
+	$(Q)(cd third_party/openssl ; CC="$(CC) $(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_EXTRA)" ./config no-asm $(OPENSSL_CONFIG_$(CONFIG)))
 endif
 endif
 	$(Q)$(MAKE) -C third_party/openssl clean
@@ -860,7 +860,7 @@
 
 $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure
 	$(E) "[MAKE]    Building protobuf"
-	$(Q)(cd third_party/protobuf ; CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS_$(CONFIG)) -g" CPPFLAGS="$(PIC_CPPFLAGS) $(CPPFLAGS_$(CONFIG)) -g" ./configure --disable-shared --enable-static)
+	$(Q)(cd third_party/protobuf ; CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS_$(CONFIG)) -g $(PROTOBUF_LDFLAGS_EXTRA)" CPPFLAGS="$(PIC_CPPFLAGS) $(CPPFLAGS_$(CONFIG)) -g $(PROTOBUF_CPPFLAGS_EXTRA)" ./configure --disable-shared --enable-static)
 	$(Q)$(MAKE) -C third_party/protobuf clean
 	$(Q)$(MAKE) -C third_party/protobuf
 	$(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf
diff --git a/test/core/end2end/dualstack_socket_test.c b/test/core/end2end/dualstack_socket_test.c
index 7d3568c..05ad42c 100644
--- a/test/core/end2end/dualstack_socket_test.c
+++ b/test/core/end2end/dualstack_socket_test.c
@@ -211,6 +211,10 @@
   drain_cq(cq);
   grpc_completion_queue_destroy(cq);
 
+  grpc_metadata_array_destroy(&initial_metadata_recv);
+  grpc_metadata_array_destroy(&trailing_metadata_recv);
+  grpc_metadata_array_destroy(&request_metadata_recv);
+
   grpc_call_details_destroy(&call_details);
   gpr_free(details);
 }
diff --git a/test/core/iomgr/alarm_test.c b/test/core/iomgr/alarm_test.c
index 362eb5f..55aa517 100644
--- a/test/core/iomgr/alarm_test.c
+++ b/test/core/iomgr/alarm_test.c
@@ -41,6 +41,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <grpc/grpc.h>
 #include <grpc/support/alloc.h>
 #include <grpc/support/log.h>
 #include <grpc/support/sync.h>
@@ -100,7 +101,7 @@
   alarm_arg arg2;
   void *fdone;
 
-  grpc_iomgr_init();
+  grpc_init();
 
   arg.counter = 0;
   arg.success = SUCCESS_NOT_SET;
@@ -113,7 +114,7 @@
   gpr_event_init(&arg.fcb_arg);
 
   grpc_alarm_init(&alarm, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(100), alarm_cb, &arg,
-                  gpr_now(GPR_CLOCK_REALTIME));
+                  gpr_now(GPR_CLOCK_MONOTONIC));
 
   alarm_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1);
   gpr_mu_lock(&arg.mu);
@@ -165,7 +166,7 @@
   gpr_event_init(&arg2.fcb_arg);
 
   grpc_alarm_init(&alarm_to_cancel, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(100),
-                  alarm_cb, &arg2, gpr_now(GPR_CLOCK_REALTIME));
+                  alarm_cb, &arg2, gpr_now(GPR_CLOCK_MONOTONIC));
   grpc_alarm_cancel(&alarm_to_cancel);
 
   alarm_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1);
@@ -214,7 +215,7 @@
   gpr_mu_destroy(&arg2.mu);
   gpr_free(arg2.followup_closure);
 
-  grpc_iomgr_shutdown();
+  grpc_shutdown();
 }
 
 int main(int argc, char **argv) {
diff --git a/test/core/iomgr/endpoint_tests.c b/test/core/iomgr/endpoint_tests.c
index 0cfba5f..cb6adc5 100644
--- a/test/core/iomgr/endpoint_tests.c
+++ b/test/core/iomgr/endpoint_tests.c
@@ -254,7 +254,7 @@
 
   gpr_mu_lock(GRPC_POLLSET_MU(g_pollset));
   while (!state.read_done || !state.write_done) {
-    GPR_ASSERT(gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0);
+    GPR_ASSERT(gpr_time_cmp(gpr_now(GPR_CLOCK_MONOTONIC), deadline) < 0);
     grpc_pollset_work(g_pollset, deadline);
   }
   gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset));
@@ -350,14 +350,14 @@
         deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10);
         gpr_mu_lock(GRPC_POLLSET_MU(g_pollset));
         while (!write_st.done) {
-          GPR_ASSERT(gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0);
+          GPR_ASSERT(gpr_time_cmp(gpr_now(deadline.clock_type), deadline) < 0);
           grpc_pollset_work(g_pollset, deadline);
         }
         gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset));
         grpc_endpoint_destroy(write_st.ep);
         gpr_mu_lock(GRPC_POLLSET_MU(g_pollset));
         while (!read_st.done) {
-          GPR_ASSERT(gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0);
+          GPR_ASSERT(gpr_time_cmp(gpr_now(deadline.clock_type), deadline) < 0);
           grpc_pollset_work(g_pollset, deadline);
         }
         gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset));
diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c
index cd26866..7d00c09 100644
--- a/test/core/iomgr/fd_posix_test.c
+++ b/test/core/iomgr/fd_posix_test.c
@@ -249,7 +249,7 @@
 static void server_wait_and_shutdown(server *sv) {
   gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
   while (!sv->done) {
-    grpc_pollset_work(&g_pollset, gpr_inf_future(GPR_CLOCK_REALTIME));
+    grpc_pollset_work(&g_pollset, gpr_inf_future(GPR_CLOCK_MONOTONIC));
   }
   gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
 }
@@ -356,7 +356,7 @@
 static void client_wait_and_shutdown(client *cl) {
   gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
   while (!cl->done) {
-    grpc_pollset_work(&g_pollset, gpr_inf_future(GPR_CLOCK_REALTIME));
+    grpc_pollset_work(&g_pollset, gpr_inf_future(GPR_CLOCK_MONOTONIC));
   }
   gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
 }
@@ -445,7 +445,7 @@
   /* And now wait for it to run. */
   gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
   while (a.cb_that_ran == NULL) {
-    grpc_pollset_work(&g_pollset, gpr_inf_future(GPR_CLOCK_REALTIME));
+    grpc_pollset_work(&g_pollset, gpr_inf_future(GPR_CLOCK_MONOTONIC));
   }
   GPR_ASSERT(a.cb_that_ran == first_read_callback);
   gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
@@ -463,7 +463,7 @@
 
   gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
   while (b.cb_that_ran == NULL) {
-    grpc_pollset_work(&g_pollset, gpr_inf_future(GPR_CLOCK_REALTIME));
+    grpc_pollset_work(&g_pollset, gpr_inf_future(GPR_CLOCK_MONOTONIC));
   }
   /* Except now we verify that second_read_callback ran instead */
   GPR_ASSERT(b.cb_that_ran == second_read_callback);
diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c
index 637886a..38b7b59 100644
--- a/test/core/iomgr/tcp_client_posix_test.c
+++ b/test/core/iomgr/tcp_client_posix_test.c
@@ -196,13 +196,13 @@
   gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
   while (gpr_time_cmp(gpr_time_add(connect_deadline,
                                    gpr_time_from_seconds(2, GPR_TIMESPAN)),
-                      gpr_now(GPR_CLOCK_REALTIME)) > 0) {
+                      gpr_now(connect_deadline.clock_type)) > 0) {
     int is_after_deadline =
-        gpr_time_cmp(connect_deadline, gpr_now(GPR_CLOCK_REALTIME)) <= 0;
+        gpr_time_cmp(connect_deadline, gpr_now(GPR_CLOCK_MONOTONIC)) <= 0;
     if (is_after_deadline &&
         gpr_time_cmp(gpr_time_add(connect_deadline,
                                   gpr_time_from_seconds(1, GPR_TIMESPAN)),
-                     gpr_now(GPR_CLOCK_REALTIME)) > 0) {
+                     gpr_now(GPR_CLOCK_MONOTONIC)) > 0) {
       /* allow some slack before insisting that things be done */
     } else {
       GPR_ASSERT(g_connections_complete ==
diff --git a/test/core/iomgr/tcp_server_posix_test.c b/test/core/iomgr/tcp_server_posix_test.c
index 83252a8..f8d0fe8 100644
--- a/test/core/iomgr/tcp_server_posix_test.c
+++ b/test/core/iomgr/tcp_server_posix_test.c
@@ -135,7 +135,7 @@
 
     gpr_log(GPR_DEBUG, "wait");
     while (g_nconnects == nconnects_before &&
-           gpr_time_cmp(deadline, gpr_now(GPR_CLOCK_REALTIME)) > 0) {
+           gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) > 0) {
       grpc_pollset_work(&g_pollset, deadline);
     }
     gpr_log(GPR_DEBUG, "wait done");
diff --git a/test/core/util/test_config.h b/test/core/util/test_config.h
index 063c797..7028ade 100644
--- a/test/core/util/test_config.h
+++ b/test/core/util/test_config.h
@@ -52,12 +52,12 @@
   (GRPC_TEST_SLOWDOWN_BUILD_FACTOR * GRPC_TEST_SLOWDOWN_MACHINE_FACTOR)
 
 #define GRPC_TIMEOUT_SECONDS_TO_DEADLINE(x)                                \
-  gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),                                \
+  gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),                               \
                gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e6 * (x), \
                                     GPR_TIMESPAN))
 
 #define GRPC_TIMEOUT_MILLIS_TO_DEADLINE(x)                                 \
-  gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),                                \
+  gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),                               \
                gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x), \
                                     GPR_TIMESPAN))
 
diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc
index 117d8bb..b95bdf6 100644
--- a/test/cpp/end2end/async_end2end_test.cc
+++ b/test/cpp/end2end/async_end2end_test.cc
@@ -415,7 +415,7 @@
   auto client_initial_metadata = srv_ctx.client_metadata();
   EXPECT_EQ(meta1.second, client_initial_metadata.find(meta1.first)->second);
   EXPECT_EQ(meta2.second, client_initial_metadata.find(meta2.first)->second);
-  EXPECT_EQ(static_cast<size_t>(2), client_initial_metadata.size());
+  EXPECT_GE(client_initial_metadata.size(), static_cast<size_t>(2));
 
   send_response.set_message(recv_request.message());
   response_writer.Finish(send_response, Status::OK, tag(3));
@@ -563,7 +563,7 @@
   auto client_initial_metadata = srv_ctx.client_metadata();
   EXPECT_EQ(meta1.second, client_initial_metadata.find(meta1.first)->second);
   EXPECT_EQ(meta2.second, client_initial_metadata.find(meta2.first)->second);
-  EXPECT_EQ(static_cast<size_t>(2), client_initial_metadata.size());
+  EXPECT_GE(client_initial_metadata.size(), static_cast<size_t>(2));
 
   srv_ctx.AddInitialMetadata(meta3.first, meta3.second);
   srv_ctx.AddInitialMetadata(meta4.first, meta4.second);
@@ -574,7 +574,7 @@
   auto server_initial_metadata = cli_ctx.GetServerInitialMetadata();
   EXPECT_EQ(meta3.second, server_initial_metadata.find(meta3.first)->second);
   EXPECT_EQ(meta4.second, server_initial_metadata.find(meta4.first)->second);
-  EXPECT_EQ(static_cast<size_t>(2), server_initial_metadata.size());
+  EXPECT_GE(server_initial_metadata.size(), static_cast<size_t>(2));
 
   send_response.set_message(recv_request.message());
   srv_ctx.AddTrailingMetadata(meta5.first, meta5.second);
@@ -590,7 +590,7 @@
   auto server_trailing_metadata = cli_ctx.GetServerTrailingMetadata();
   EXPECT_EQ(meta5.second, server_trailing_metadata.find(meta5.first)->second);
   EXPECT_EQ(meta6.second, server_trailing_metadata.find(meta6.first)->second);
-  EXPECT_EQ(static_cast<size_t>(2), server_trailing_metadata.size());
+  EXPECT_GE(server_trailing_metadata.size(), static_cast<size_t>(2));
 }
 }  // namespace
 }  // namespace testing
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc
index 6367bea..a865a0e 100644
--- a/test/cpp/end2end/end2end_test.cc
+++ b/test/cpp/end2end/end2end_test.cc
@@ -249,9 +249,10 @@
   void TearDown() GRPC_OVERRIDE { server_->Shutdown(); }
 
   void ResetStub() {
-    std::shared_ptr<ChannelInterface> channel =
-        CreateChannel(server_address_.str(), FakeTransportSecurityCredentials(),
-                      ChannelArguments());
+    ChannelArguments args;
+    args.SetString(GRPC_ARG_SECONDARY_USER_AGENT_STRING, "end2end_test");
+    std::shared_ptr<ChannelInterface> channel = CreateChannel(
+        server_address_.str(), FakeTransportSecurityCredentials(), args);
     stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel));
   }
 
@@ -273,7 +274,7 @@
 
   for (int i = 0; i < num_rpcs; ++i) {
     ClientContext context;
-    context._experimental_set_compression_algorithm(GRPC_COMPRESS_GZIP);
+    context.set_compression_algorithm(GRPC_COMPRESS_GZIP);
     Status s = stub->Echo(&context, request, &response);
     EXPECT_EQ(response.message(), request.message());
     EXPECT_TRUE(s.ok());
diff --git a/test/cpp/end2end/generic_end2end_test.cc b/test/cpp/end2end/generic_end2end_test.cc
index 8fe0d68..4951c82 100644
--- a/test/cpp/end2end/generic_end2end_test.cc
+++ b/test/cpp/end2end/generic_end2end_test.cc
@@ -227,7 +227,7 @@
   GenericServerContext srv_ctx;
   GenericServerAsyncReaderWriter srv_stream(&srv_ctx);
 
-  cli_ctx._experimental_set_compression_algorithm(GRPC_COMPRESS_GZIP);
+  cli_ctx.set_compression_algorithm(GRPC_COMPRESS_GZIP);
   send_request.set_message("Hello");
   std::unique_ptr<GenericClientAsyncReaderWriter> cli_stream =
       generic_stub_->Call(&cli_ctx, kMethodName, &cli_cq_, tag(1));
diff --git a/test/cpp/qps/qps_test.cc b/test/cpp/qps/qps_test.cc
index 07b4834..7b93443 100644
--- a/test/cpp/qps/qps_test.cc
+++ b/test/cpp/qps/qps_test.cc
@@ -44,8 +44,8 @@
 namespace grpc {
 namespace testing {
 
-static const int WARMUP = 5;
-static const int BENCHMARK = 10;
+static const int WARMUP = 20;
+static const int BENCHMARK = 40;
 
 static void RunQPS() {
   gpr_log(GPR_INFO, "Running QPS test");
@@ -53,8 +53,8 @@
   ClientConfig client_config;
   client_config.set_client_type(ASYNC_CLIENT);
   client_config.set_enable_ssl(false);
-  client_config.set_outstanding_rpcs_per_channel(1000);
-  client_config.set_client_channels(8);
+  client_config.set_outstanding_rpcs_per_channel(10);
+  client_config.set_client_channels(800);
   client_config.set_payload_size(1);
   client_config.set_async_client_threads(8);
   client_config.set_rpc_type(UNARY);
@@ -62,7 +62,7 @@
   ServerConfig server_config;
   server_config.set_server_type(ASYNC_SERVER);
   server_config.set_enable_ssl(false);
-  server_config.set_threads(4);
+  server_config.set_threads(8);
 
   const auto result =
       RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2);
diff --git a/tools/jenkins/docker_run_jenkins.sh b/tools/jenkins/docker_run_jenkins.sh
index eb6c914..0a5516c 100755
--- a/tools/jenkins/docker_run_jenkins.sh
+++ b/tools/jenkins/docker_run_jenkins.sh
@@ -41,5 +41,5 @@
 cd /var/local/git/grpc
 nvm use 0.12
 rvm use ruby-2.1
-tools/run_tests/prepare_travis.sh
-$arch tools/run_tests/run_tests.py -t -c $config -l $language -x report.xml
+
+setarch $arch tools/run_tests/run_tests.py -t -c $config -l $language -x report.xml
diff --git a/tools/jenkins/grpc_jenkins_slave/Dockerfile b/tools/jenkins/grpc_jenkins_slave/Dockerfile
index f37c0b9..9058b04 100644
--- a/tools/jenkins/grpc_jenkins_slave/Dockerfile
+++ b/tools/jenkins/grpc_jenkins_slave/Dockerfile
@@ -38,8 +38,10 @@
   autotools-dev \
   build-essential \
   bzip2 \
+  ccache \
   curl \
   gcc \
+  gcc-multilib \
   git \
   libc6 \
   libc6-dbg \
@@ -55,6 +57,14 @@
   wget \
   zip && apt-get clean
 
+# Prepare ccache
+RUN ln -s /usr/bin/ccache /usr/local/bin/gcc
+RUN ln -s /usr/bin/ccache /usr/local/bin/g++
+RUN ln -s /usr/bin/ccache /usr/local/bin/cc
+RUN ln -s /usr/bin/ccache /usr/local/bin/c++
+RUN ln -s /usr/bin/ccache /usr/local/bin/clang
+RUN ln -s /usr/bin/ccache /usr/local/bin/clang++
+
 ##################
 # C++ dependencies
 RUN apt-get update && apt-get -y install libgflags-dev libgtest-dev libc++-dev clang
diff --git a/tools/jenkins/grpc_jenkins_slave_32bits/Dockerfile b/tools/jenkins/grpc_jenkins_slave_32bits/Dockerfile
new file mode 100644
index 0000000..2beaf9a
--- /dev/null
+++ b/tools/jenkins/grpc_jenkins_slave_32bits/Dockerfile
@@ -0,0 +1,152 @@
+# Copyright 2015, Google Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+#     * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# A work-in-progress Dockerfile that allows running gRPC test suites
+# inside a docker container.
+
+FROM 32bit/debian:jessie
+
+# Install Git.
+RUN apt-get update && apt-get install -y \
+  autoconf \
+  autotools-dev \
+  build-essential \
+  bzip2 \
+  ccache \
+  curl \
+  gcc \
+  gcc-multilib \
+  git \
+  libc6 \
+  libc6-dbg \
+  libc6-dev \
+  libgtest-dev \
+  libtool \
+  make \
+  strace \
+  python-dev \
+  python-setuptools \
+  telnet \
+  unzip \
+  wget \
+  zip && apt-get clean
+
+# Prepare ccache
+RUN ln -s /usr/bin/ccache /usr/local/bin/gcc
+RUN ln -s /usr/bin/ccache /usr/local/bin/g++
+RUN ln -s /usr/bin/ccache /usr/local/bin/cc
+RUN ln -s /usr/bin/ccache /usr/local/bin/c++
+RUN ln -s /usr/bin/ccache /usr/local/bin/clang
+RUN ln -s /usr/bin/ccache /usr/local/bin/clang++
+
+##################
+# C++ dependencies
+RUN apt-get update && apt-get -y install libgflags-dev libgtest-dev libc++-dev clang
+
+#################
+# C# dependencies
+
+# Update to a newer version of mono
+RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
+RUN echo "deb http://download.mono-project.com/repo/debian wheezy main" | tee /etc/apt/sources.list.d/mono-xamarin.list
+RUN echo "deb http://download.mono-project.com/repo/debian wheezy-apache24-compat main" | tee -a /etc/apt/sources.list.d/mono-xamarin.list
+RUN echo "deb http://download.mono-project.com/repo/debian wheezy-libjpeg62-compat main" | tee -a /etc/apt/sources.list.d/mono-xamarin.list
+RUN echo "deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat main" | tee -a /etc/apt/sources.list.d/mono-xamarin.list
+
+# Install dependencies
+RUN apt-get update && apt-get -y dist-upgrade && apt-get install -y \
+    mono-devel \
+    nunit \
+    nunit-console \
+    monodevelop
+
+# Download NuGet
+RUN cd /var/local && wget www.nuget.org/NuGet.exe
+ENV NUGET mono /var/local/NuGet.exe
+
+# TODO(jtattermusch): add dependencies for other languages
+
+##################
+# Node dependencies
+
+# Install nvm
+RUN touch .profile
+RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash
+RUN /bin/bash -l -c "nvm install 0.12"
+
+##################
+# Ruby dependencies
+
+# Install rvm
+RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
+RUN \curl -sSL https://get.rvm.io | bash -s stable
+
+# Install Ruby 2.1
+RUN /bin/bash -l -c "rvm install ruby-2.1"
+RUN /bin/bash -l -c "rvm use --default ruby-2.1"
+RUN /bin/bash -l -c "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc"
+RUN /bin/bash -l -c "echo 'export PATH=/usr/local/rvm/bin:$PATH' >> ~/.bashrc"
+RUN /bin/bash -l -c "echo 'rvm --default use ruby-2.1' >> ~/.bashrc"
+RUN /bin/bash -l -c "gem install bundler --no-ri --no-rdoc"
+
+##################
+# Python dependencies
+
+# Install dependencies
+
+RUN apt-get update && apt-get install -y \
+    python-all-dev \
+    python3-all-dev \
+    python-pip \
+    python-virtualenv
+
+# Install Python packages from PyPI
+RUN pip install futures==2.2.0 enum34==1.0.4 protobuf==3.0.0a2
+
+# For sanity test
+RUN pip install simplejson mako
+
+##################
+# PHP dependencies
+
+# Install dependencies
+
+RUN /bin/bash -l -c "echo 'deb http://packages.dotdeb.org wheezy-php55 all' \
+    >> /etc/apt/sources.list.d/dotdeb.list"
+RUN /bin/bash -l -c "echo 'deb-src http://packages.dotdeb.org wheezy-php55 all' \
+    >> /etc/apt/sources.list.d/dotdeb.list"
+RUN wget http://www.dotdeb.org/dotdeb.gpg -O- | apt-key add -
+
+RUN apt-get update && apt-get install -y \
+    git php5 php5-dev phpunit unzip
+
+RUN mkdir /var/local/jenkins
+
+# Define the default command.
+CMD ["bash"]
diff --git a/tools/jenkins/run_distribution.sh b/tools/jenkins/run_distribution.sh
index fd31869..2824c31 100755
--- a/tools/jenkins/run_distribution.sh
+++ b/tools/jenkins/run_distribution.sh
@@ -39,19 +39,19 @@
     sha1=$(sha1sum tools/jenkins/grpc_linuxbrew/Dockerfile | cut -f1 -d\ )
     DOCKER_IMAGE_NAME=grpc_linuxbrew_$sha1
 
+    # build docker image, contains all pre-requisites
     docker build -t $DOCKER_IMAGE_NAME tools/jenkins/grpc_linuxbrew
 
-    supported="python nodejs ruby php"
-
     if [ "$language" == "core" ]; then
       command="curl -fsSL https://goo.gl/getgrpc | bash -"
-    elif [[ "$supported" =~ "$language" ]]; then
+    elif [[ "python nodejs ruby php" =~ "$language" ]]; then
       command="curl -fsSL https://goo.gl/getgrpc | bash -s $language"
     else
       echo "unsupported language $language"
       exit 1
     fi
 
+    # run per-language homebrew installation script
     docker run $DOCKER_IMAGE_NAME bash -l \
       -c "nvm use 0.12; \
           npm set unsafe-perm true; \
@@ -66,26 +66,81 @@
 elif [ "$platform" == "macos" ]; then
 
   if [ "$dist_channel" == "homebrew" ]; then
-    which brew # TODO: for debug, can be removed later
+    # system installed homebrew, don't interfere
     brew list -l
-    dir=/tmp/homebrew-test-$language
-    rm -rf $dir
-    mkdir -p $dir
-    git clone https://github.com/Homebrew/homebrew.git $dir
-    cd $dir
-    # TODO: Uncomment these when the general structure of the script is verified
-    # PATH=$dir/bin:$PATH brew tap homebrew/dupes
-    # PATH=$dir/bin:$PATH brew install zlib
-    # PATH=$dir/bin:$PATH brew install openssl
-    # PATH=$dir/bin:$PATH brew tap grpc/grpc
-    # PATH=$dir/bin:$PATH brew install --without-python google-protobuf
-    # PATH=$dir/bin:$PATH brew install grpc
-    PATH=$dir/bin:$PATH brew list -l
+
+    # Set up temp directories for test installation of homebrew
+    brew_root=/tmp/homebrew-test-$language
+    rm -rf $brew_root
+    mkdir -p $brew_root
+    git clone https://github.com/Homebrew/homebrew.git $brew_root
+
+    # Install grpc via homebrew
+    #
+    # The temp $PATH env variable makes sure we are operating at the right copy of
+    # temp homebrew installation, and do not interfere with the system's main brew
+    # installation.
+    #
+    # TODO: replace the next section with the actual homebrew installation script
+    # i.e. curl -fsSL https://goo.gl/getgrpc | bash -s $language
+    # need to resolve a bunch of environment and privilege issue on the jenkins
+    # mac machine itself
+    OLD_PATH=$PATH
+    PATH=$brew_root/bin:$PATH
+    cd $brew_root
+    brew tap homebrew/dupes
+    brew install zlib
+    brew install openssl
+    brew tap grpc/grpc
+    brew install --without-python google-protobuf
+    brew install grpc
     brew list -l
+
+    # Install per-language modules/extensions on top of core grpc
+    #
+    # If a command below needs root access, the binary had been added to
+    # /etc/sudoers. This step needs to be repeated if we add more mac instances
+    # to our jenkins project.
+    #
+    # Examples (lines that needed to be added to /etc/sudoers):
+    # + Defaults        env_keep += "CFLAGS CXXFLAGS LDFLAGS enable_grpc"
+    # + jenkinsnode1 ALL=(ALL) NOPASSWD: /usr/bin/pecl, /usr/local/bin/pip,
+    # +   /usr/local/bin/npm
+    case $language in
+      *core*) ;;
+      *python*)
+        sudo CFLAGS=-I$brew_root/include LDFLAGS=-L$brew_root/lib pip install grpcio
+        pip list | grep grpcio
+        echo 'y' | sudo pip uninstall grpcio
+        ;;
+      *nodejs*)
+        sudo CXXFLAGS=-I$brew_root/include LDFLAGS=-L$brew_root/lib npm install grpc
+        npm list | grep grpc
+        sudo npm uninstall grpc
+        ;;
+      *ruby*)
+        gem install grpc -- --with-grpc-dir=$brew_root
+        gem list | grep grpc
+        gem uninstall grpc
+        ;;
+      *php*)
+        sudo enable_grpc=$brew_root CFLAGS="-Wno-parentheses-equality" pecl install grpc-alpha
+        pecl list | grep grpc
+        sudo pecl uninstall grpc
+        ;;
+      *)
+        echo "Unsupported language $language"
+        exit 1
+        ;;
+    esac
+
+    # clean up
     cd ~/ 
-    rm -rf $dir
-    echo $PATH # TODO: for debug, can be removed later
-    brew list -l # TODO: for debug, can be removed later
+    rm -rf $brew_root
+
+    # Make sure the system brew installation is still unaffected
+    PATH=$OLD_PATH
+    brew list -l
 
   else
     echo "Unsupported $platform dist_channel $dist_channel"
diff --git a/tools/jenkins/run_jenkins.sh b/tools/jenkins/run_jenkins.sh
index 8cb85cb..56f9e82 100755
--- a/tools/jenkins/run_jenkins.sh
+++ b/tools/jenkins/run_jenkins.sh
@@ -46,6 +46,7 @@
   i386)
     arch="i386"
     platform="linux"
+    docker_suffix=_32bits
     ;;
 esac
 
@@ -57,11 +58,13 @@
   git_root=`pwd`
   cd -
 
+  mkdir -p /tmp/ccache
+
   # Use image name based on Dockerfile checksum
-  DOCKER_IMAGE_NAME=grpc_jenkins_slave_`sha1sum tools/jenkins/grpc_jenkins_slave/Dockerfile | cut -f1 -d\ `
+  DOCKER_IMAGE_NAME=grpc_jenkins_slave$docker_suffix_`sha1sum tools/jenkins/grpc_jenkins_slave/Dockerfile | cut -f1 -d\ `
 
   # Make sure docker image has been built. Should be instantaneous if so.
-  docker build -t $DOCKER_IMAGE_NAME tools/jenkins/grpc_jenkins_slave
+  docker build -t $DOCKER_IMAGE_NAME tools/jenkins/grpc_jenkins_slave$docker_suffix
 
   # Create a local branch so the child Docker script won't complain
   git branch jenkins-docker
@@ -74,8 +77,10 @@
     -e "config=$config" \
     -e "language=$language" \
     -e "arch=$arch" \
+    -e CCACHE_DIR=/tmp/ccache \
     -i \
     -v "$git_root:/var/local/jenkins/grpc" \
+    -v /tmp/ccache:/tmp/ccache \
     --cidfile=docker.cid \
     $DOCKER_IMAGE_NAME \
     bash -l /var/local/jenkins/grpc/tools/jenkins/docker_run_jenkins.sh || DOCKER_FAILED="true"