Some HipHop fixes:
authorTim Starling <tstarling@users.mediawiki.org>
Fri, 27 May 2011 06:25:21 +0000 (06:25 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Fri, 27 May 2011 06:25:21 +0000 (06:25 +0000)
* Scan the C++ for volatile classes and show a warning with a list of them
* Fixed volatile classes Revision, CoreLinkFunctions and FileRepoStatus, made them non-volatile by patching the referring code
* Added some configuration for the build process to DefaultSettings.php.
* Split a few functions off MakeHipHop::execute()
* Only include UtfNormalDefines.php in interpreted mode, since in compiled mode, the constants exist from startup
* Apparently HipHop does not support set_exception_handler(). Added a try/catch block around the main part of index.php instead.
* Fixed ini_get() dependencies in Special:Upload. Upload now works, if you disable ZipDirectoryReader.

includes/DefaultSettings.php
includes/Init.php
includes/Setup.php
includes/filerepo/FileRepo.php
includes/parser/Parser_LinkHooks.php
includes/specials/SpecialUpload.php
includes/upload/UploadBase.php
index.php
maintenance/hiphop/make
maintenance/userDupes.inc

index 7047bfb..012ac5f 100644 (file)
@@ -5308,6 +5308,25 @@ $wgUpdateRowsPerQuery = 100;
 
 /** @} */ # End job queue }
 
+/************************************************************************//**
+ * @name   HipHop compilation
+ * @{
+ */
+
+/**
+ * The HipHop build type. Can be either "Debug" or "Release".
+ */
+$wgHipHopBuildType = 'Debug';
+
+/**
+ * Number of parallel processes to use during HipHop compilation, or "detect"
+ * to guess from system properties.
+ */
+$wgHipHopCompilerProcs = 'detect';
+
+/** @} */ # End of HipHop compilation }
+
+
 /************************************************************************//**
  * @name   Miscellaneous
  * @{
index 4c84b9a..7f1449f 100644 (file)
@@ -90,4 +90,13 @@ class MWInit {
                }
                return $r !== false;
        }
+
+       /**
+        * Call a static method of a class with variable arguments without causing 
+        * it to become volatile.
+        */
+       static function callStaticMethod( $className, $methodName, $args ) {
+               $r = new ReflectionMethod( $className, $methodName );
+               return $r->invokeArgs( null, $args );
+       }
 }
index f343c49..e70868a 100644 (file)
@@ -337,9 +337,9 @@ if ( !defined( 'MW_COMPILED' ) ) {
        require_once( "$IP/includes/Hooks.php" );
        require_once( "$IP/includes/ProxyTools.php" );
        require_once( "$IP/includes/ImageFunctions.php" );
+       require_once( "$IP/includes/normal/UtfNormalDefines.php" );
        wfProfileOut( $fname . '-includes' );
 }
-require_once( MWInit::compiledPath( 'includes/normal/UtfNormalDefines.php' ) );
 
 wfProfileIn( $fname . '-misc1' );
 
