VirtualBox

Changeset 103569 in vbox


Ignore:
Timestamp:
Feb 26, 2024 1:11:52 PM (11 months ago)
Author:
vboxsync
Message:

libs/xpcom: Replace the old ipcMessageWriter helper class with an inline version to avoid function calls in hot code paths, ​bugref:10597

Location:
trunk/src/libs/xpcom18a4
Files:
1 added
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/Makefile.kmk

    r103562 r103569  
    292292IPCD-HEADERS_SOURCES = \
    293293        ipc/ipcd/client/public/ipcCID.h \
    294         ipc/ipcd/util/public/ipcMessageWriter.h \
    295294        ipc/ipcd/client/public/ipcdclient.h
    296295
     
    813812        ipc/ipcd/client/src/ipcModuleFactory.cpp \
    814813        ipc/ipcd/extensions/dconnect/src/ipcDConnectService.cpp \
    815         \
    816         ipc/ipcd/util/src/ipcMessageWriter.cpp \
    817814        \
    818815        ipc/ipcd/client/src/ipcConnectionUnix.cpp
  • trunk/src/libs/xpcom18a4/ipc/ipcd/extensions/dconnect/src/ipcDConnectService.cpp

    r103563 r103569  
    3838#define LOG_GROUP LOG_GROUP_IPC
    3939#include "ipcDConnectService.h"
    40 #include "ipcMessageWriter.h"
    41 #include "ipcMsgReader.h"
    4240
    4341#include "nsIServiceManagerUtils.h"
     
    321319
    322320static nsresult
    323 SerializeParam(ipcMessageWriter &writer, const nsXPTType &t, const nsXPTCMiniVariant &v)
     321SerializeParam(PIPCMSGWRITER pMsgWriter, const nsXPTType &t, const nsXPTCMiniVariant &v)
    324322{
    325323  switch (t.TagPart())
     
    327325    case nsXPTType::T_I8:
    328326    case nsXPTType::T_U8:
    329       writer.PutInt8(v.val.u8);
     327      IPCMsgWriterPutU8(pMsgWriter, v.val.u8);
    330328      break;
    331329
    332330    case nsXPTType::T_I16:
    333331    case nsXPTType::T_U16:
    334       writer.PutInt16(v.val.u16);
     332      IPCMsgWriterPutU16(pMsgWriter, v.val.u16);
    335333      break;
    336334
    337335    case nsXPTType::T_I32:
    338336    case nsXPTType::T_U32:
    339       writer.PutInt32(v.val.u32);
     337      IPCMsgWriterPutU32(pMsgWriter, v.val.u32);
    340338      break;
    341339
    342340    case nsXPTType::T_I64:
    343341    case nsXPTType::T_U64:
    344       writer.PutBytes(&v.val.u64, sizeof(PRUint64));
     342      IPCMsgWriterPutU64(pMsgWriter, v.val.u64);
    345343      break;
    346344
    347345    case nsXPTType::T_FLOAT:
    348       writer.PutBytes(&v.val.f, sizeof(float));
     346      IPCMsgWriterPutBytes(pMsgWriter, &v.val.f, sizeof(float));
    349347      break;
    350348
    351349    case nsXPTType::T_DOUBLE:
    352       writer.PutBytes(&v.val.d, sizeof(double));
     350      IPCMsgWriterPutBytes(pMsgWriter, &v.val.d, sizeof(double));
    353351      break;
    354352
    355353    case nsXPTType::T_BOOL:
    356       writer.PutBytes(&v.val.b, sizeof(PRBool));
     354      IPCMsgWriterPutBytes(pMsgWriter, &v.val.b, sizeof(PRBool));
    357355      break;
    358356
    359357    case nsXPTType::T_CHAR:
    360       writer.PutBytes(&v.val.c, sizeof(char));
     358      IPCMsgWriterPutBytes(pMsgWriter, &v.val.c, sizeof(char));
    361359      break;
    362360
    363361    case nsXPTType::T_WCHAR:
    364       writer.PutBytes(&v.val.wc, sizeof(PRUnichar));
     362      IPCMsgWriterPutBytes(pMsgWriter, &v.val.wc, sizeof(PRUnichar));
    365363      break;
    366364
     
    368366      {
    369367        AssertReturn(v.val.p, NS_ERROR_INVALID_POINTER);
    370         writer.PutBytes(v.val.p, sizeof(nsID));
     368        IPCMsgWriterPutBytes(pMsgWriter, v.val.p, sizeof(nsID));
    371369      }
    372370      break;
     
    377375        {
    378376          int len = strlen((const char *) v.val.p);
    379           writer.PutInt32(len);
    380           writer.PutBytes(v.val.p, len);
     377          IPCMsgWriterPutU32(pMsgWriter, len);
     378          IPCMsgWriterPutBytes(pMsgWriter, v.val.p, len);
    381379        }
    382380        else
    383381        {
    384382          // put -1 to indicate null string
    385           writer.PutInt32((PRUint32) -1);
     383          IPCMsgWriterPutU32(pMsgWriter, (PRUint32) -1);
    386384        }
    387385      }
     
    393391        {
    394392          int len = 2 * nsCRT::strlen((const PRUnichar *) v.val.p);
    395           writer.PutInt32(len);
    396           writer.PutBytes(v.val.p, len);
     393          IPCMsgWriterPutU32(pMsgWriter, len);
     394          IPCMsgWriterPutBytes(pMsgWriter, v.val.p, len);
    397395        }
    398396        else
    399397        {
    400398          // put -1 to indicate null string
    401           writer.PutInt32((PRUint32) -1);
     399          IPCMsgWriterPutU32(pMsgWriter, (PRUint32) -1);
    402400        }
    403401      }
     
    418416        const PRUnichar *data = str->BeginReading(begin).get();
    419417
    420         writer.PutInt32(len);
    421         writer.PutBytes(data, len);
     418        IPCMsgWriterPutU32(pMsgWriter, len);
     419        IPCMsgWriterPutBytes(pMsgWriter, data, len);
    422420      }
    423421      break;
     
    432430        const char *data = str->BeginReading(begin).get();
    433431
    434         writer.PutInt32(len);
    435         writer.PutBytes(data, len);
     432        IPCMsgWriterPutU32(pMsgWriter, len);
     433        IPCMsgWriterPutBytes(pMsgWriter, data, len);
    436434      }
    437435      break;
     
    996994static nsresult
    997995SerializeArrayParam(ipcDConnectService *dConnect,
    998                     ipcMessageWriter &writer, PRUint32 peerID,
     996                    PIPCMSGWRITER pMsgWriter, PRUint32 peerID,
    999997                    nsIInterfaceInfo *iinfo, uint16 methodIndex,
    1000998                    const nsXPTMethodInfo &methodInfo,
     
    10061004  {
    10071005    // put 0 to indicate null array
    1008     writer.PutInt8(0);
     1006    IPCMsgWriterPutU8(pMsgWriter, 0);
    10091007    return NS_OK;
    10101008  }
    10111009
    10121010  // put 1 to indicate non-null array
    1013   writer.PutInt8(1);
     1011  IPCMsgWriterPutU8(pMsgWriter, 1);
    10141012
    10151013  PRUint32 size = 0;
     
    10321030  {
    10331031    // this is a simple arithmetic type, write the whole array at once
    1034     writer.PutBytes(array, length * elemSize);
     1032    IPCMsgWriterPutBytes(pMsgWriter, array, length * elemSize);
    10351033    return NS_OK;
    10361034  }
     
    10501048                                          iid);
    10511049      if (NS_SUCCEEDED(rv))
    1052         rv = dConnect->SerializeInterfaceParam(writer, peerID, iid,
     1050        rv = dConnect->SerializeInterfaceParam(pMsgWriter, peerID, iid,
    10531051                                               (nsISupports *) v.val.p,
    10541052                                               wrappers);
    10551053    }
    10561054    else
    1057       rv = SerializeParam(writer, elemType, v);
     1055      rv = SerializeParam(pMsgWriter, elemType, v);
    10581056
    10591057    if (NS_FAILED(rv))
     
    16311629
    16321630nsresult
    1633 ipcDConnectService::SerializeInterfaceParam(ipcMessageWriter &writer,
     1631ipcDConnectService::SerializeInterfaceParam(PIPCMSGWRITER pMsgWriter,
    16341632                                            PRUint32 peer, const nsID &iid,
    16351633                                            nsISupports *obj,
     
    16611659    // write null address
    16621660    DConAddr nullobj = 0;
    1663     writer.PutBytes(&nullobj, sizeof(nullobj));
     1661    IPCMsgWriterPutBytes(pMsgWriter, &nullobj, sizeof(nullobj));
    16641662  }
    16651663  else
     
    16701668    {
    16711669      DConAddr p = stub->Instance();
    1672       writer.PutBytes(&p, sizeof(p));
     1670      IPCMsgWriterPutBytes(pMsgWriter, &p, sizeof(p));
    16731671    }
    16741672    else
     
    17211719      NS_ASSERTION((bits & PTRBITS_REMOTE_BIT) == 0, "remote bit wrong)");
    17221720      bits |= PTRBITS_REMOTE_BIT;
    1723       writer.PutBytes(&bits, sizeof(bits));
     1721      IPCMsgWriterPutBytes(pMsgWriter, &bits, sizeof(bits));
    17241722    }
    17251723    NS_IF_RELEASE(stub);
     
    19521950
    19531951nsresult
    1954 ipcDConnectService::SerializeException(ipcMessageWriter &writer,
     1952ipcDConnectService::SerializeException(PIPCMSGWRITER pMsgWriter,
    19551953                                       PRUint32 peer, nsIException *xcpt,
    19561954                                       nsVoidArray &wrappers)
     
    19761974      // see ipcDConnectService::DeserializeException()!
    19771975      PtrBits bits = 0;
    1978       writer.PutBytes(&bits, sizeof(bits));
     1976      IPCMsgWriterPutBytes(pMsgWriter, &bits, sizeof(bits));
    19791977#else
    1980       writer.PutBytes(&xcpt, sizeof(xcpt));
     1978      IPCMsgWriterPutBytes(pMsgWriter, &xcpt, sizeof(xcpt));
    19811979#endif
    19821980    }
     
    19891987        // send the wrapper instance back to the peer
    19901988        DConAddr p = stub->Stub()->Instance();
    1991         writer.PutBytes(&p, sizeof(p));
     1989        IPCMsgWriterPutBytes(pMsgWriter, &p, sizeof(p));
    19921990      }
    19931991      else
     
    20392037        // to the remote party that this is a remote instance wrapper.
    20402038        PtrBits bits = ((PtrBits)(uintptr_t) wrapper) | PTRBITS_REMOTE_BIT;
    2041         writer.PutBytes(&bits, sizeof(bits));
     2039        IPCMsgWriterPutBytes(pMsgWriter, &bits, sizeof(bits));
    20422040
    20432041        // we want to cache fields to minimize the number of IPC calls when
     
    20632061    nsACString::const_iterator begin;
    20642062    const char *data = str.BeginReading(begin).get();
    2065     writer.PutInt32(len);
    2066     writer.PutBytes(data, len);
     2063    IPCMsgWriterPutU32(pMsgWriter, len);
     2064    IPCMsgWriterPutBytes(pMsgWriter, data, len);
    20672065  }
    20682066  else
    2069     writer.PutInt32(0);
     2067    IPCMsgWriterPutU32(pMsgWriter, 0);
    20702068
    20712069  // result
    20722070  nsresult res = 0;
    20732071  xcpt->GetResult(&res);
    2074   writer.PutInt32(res);
     2072  IPCMsgWriterPutU32(pMsgWriter, res);
    20752073
    20762074  // name
     
    20812079    nsACString::const_iterator begin;
    20822080    const char *data = str.BeginReading(begin).get();
    2083     writer.PutInt32(len);
    2084     writer.PutBytes(data, len);
     2081    IPCMsgWriterPutU32(pMsgWriter, len);
     2082    IPCMsgWriterPutBytes(pMsgWriter, data, len);
    20852083  }
    20862084  else
    2087     writer.PutInt32(0);
     2085    IPCMsgWriterPutU32(pMsgWriter, 0);
    20882086
    20892087  // filename
     
    20942092    nsACString::const_iterator begin;
    20952093    const char *data = str.BeginReading(begin).get();
    2096     writer.PutInt32(len);
    2097     writer.PutBytes(data, len);
     2094    IPCMsgWriterPutU32(pMsgWriter, len);
     2095    IPCMsgWriterPutBytes(pMsgWriter, data, len);
    20982096  }
    20992097  else
    2100     writer.PutInt32(0);
     2098    IPCMsgWriterPutU32(pMsgWriter, 0);
    21012099
    21022100  // lineNumber
    21032101  num = 0;
    21042102  xcpt->GetLineNumber(&num);
    2105   writer.PutInt32(num);
     2103  IPCMsgWriterPutU32(pMsgWriter, num);
    21062104
    21072105  // columnNumber
    21082106  num = 0;
    21092107  xcpt->GetColumnNumber(&num);
    2110   writer.PutInt32(num);
    2111 
    2112   return writer.HasError() ? NS_ERROR_OUT_OF_MEMORY : NS_OK;
     2108  IPCMsgWriterPutU32(pMsgWriter, num);
     2109
     2110  return IPCMsgWriterHasError(pMsgWriter) ? NS_ERROR_OUT_OF_MEMORY : NS_OK;
    21132111}
    21142112
     
    25262524#endif
    25272525
    2528 
    2529   ipcMessageWriter writer(16 * paramCount);
     2526  IPCMSGWRITER MsgWriter;
     2527  IPCMsgWriterInit(&MsgWriter, 16 * paramCount);
    25302528
    25312529  // INVOKE message header
     
    25402538  Log(("  request-index=%d\n", (PRUint32) invoke.request_index));
    25412539
    2542   writer.PutBytes(&invoke, sizeof(invoke));
     2540  IPCMsgWriterPutBytes(&MsgWriter, &invoke, sizeof(invoke));
    25432541
    25442542  // list of wrappers that get created during parameter serialization.  if we
     
    25602558                                             aMethodIndex, aParams, PR_FALSE, iid);
    25612559        if (NS_SUCCEEDED(rv))
    2562           rv = dConnect->SerializeInterfaceParam(writer, mPeerID, iid,
     2560          rv = dConnect->SerializeInterfaceParam(&MsgWriter, mPeerID, iid,
    25632561                                                 (nsISupports *) aParams[i].val.p,
    25642562                                                 wrappers);
    25652563      }
    25662564      else
    2567         rv = SerializeParam(writer, type, aParams[i]);
     2565        rv = SerializeParam(&MsgWriter, type, aParams[i]);
    25682566
    25692567      AssertMsgBreak(NS_SUCCEEDED(rv), ("i=%d rv=%#x\n", i, rv));
     
    25822580    // INVOKE message wasn't sent; clean up wrappers
    25832581    dConnect->ReleaseWrappers(wrappers, mPeerID);
     2582    IPCMsgWriterCleanup(&MsgWriter);
    25842583    return rv;
    25852584  }
     
    25952594        paramInfo.IsIn() && !paramInfo.IsDipper())
    25962595    {
    2597       rv = SerializeArrayParam(dConnect, writer, mPeerID, mIInfo, aMethodIndex,
     2596      rv = SerializeArrayParam(dConnect, &MsgWriter, mPeerID, mIInfo, aMethodIndex,
    25982597                               *aInfo, aParams, PR_FALSE, paramInfo,
    25992598                               aParams[i].val.p, wrappers);
     
    26022601        // INVOKE message wasn't sent; clean up wrappers
    26032602        dConnect->ReleaseWrappers(wrappers, mPeerID);
     2603        IPCMsgWriterCleanup(&MsgWriter);
    26042604        return rv;
    26052605      }
     
    26122612
    26132613  rv = IPC_SendMessage(mPeerID, kDConnectTargetID,
    2614                        writer.GetBuffer(),
    2615                        writer.GetSize());
     2614                       IPCMsgWriterGetBuf(&MsgWriter),
     2615                       IPCMsgWriterGetSize(&MsgWriter));
     2616  IPCMsgWriterCleanup(&MsgWriter);
     2617
    26162618  Log(("DConnectStub::CallMethod: IPC_SendMessage()=%08X\n", rv));
    26172619  if (NS_FAILED(rv))
     
    35843586  }
    35853587
    3586   ipcMessageWriter writer(64);
     3588  IPCMSGWRITER MsgWriter;
     3589  IPCMsgWriterInit(&MsgWriter, 64 /*cbInitial*/);
    35873590
    35883591  DConnectSetupReply msg;
     
    35973600    msg.flags |= DCON_OP_FLAGS_REPLY_EXCEPTION;
    35983601
    3599   writer.PutBytes(&msg, sizeof(msg));
     3602  IPCMsgWriterPutBytes(&MsgWriter, &msg, sizeof(msg));
    36003603
    36013604  if (got_exception)
    36023605  {
    3603     rv = SerializeException(writer, peer, exception, wrappers);
     3606    rv = SerializeException(&MsgWriter, peer, exception, wrappers);
    36043607    NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get/serialize exception");
    36053608  }
     
    36113614  else
    36123615    rv = IPC_SendMessage(peer, kDConnectTargetID,
    3613                          writer.GetBuffer(), writer.GetSize());
     3616                         IPCMsgWriterGetBuf(&MsgWriter), IPCMsgWriterGetSize(&MsgWriter));
    36143617
    36153618  if (NS_FAILED(rv))
     
    36183621    ReleaseWrappers(wrappers, peer);
    36193622  }
     3623
     3624  IPCMsgWriterCleanup(&MsgWriter);
    36203625}
    36213626
     
    38133818    wrapper->Release();
    38143819
    3815   ipcMessageWriter writer(64);
     3820  IPCMSGWRITER MsgWriter;
     3821  IPCMsgWriterInit(&MsgWriter, 64 /*cbInitial*/);
    38163822
    38173823  DConnectInvokeReply reply;
     
    38253831    reply.flags |= DCON_OP_FLAGS_REPLY_EXCEPTION;
    38263832
    3827   writer.PutBytes(&reply, sizeof(reply));
     3833  IPCMsgWriterPutBytes(&MsgWriter, &reply, sizeof(reply));
    38283834
    38293835  nsVoidArray wrappers;
     
    38463852                                    invoke->method_index, params, PR_TRUE, iid);
    38473853          if (NS_SUCCEEDED(rv))
    3848             rv = SerializeInterfaceParam(writer, peer, iid,
     3854            rv = SerializeInterfaceParam(&MsgWriter, peer, iid,
    38493855                                         (nsISupports *) params[i].val.p, wrappers);
    38503856        }
    38513857        else
    3852           rv = SerializeParam(writer, type, params[i]);
     3858          rv = SerializeParam(&MsgWriter, type, params[i]);
    38533859
    38543860        if (NS_FAILED(rv))
     
    38723878            (paramInfo.IsRetval() || paramInfo.IsOut()))
    38733879        {
    3874           rv = SerializeArrayParam(this, writer, peer, iinfo, invoke->method_index,
     3880          rv = SerializeArrayParam(this, &MsgWriter, peer, iinfo, invoke->method_index,
    38753881                                   *methodInfo, params, PR_TRUE, paramInfo,
    38763882                                   params[i].val.p, wrappers);
     
    38873893  if (got_exception)
    38883894  {
    3889     rv = SerializeException(writer, peer, exception, wrappers);
     3895    rv = SerializeException(&MsgWriter, peer, exception, wrappers);
    38903896    NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get/serialize exception");
    38913897  }
     
    38943900    rv = IPC_SendMessage(peer, kDConnectTargetID, (const PRUint8 *) &reply, sizeof(reply));
    38953901  else
    3896     rv = IPC_SendMessage(peer, kDConnectTargetID, writer.GetBuffer(), writer.GetSize());
     3902    rv = IPC_SendMessage(peer, kDConnectTargetID, IPCMsgWriterGetBuf(&MsgWriter), IPCMsgWriterGetSize(&MsgWriter));
    38973903  if (NS_FAILED(rv))
    38983904  {
     
    39173923    RTMemFree(params);
    39183924  }
    3919 }
     3925
     3926  IPCMsgWriterCleanup(&MsgWriter);
     3927}
  • trunk/src/libs/xpcom18a4/ipc/ipcd/extensions/dconnect/src/ipcDConnectService.h

    r103562 r103569  
    4040
    4141#include "ipcMsgReader.h"
     42#include "ipcMsgWriter.h"
    4243
    4344#include "nsIInterfaceInfo.h"
     
    5758
    5859class nsIException;
    59 class ipcMessageWriter;
    6060
    6161// a key class used to identify DConnectInstance objects stored in a hash table
     
    194194                                            nsID &result);
    195195
    196   NS_HIDDEN_(nsresult) SerializeInterfaceParam(ipcMessageWriter &writer,
     196  NS_HIDDEN_(nsresult) SerializeInterfaceParam(PIPCMSGWRITER pMsgWriter,
    197197                                               PRUint32 peer, const nsID &iid,
    198198                                               nsISupports *obj,
     
    202202                                                     nsISupports *&obj);
    203203
    204   NS_HIDDEN_(nsresult) SerializeException(ipcMessageWriter &writer,
     204  NS_HIDDEN_(nsresult) SerializeException(PIPCMSGWRITER pMsgWriter,
    205205                                          PRUint32 peer, nsIException *xcpt,
    206206                                          nsVoidArray &wrappers);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette