Problem using V8RuntimeConstraints

Nov 13, 2014 at 9:34 PM
I'm running into a problem trying to use V8RuntimeConstraints when creating a V8ScriptEngine, and I'm not doing anything weird so I'm guessing there must be something wrong with my project. I'm posting here in case anyone else has hit this and has a suggestion.

I'm using ClearScript 5.4.0 built myself from the official download. If I don't pass in any constraints, everything works fine. With constraints, I get a System.Reflection.TargetInvocationException when V8Proxy tries to create an instance of V8ContextProxyImpl.

The details:

Code:

var constraints = new V8RuntimeConstraints();
constraints .MaxExecutableSize = 1024*1024;
constraints .MaxNewSpaceSize = 1024 * 1024;
constraints .MaxOldSpaceSize = 1024 * 1024;

var engine = new V8ScriptEngine(EngineConstraints); // Exception thrown in here

The exception:
  • $exception {"Exception has been thrown by the target of an invocation."} System.Exception {System.Reflection.TargetInvocationException}
  • [System.Reflection.TargetInvocationException] {"Exception has been thrown by the target of an invocation."} System.Reflection.TargetInvocationException
    _className  null    string
  • _data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
    _dynamicMethods null    object
    _exceptionMethod    null    System.Reflection.MethodBase
    _exceptionMethodString  null    string
    _helpURL    null    string
    _HResult    -2146232828 int
  • _innerException {"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."} System.Exception {System.AccessViolationException}
  • _ipForWatsonBuckets 0 System.UIntPtr
    _message    "Exception has been thrown by the target of an invocation." string
    _remoteStackIndex   0   int
    _remoteStackTraceString null    string
  • _safeSerializationManager {System.Runtime.Serialization.SafeSerializationManager} System.Runtime.Serialization.SafeSerializationManager
    _source null    string
  • _stackTrace {sbyte[48]} object {sbyte[]}
    _stackTraceString   null    string
  • _watsonBuckets {byte[5616]} object {byte[]}
    _xcode  -532462766  int
  • _xptrs 0 System.IntPtr
  • Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
    HelpLink    null    string
    HResult -2146232828 int
  • InnerException {"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."} System.Exception {System.AccessViolationException}
  • IPForWatsonBuckets 0 System.UIntPtr
    IsTransient false   bool
    Message "Exception has been thrown by the target of an invocation." string
    RemoteStackTrace    null    string
    Source  "mscorlib"  string
    StackTrace  "   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)\r\n   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)"   string
  • TargetSite {System.Object InvokeMethod(System.Object, System.Object[], System.Signature, Boolean)} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
  • WatsonBuckets {byte[5616]} object {byte[]}
  • Static members
Seems like there's a bad pointer or something at the C++ level. I have no idea why that would be going wrong. Any ideas?
Coordinator
Nov 14, 2014 at 3:15 AM
Greetings!

We ran a quick test using your V8RuntimeConstraints configuration. It turns out that those numbers are too tight for V8 to get off the ground, much less run any script code. It exceeds those limits during initialization and kills the process.

Unfortunately this is how newer V8 builds deal with out-of-memory situations: immediate process termination. In the past V8 had graceful out-of-memory handling, but its developers sacrificed that in favor of performance. You can find more information here.

Because V8 now crashes instead of reporting out-of-memory errors, V8RuntimeConstraints is no longer generally useful. We recommend that you avoid it unless your application uses a Chrome-like multi-process architecture that withstands process crashes.

Good luck!
Nov 14, 2014 at 4:13 PM
Good to know, thanks for the update.