index 7fe8e81..6b87f63 100644 (file)
@@ -606,7 +606,7 @@ abstract class FileRepo {
        function newFatal( $message /*, parameters...*/ ) {
                $params = func_get_args();
                array_unshift( $params, $this );
-               return call_user_func_array( array( 'FileRepoStatus', 'newFatal' ), $params );
+               return MWInit::callStaticMethod( 'FileRepoStatus', 'newFatal', $params );
        }
 
        /**
index e3fab9d..90e4494 100644 (file)
@@ -254,8 +254,8 @@ class Parser_LinkHooks extends Parser {
                }
                if( $return === true ) {
                        # True (treat as plain link) was returned, call the defaultLinkHook
-                       $args = array( $parser, $holders, $markers, $title, $titleText, &$paramText, &$leadingColon );
-                       $return = call_user_func_array( array( 'CoreLinkFunctions', 'defaultLinkHook' ), $args );
+                       $return = CoreLinkFunctions::defaultLinkHook( $parser, $holders, $markers, $title, 
+                               $titleText, $paramText, $leadingColon );
                }
                if( $return === false ) {
                        # False (no link) was returned, output plain wikitext
index f793b41..bb5c91f 100644 (file)
@@ -863,9 +863,13 @@ class UploadForm extends HTMLForm {
                        );
                }
 
-               $this->mMaxUploadSize['file'] = min(
-                       wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ),
-                       UploadBase::getMaxUploadSize( 'file' ) );
+               $this->mMaxUploadSize['file'] = UploadBase::getMaxUploadSize( 'file' );
+               # Limit to upload_max_filesize unless we are running under HipHop and 
+               # that setting doesn't exist
+               if ( !wfIsHipHop() ) {
+                       $this->mMaxUploadSize['file'] = min( $this->mMaxUploadSize['file'],
+                               wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ) );
+               }
 
                $descriptor['UploadFile'] = array(
                        'class' => 'UploadSourceField',
index a824308..967c8ad 100644 (file)
@@ -75,7 +75,7 @@ abstract class UploadBase {
                }
 
                # Check php's file_uploads setting
-               if( !wfIniGetBool( 'file_uploads' ) ) {
+               if( !wfIsHipHop() && !wfIniGetBool( 'file_uploads' ) ) {
                        return false;
                }
                return true;
index 4fed9b8..9caed7a 100644 (file)
--- a/index.php
+++ b/index.php
@@ -66,7 +66,11 @@ ENDL;
 # does *not* load $wgTitle
 require ( dirname( __FILE__ ) . '/includes/WebStart.php' );
 
-wfIndexMain();
+try {
+       wfIndexMain();
+} catch ( Exception $e ) {
+       wfExceptionHandler( $e );
+}
 
 function wfIndexMain() {
        global $wgRequest, $wgShowHostnames, $mediaWiki, $wgTitle, $wgUseAjax, $wgUseFileCache;
index 60388ac..bfeb960 100755 (executable)
@@ -4,7 +4,6 @@
 require( dirname( __FILE__ ) . '/../Maintenance.php' );
 
 class MakeHipHop extends Maintenance {
-
        function execute() {
                $startTime = time();
 
@@ -63,13 +62,21 @@ class MakeHipHop extends Maintenance {
                        ' --parse-on-demand=false' .
                        ' --program=mediawiki-hphp' .
                        ' --output-dir=' . wfEscapeShellArg( $outDir ) .
-                       ' --log=3' );
+                       ' --log=3', $ret );
+
+               if ( $ret ) {
+                       $this->error( "hphp hit an error. Stopping build.\n" );
+                       exit( 1 );
+               }
 
                # Sanity check, quickly make sure we've got an output directory
                if( !is_dir( $outDir ) ) {
                        $this->error( "No output directory", true );
                }
 
+               # Warn about volatile classes
+               $this->checkVolatileClasses( $outDir );
+
                # Copy the generated C++ files into the source directory for cmake
                $iter = new RecursiveIteratorIterator( 
                        new RecursiveDirectoryIterator( $outDir ),
@@ -140,7 +147,7 @@ class MakeHipHop extends Maintenance {
                        }
 
                        $cmd = 'cmake' .
-                               ' -D CMAKE_BUILD_TYPE:string=Debug' .
+                               " -D CMAKE_BUILD_TYPE:string=" . wfEscapeShellArg( $GLOBALS['wgHipHopBuildType'] ) .
                                ' -D PROGRAM_NAME:string=mediawiki-hphp';
                        
                        if ( file_exists( '/usr/bin/ccache' ) ) {
@@ -155,19 +162,7 @@ class MakeHipHop extends Maintenance {
 
                # Determine appropriate make concurrency
                # Compilation can take a lot of memory, let's assume that that is limiting.
-               $mem = false;
-               foreach ( file( '/proc/meminfo' ) as $line ) {
-                       if ( preg_match( '/^MemTotal:\s+(\d+)\s+kB/', $line, $m ) ) {
-                               $mem = intval( $m[1] );
-                               break;
-                       }
-               }
-               if ( $mem ) {
-                       $procs = floor( $mem / 1000000 );
-                       $procs = $procs >= 1 ? $procs : 1; // No less than 1
-               } else {
-                       $procs = 1;
-               }
+               $procs = $this->getNumProcs();
                
                # Run make. This is the slow step.
                passthru( 'make -j' . wfEscapeShellArg( $procs ) );
@@ -188,6 +183,47 @@ class MakeHipHop extends Maintenance {
                echo $elapsed . "s\n";
                echo "The MediaWiki executable is at build/persistent/mediawiki-hphp\n";
        }
+
+       function checkVolatileClasses( $dir ) {
+               $lines = file( "$dir/sys/dynamic_table_class.cpp" );
+               $classes = array();
+               foreach ( $lines as $line ) {
+                       if ( preg_match( '/^\s+\(const char \*\)"([^"]*)", \(const char \*\)-1/', $line, $m ) ) {
+                               $classes[] = $m[1];
+                       }
+               }
+               if ( !count( $classes ) ) {
+                       print "No volatile classes found\n";
+                       return;
+               }
+               sort( $classes );
+               $classes = array_unique( $classes );
+               print "WARNING: The following classes are volatile: " . implode( ', ', $classes ) . "\n";
+       }
+
+       function getNumProcs() {
+               global $wgHipHopCompilerProcs;
+               if ( $wgHipHopCompilerProcs !== 'detect' ) {
+                       return intval( $wgHipHopCompilerProcs );
+               }
+
+               if ( !file_exists( '/proc/meminfo' ) ) {
+                       return 1;
+               }
+               $mem = false;
+               foreach ( file( '/proc/meminfo' ) as $line ) {
+                       if ( preg_match( '/^MemTotal:\s+(\d+)\s+kB/', $line, $m ) ) {
+                               $mem = intval( $m[1] );
+                               break;
+                       }
+               }
+               if ( $mem ) {
+                       // At least one process
+                       return max( 1, floor( $mem / 1000000 ) );
+               } else {
+                       return 1;
+               }
+       }
 }
 
 $maintClass = 'MakeHipHop';
index 49fd309..31bae8e 100644 (file)
@@ -174,7 +174,7 @@ class UserDupes {
         * @access private
         */
        function newSchema() {
-               return class_exists( 'Revision' );
+               return MWInit::classExists( 'Revision' );
        }
 
        /**